{"record":{"id":"9e6026f0b226e363","repo":"microsoft/autogen","slug":"http-response-status-errortext-failed-to","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/mcp/api.ts","lineNumber":278,"sourceCode":"        return result.status;\n      }\n      return false;\n    } catch (error) {\n      return false;\n    }\n  }\n\n  // WebSocket connection management\n  async createWebSocketConnection(serverParams: McpServerParams): Promise<any> {\n    const response = await fetch(`${this.getBaseUrl()}/mcp/ws/connect`, {\n      method: \"POST\",\n      headers: this.getHeaders(),\n      body: JSON.stringify({ server_params: serverParams }),\n    });\n\n    if (!response.ok) {\n      const errorText = await response.text();\n      throw new Error(\n        `HTTP ${response.status}: ${\n          errorText || \"Failed to create WebSocket connection\"\n        }`\n      );\n    }\n\n    try {\n      const responseText = await response.text();\n      return JSON.parse(responseText);\n    } catch (jsonError) {\n      throw new Error(\n        `Invalid JSON response from server. Check if the MCP route is properly configured.`\n      );\n    }\n  }\n}\n\n// WebSocket-based MCP functionality","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-studio/frontend/src/components/views/mcp/api.ts#L260-L296","documentation":"Thrown by McpAPI.createWebSocketConnection when POST /mcp/ws/connect returns non-2xx. Unlike the JSON-based paths, this one reads the body as text and embeds both the status code and body text in the error, so the message here is a template literal pattern, not the literal thrown string. Failures include backend refusal to create the MCP session or transport errors during server connection.","triggerScenarios":"POST {base}/mcp/ws/connect with server_params returning 4xx/5xx: backend cannot spawn/connect the MCP server (bad command, missing binary), server_params schema rejected, auth failure, or no WebSocket-capable transport available for the given server type.","commonSituations":"stdio server command not found in the backend container, SSE URL unreachable from backend, reverse proxy (nginx) blocking or timing out the connect endpoint, backend log shows the real spawn error while the browser only sees the HTTP status.","solutions":["Read the embedded status/body in the thrown message — 'HTTP 500: ...' text carries the backend's reason","Check backend logs at the moment of the call; spawn/connect failures are logged server-side with the command and stderr","Verify server_params against the backend's expected schema (command/args/env for stdio, url/headers for SSE)","Ensure the auth token is valid if status is 401/403","If behind a proxy, confirm POST /mcp/ws/connect is forwarded and not size/time limited"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"try {\n  const conn = await mcpAPI.createWebSocketConnection(serverParams);\n  return conn;\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.startsWith(\"HTTP 401\") || msg.startsWith(\"HTTP 403\")) await reauthenticate();\n  throw e;\n}","preventionTips":["Map the embedded 'HTTP <status>' prefix to user actions (401 → re-login, 500 → check backend logs)","Surface the full status+body string in diagnostics — it is the only client-side evidence","Test server_params with listTools first; if that works, ws/connect failures are transport-specific"],"tags":["mcp","websocket","http","fetch","autogen-studio"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}