{"record":{"id":"eba409f0094849cb","repo":"can1357/oh-my-pi","slug":"could-not-connect-to-oauth-server-please-check-th","errorCode":null,"errorMessage":"Could not connect to OAuth server. Please check the URLs and your network connection.","messagePattern":"Could not connect to OAuth server\\. Please check the URLs and your network connection\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/controllers/mcp-command-controller.ts","lineNumber":1038,"sourceCode":"\t\t} catch (error) {\n\t\t\t// Esc, an external abort, or a newer MCP flow are neutral\n\t\t\t// cancellations. The timeout path also aborts the controller but does\n\t\t\t// not set this flag, so it remains a surfaced error.\n\t\t\tif (cancellationRequested) {\n\t\t\t\tthrow new MCPOAuthCancelledError();\n\t\t\t}\n\n\t\t\tconst errorMsg = error instanceof Error ? error.message : String(error);\n\n\t\t\t// Provide helpful error messages based on failure type\n\t\t\tif (errorMsg.includes(\"timeout\") || errorMsg.includes(\"timed out\")) {\n\t\t\t\tthrow new Error(\"OAuth flow timed out. Please try again.\");\n\t\t\t} else if (errorMsg.includes(\"403\") || errorMsg.includes(\"unauthorized\")) {\n\t\t\t\tthrow new Error(\"OAuth authorization failed. Please check your client credentials.\");\n\t\t\t} else if (errorMsg.includes(\"invalid_grant\")) {\n\t\t\t\tthrow new Error(\"OAuth authorization code is invalid or expired. Please try again.\");\n\t\t\t} else if (errorMsg.includes(\"ECONNREFUSED\") || errorMsg.includes(\"fetch failed\")) {\n\t\t\t\tthrow new Error(\"Could not connect to OAuth server. Please check the URLs and your network connection.\");\n\t\t\t} else {\n\t\t\t\tthrow new Error(`OAuth authentication failed: ${errorMsg}`);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.ctx.editor.onEscape = originalOnEscape;\n\t\t\texternalSignal?.removeEventListener(\"abort\", onExternalAbort);\n\t\t\tmanualInputClaim?.clear(\"Manual MCP OAuth input cleared\");\n\t\t\tflowClaim.release();\n\t\t}\n\t}\n\n\t/**\n\t * Fold a completed OAuth flow back into a server config. Owns the\n\t * persistence policy in one place: the auth block records the credential\n\t * pointer plus refresh material, the oauth block echoes the client id for\n\t * pre-auth reuse, and only a user-supplied client secret is ever written —\n\t * DCR-issued secrets stay embedded in the stored credential so they cannot\n\t * leak into (possibly shared/committed) config files.","sourceCodeStart":1020,"sourceCodeEnd":1056,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/controllers/mcp-command-controller.ts#L1020-L1056","documentation":"The MCP OAuth flow failed and the underlying error contained 'ECONNREFUSED' or 'fetch failed', mapped to this message. The client could not establish a TCP/HTTP connection to the OAuth authorization or token endpoint.","triggerScenarios":"OAuth server not running or wrong port in the configured URLs; DNS failure; firewall/proxy blocking outbound HTTPS; offline machine.","commonSituations":"Local dev OAuth server (e.g. localhost:8080) not started; typo'd host/port in config; corporate proxy requiring env vars (HTTPS_PROXY) that aren't set; VPN disconnected.","solutions":["Verify the auth/token endpoints are reachable: curl the token URL and check the port/host","Start the local OAuth server if the URLs point to localhost","Set proxy environment variables (HTTPS_PROXY/HTTP_PROXY) if behind a corporate proxy","Check DNS, firewall, and VPN connectivity, then retry the flow"],"exampleFix":"// before\ntokenUrl = \"https://localhost:9999/token\" // server not listening on 9999\n// after\ntokenUrl = \"https://localhost:8080/token\" // matching the running local server","handlingStrategy":"validation","validationCode":"// Reachability pre-check before starting the flow\nconst reachable = await fetch(tokenUrl, { method: 'HEAD', signal: AbortSignal.timeout(5000) })\n  .then(() => true).catch(() => false);\nif (!reachable) {\n  console.error(`Cannot reach OAuth server at ${tokenUrl} — check host, port, proxy, VPN`);\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runMcpOAuthFlow();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Could not connect to OAuth server')) {\n    // show connectivity diagnostics: URL, proxy env, DNS\n  }\n}","preventionTips":["Verify OAuth server URLs (host/port) before saving them","Start local dev OAuth servers before running the flow","Set HTTPS_PROXY/HTTP_PROXY when behind a corporate proxy","Confirm VPN/network reachability to the provider"],"tags":["oauth","network","mcp","connection"],"backgroundTag":"connection-refused","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}