{"record":{"id":"00c155414c3b80ab","repo":"microsoft/autogen","slug":"http-response-status-errortext-failed-to-00c155","errorCode":null,"errorMessage":"HTTP ${response.status}: ${errorText || \"Failed to create WebSocket connection\"}","messagePattern":"HTTP (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/workbench/useMcpWebSocket.ts","lineNumber":141,"sourceCode":"\n    try {\n      // First, get the WebSocket connection URL\n      console.log(\"Connecting to MCP server with params:\", serverParams);\n      const serverUrl = getServerUrl();\n      const response = await fetch(`${serverUrl}/mcp/ws/connect`, {\n        method: \"POST\",\n        headers: {\n          \"Content-Type\": \"application/json\",\n        },\n        body: JSON.stringify({ server_params: serverParams }),\n      });\n\n      console.log(\"Response status:\", response.status, response.statusText);\n\n      if (!response.ok) {\n        const errorText = await response.text();\n        console.error(\"HTTP error response:\", errorText);\n        throw new Error(\n          `HTTP ${response.status}: ${\n            errorText || \"Failed to create WebSocket connection\"\n          }`\n        );\n      }\n\n      let connectionData;\n      try {\n        const responseText = await response.text();\n        console.log(\"Raw response:\", responseText);\n        connectionData = JSON.parse(responseText);\n      } catch (jsonError) {\n        console.error(\"JSON parse error:\", jsonError);\n        throw new Error(\n          `Invalid JSON response from server. Check if the MCP route is properly configured.`\n        );\n      }\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/workbench/useMcpWebSocket.ts#L123-L159","documentation":"Thrown by useMcpWebSocket when the HTTP POST that initiates an MCP session (sending server_params) returns a non-OK status. The message interpolates the HTTP status code plus the raw response body text, defaulting to 'Failed to create WebSocket connection' when the body is empty. It means the backend rejected or failed the MCP connection setup before a WebSocket was opened.","triggerScenarios":"POSTing server_params for an MCP server that the backend cannot reach (404 route missing), invalid/unsupported server_params payload (400/422), auth failure (401/403), or backend exception while spawning the MCP session (500). The URL and status in the message identify which.","commonSituations":"MCP server command/path configured incorrectly in the component (backend can't launch it, returns 4xx/5xx); frontend and backend versions mismatched so /mcp route doesn't exist; gateway timeout because the MCP server takes too long to start.","solutions":["Read the interpolated status: 404 means the MCP route is absent (update backend or fix URL); 4xx/5xx bodies usually contain the backend's reason.","Verify the MCP server params (command, args, env) work by launching the MCP server manually.","Ensure the AutoGen Studio backend version matches the frontend and includes MCP support enabled in settings.","Check backend logs for the exception raised during session creation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const mcpEndpoint = `${getServerUrl()}/mcp`;\n// Preflight: does the route exist at all?\nconst probe = await fetch(mcpEndpoint, { method: 'OPTIONS' });\nif (probe.status === 404) throw new Error('MCP route not found on backend');","typeGuard":null,"tryCatchPattern":"try {\n  await connectMcp(serverParams);\n} catch (e) {\n  if (e instanceof Error && /^HTTP (401|403)/.test(e.message)) {\n    promptReauthentication();\n  } else if (e instanceof Error && /^HTTP 404/.test(e.message)) {\n    showDeployError('Backend does not expose MCP routes; update the server.');\n  } else {\n    showError(e.message); // includes status + server body\n  }\n}","preventionTips":["Verify MCP support is enabled in AutoGen Studio settings before offering MCP fields in the UI.","Smoke-test the MCP route after each backend upgrade.","Log the response body on failure — it's already embedded in this error's message."],"tags":["http","websocket","mcp","typescript","frontend"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}