microsoft/autogen · error · Error

connectionData.message || "Failed to create WebSocket connec

Error message

connectionData.message || "Failed to create WebSocket connection"

What it means

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.

Source

Thrown at python/packages/autogen-studio/frontend/src/components/views/mcp/api.ts:431

      }
      return baseUrl;
    } catch (error) {
      throw new Error("Invalid server URL configuration");
    }
  }

  async connect(): Promise<void> {
    this.updateState({ connecting: true, error: null });

    try {
      // First, get the WebSocket connection URL using proper API construction
      const mcpApiInstance = mcpAPI;
      const connectionData = await mcpApiInstance.createWebSocketConnection(
        this.serverParams
      );

      if (!connectionData.status) {
        throw new Error(
          connectionData.message || "Failed to create WebSocket connection"
        );
      }

      const { session_id, websocket_url } = connectionData;

      // Construct WebSocket URL using the correct server URL (not window.location.host)
      // This handles cases where backend runs on different port (e.g., 8081 vs 8000)
      const serverUrl = getServerUrl(); // e.g., "/api" or "http://localhost:8081/api"
      const baseUrl = this.getWebSocketBaseUrl(serverUrl);
      const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
      const wsUrl = `${protocol}//${baseUrl}${websocket_url}`;

      // Create WebSocket connection
      const ws = new WebSocket(wsUrl);
      this.wsRef = ws;

      ws.onopen = () => {

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Log the full connectionData object — its message field carries the backend's reason even when HTTP was 200
  2. Reproduce with curl -X POST to see the raw {status:false,...} body
  3. Fix whatever the backend message names (usually server spawn/connect failure — check backend logs)
  4. Retry the connect after fixing; transient backend failures often clear immediately
  5. If message is habitually missing, improve the backend to always populate it on status:false

Example fix

// before
if (!connectionData.status) {
  throw new Error(connectionData.message || "Failed to create WebSocket connection");
}
// after
if (!connectionData.status) {
  throw new Error(
    connectionData.message ||
      `Failed to create WebSocket connection: ${JSON.stringify(connectionData).slice(0, 200)}`
  );
}
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

function isConnectionData(x: unknown): x is { status: boolean; message?: string; session_id: string; websocket_url: string } {
  if (!x || typeof x !== "object" || !("status" in x)) return false;
  const c = x as any;
  return typeof c.status === "boolean" && typeof c.websocket_url === "string";
}

Try / catch

try {
  await manager.connect();
} catch (e) {
  // in-band failure: safe to retry once, transport may be flapping
  await delay(500);
  await manager.connect();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/bce5aa26b0afa6f7. Report an issue: GitHub.