{"record":{"id":"bce5aa26b0afa6f7","repo":"microsoft/autogen","slug":"connectiondata-message-failed-to-create-websoc","errorCode":null,"errorMessage":"connectionData.message || \"Failed to create WebSocket connection\"","messagePattern":"connectionData\\.message \\|\\| \"Failed to create WebSocket connection\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-studio/frontend/src/components/views/mcp/api.ts","lineNumber":431,"sourceCode":"      }\n      return baseUrl;\n    } catch (error) {\n      throw new Error(\"Invalid server URL configuration\");\n    }\n  }\n\n  async connect(): Promise<void> {\n    this.updateState({ connecting: true, error: null });\n\n    try {\n      // First, get the WebSocket connection URL using proper API construction\n      const mcpApiInstance = mcpAPI;\n      const connectionData = await mcpApiInstance.createWebSocketConnection(\n        this.serverParams\n      );\n\n      if (!connectionData.status) {\n        throw new Error(\n          connectionData.message || \"Failed to create WebSocket connection\"\n        );\n      }\n\n      const { session_id, websocket_url } = connectionData;\n\n      // Construct WebSocket URL using the correct server URL (not window.location.host)\n      // This handles cases where backend runs on different port (e.g., 8081 vs 8000)\n      const serverUrl = getServerUrl(); // e.g., \"/api\" or \"http://localhost:8081/api\"\n      const baseUrl = this.getWebSocketBaseUrl(serverUrl);\n      const protocol = window.location.protocol === \"https:\" ? \"wss:\" : \"ws:\";\n      const wsUrl = `${protocol}//${baseUrl}${websocket_url}`;\n\n      // Create WebSocket connection\n      const ws = new WebSocket(wsUrl);\n      this.wsRef = ws;\n\n      ws.onopen = () => {","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-studio/frontend/src/components/views/mcp/api.ts#L413-L449","documentation":"Thrown in McpWebSocketManager.connect after POST /mcp/ws/connect succeeded, when the parsed connectionData object has a falsy status field. The backend returned 2xx JSON but flagged failure in-band (status:false), optionally with a message. The literal fallback fires when message is absent, so the real cause lives in the backend's response.","triggerScenarios":"Backend returns {status:false, message?} from /mcp/ws/connect: MCP server spawn/connect failed server-side, session table full or unavailable, server_params rejected by backend validation — all with HTTP 200.","commonSituations":"Backend wraps errors as 200 + status:false (autogen-studio's standard envelope), so response.ok checks pass but the in-band flag fails; MCP server flapping; database/session store briefly unavailable.","solutions":["Log the full connectionData object — its message field carries the backend's reason even when HTTP was 200","Reproduce with curl -X POST to see the raw {status:false,...} body","Fix whatever the backend message names (usually server spawn/connect failure — check backend logs)","Retry the connect after fixing; transient backend failures often clear immediately","If message is habitually missing, improve the backend to always populate it on status:false"],"exampleFix":"// before\nif (!connectionData.status) {\n  throw new Error(connectionData.message || \"Failed to create WebSocket connection\");\n}\n// after\nif (!connectionData.status) {\n  throw new Error(\n    connectionData.message ||\n      `Failed to create WebSocket connection: ${JSON.stringify(connectionData).slice(0, 200)}`\n  );\n}","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"function isConnectionData(x: unknown): x is { status: boolean; message?: string; session_id: string; websocket_url: string } {\n  if (!x || typeof x !== \"object\" || !(\"status\" in x)) return false;\n  const c = x as any;\n  return typeof c.status === \"boolean\" && typeof c.websocket_url === \"string\";\n}","tryCatchPattern":"try {\n  await manager.connect();\n} catch (e) {\n  // in-band failure: safe to retry once, transport may be flapping\n  await delay(500);\n  await manager.connect();\n}","preventionTips":["Distinguish envelope failures (status:false, HTTP 200) from HTTP failures in error handling — they have different fixes","Always log the raw connectionData on failure","Retry once with backoff for spawn-type failures before giving up"],"tags":["mcp","websocket","error-envelope","autogen-studio"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}