{"record":{"id":"7ff4f11edf45592e","repo":"unslothai/unsloth","slug":"use-oauth-must-be-true-or-false","errorCode":null,"errorMessage":"use_oauth must be true or false","messagePattern":"use_oauth must be true or false","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"studio/backend/routes/mcp_servers.py","lineNumber":196,"sourceCode":"    changes: dict = {}\n\n    if \"display_name\" in sent:\n        name = (payload.display_name or \"\").strip()\n        if not name:\n            raise HTTPException(status_code = 400, detail = \"display_name must not be empty\")\n        changes[\"display_name\"] = name\n    if \"url\" in sent:\n        changes[\"url\"] = _validate_url(payload.url or \"\")\n    if \"headers\" in sent:\n        headers = _normalize_headers(payload.headers)\n        changes[\"headers_json\"] = json.dumps(headers) if headers else None\n    if \"is_enabled\" in sent:\n        if payload.is_enabled is None:\n            raise HTTPException(status_code = 400, detail = \"is_enabled must be true or false\")\n        changes[\"is_enabled\"] = payload.is_enabled\n    if \"use_oauth\" in sent:\n        if payload.use_oauth is None:\n            raise HTTPException(status_code = 400, detail = \"use_oauth must be true or false\")\n        changes[\"use_oauth\"] = payload.use_oauth\n    # stdio is OAuth-less: drop a stale OAuth flag when switching to a command.\n    if \"url\" in changes and is_stdio(changes[\"url\"]):\n        changes[\"use_oauth\"] = False\n    return changes\n\n\n@router.put(\"/{server_id}\", response_model = McpServerResponse)\nasync def update_mcp_server(\n    server_id: str,\n    payload: McpServerUpdate,\n    current_subject: str = Depends(get_current_subject),\n    via_api_key: ViaApiKey = False,\n):\n    old = mcp_servers_db.get_server(server_id)\n    if not old:\n        raise HTTPException(status_code = 404, detail = \"MCP server not found\")\n    changes = _changes_from_payload(payload)","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/routes/mcp_servers.py#L178-L214","documentation":"400 from _changes_from_payload when the update payload includes use_oauth but sets it to null. The OAuth flag must be a definite boolean on update (absent = unchanged; true/false = set), and null would leave the probe path ambiguous, so it's rejected before any change is applied.","triggerScenarios":"PUT /{server_id} with {\"use_oauth\": null} in the body. Note the backend itself forces use_oauth=false when the url switches to a stdio command, so clients never need to send null to clear it.","commonSituations":"Reset-style forms that send null to 'clear' the OAuth toggle; API wrappers that include every field with null defaults.","solutions":["Send {\"use_oauth\": true} or {\"use_oauth\": false}, or omit the key to leave it unchanged.","Rely on the server's automatic use_oauth=false when repointing a row at a stdio command instead of clearing it manually.","Exclude null-valued keys when serializing update payloads."],"exampleFix":"# before\nclient.put(f'/api/mcp-servers/{sid}', json={'use_oauth': None})\n# -> 400\n\n# after\nclient.put(f'/api/mcp-servers/{sid}', json={'use_oauth': False})\n# or omit the key entirely","handlingStrategy":"type-guard","validationCode":"if ('use_oauth' in payload && typeof payload.use_oauth !== 'boolean') throw new Error('use_oauth must be true or false');","typeGuard":"function validOAuthUpdate(p) { return !('use_oauth' in p) || typeof p.use_oauth === 'boolean'; }","tryCatchPattern":null,"preventionTips":["Never send null for use_oauth; omit it to keep it unchanged.","Let the server force use_oauth=false on stdio switches instead of clearing it client-side."],"tags":["mcp","validation","http-400","oauth"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}