{"record":{"id":"5c8f5b140728922c","repo":"different-ai/openwork","slug":"failed-to-start-oauth-response-status","errorCode":null,"errorMessage":"Failed to start OAuth (${response.status}).","messagePattern":"Failed to start OAuth \\((.+?)\\)\\.","errorType":"exception","errorClass":"McpOAuthStartError","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx","lineNumber":895,"sourceCode":"  const { orgId } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (connectionId: string): Promise<{ status: \"connected\" | \"needs_auth\"; authorizeUrl: string | null }> => {\n      const { response, payload } = await requestJson(\n        `/v1/mcp-connections/${encodeURIComponent(connectionId)}/connect/start`,\n        { headers: getOrgScopeHeaders(requireOrgId(orgId)) },\n        20000,\n      );\n      if (!response.ok) {\n        const details = mcpOAuthStartDebugDetails(payload, response.status);\n        const requestError = getRequestError(payload, response, `Failed to start OAuth (${response.status}).`);\n        if (details.errorCode === \"mcp_oauth_configuration_required\") {\n          throw new McpOAuthConfigurationRequiredError(\n            requestError.message,\n            details,\n          );\n        }\n        throw new McpOAuthStartError(requestError.message, details);\n      }\n      return payload as { status: \"connected\" | \"needs_auth\"; authorizeUrl: string | null };\n    },\n  });\n}\n\nexport function useDisconnectMyProviderAccount() {\n  const queryClient = useQueryClient();\n  const { orgId } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (connection: Pick<ExternalMcpConnection, \"id\" | \"nativeProviderKey\">): Promise<string> => {\n      const path = isNativeProviderConnectionId(connection.id, connection.nativeProviderKey)\n        ? `/v1/oauth-providers/${encodeURIComponent(connection.id)}/disconnect`\n        : `/v1/mcp-connections/${encodeURIComponent(connection.id)}/disconnect-my-account`;\n      const { response, payload } = await requestJson(\n        path,\n        { method: \"POST\", headers: getOrgScopeHeaders(requireOrgId(orgId)) },","sourceCodeStart":877,"sourceCodeEnd":913,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx#L877-L913","documentation":"Same non-2xx start-OAuth failure as its sibling, but without the 'configuration_required' errorCode: the failure is wrapped in McpOAuthStartError with debug details (status, payload-derived errorCode) for the UI to display. This is the generic OAuth handshake-start failure path.","triggerScenarios":"POST to start MCP OAuth returns non-2xx whose payload errorCode is anything other than 'mcp_oauth_configuration_required' (e.g. connection not found, provider unreachable, invalid state, upstream 502 from the MCP server).","commonSituations":"MCP server temporarily down or timing out upstream; connection was deleted between listing and OAuth start; bad request payload (malformed connectionId); transient 5xx during provider maintenance.","solutions":["Read details/errorCode on the thrown McpOAuthStartError to identify the specific upstream cause","Verify the connectionId still exists (refetch mcpConnectionQueryKeys.all) and retry","Check Den server logs for the outbound call to the MCP authorization server","Retry after confirming the MCP server is reachable — transient 5xx/502 resolve on retry","If persistent 4xx, the stored connection/issuer data is stale: disconnect and re-add the connection"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-check the connection still exists\nconst conn = queryClient.getQueryData<UpdatedMcpConnection>([...mcpConnectionQueryKeys.all, connectionId]);\nif (!conn) { refetchConnections(); return; }","typeGuard":"function isMcpOAuthStartError(e: unknown): e is McpOAuthStartError {\n  return e instanceof McpOAuthStartError;\n}","tryCatchPattern":"try {\n  await startOAuth.mutateAsync(connectionId);\n} catch (e) {\n  if (e instanceof McpOAuthStartError && isTransient(e.details)) {\n    await retryWithBackoff(() => startOAuth.mutateAsync(connectionId), 3);\n    return;\n  }\n  showToast({ variant: 'error', title: 'OAuth start failed', description: e instanceof Error ? e.message : String(e) });\n}","preventionTips":["Retry only transient errorCodes (5xx/timeouts); never retry 4xx contract errors","Log details from McpOAuthStartError for support triage","Monitor MCP server availability that OAuth start depends on","Refetch connections before retry after deletes/removals"],"tags":["oauth","mcp","http-error","network"],"backgroundTag":"oauth-handshake-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}