microsoft/autogen · error · Error
Failed to create WebSocket connection
Error message
Failed to create WebSocket connection
What it means
Thrown by useMcpWebSocket when the MCP initiation endpoint returns valid JSON with status falsy and no message field. It means the backend deliberately reported a failed session creation but did not include a reason, so the generic message is used. Occurs after the JSON parse succeeded, before the WebSocket is constructed.
Source
Thrown at python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/workbench/useMcpWebSocket.ts:161
errorText || "Failed to create WebSocket connection"
}`
);
}
let connectionData;
try {
const responseText = await response.text();
console.log("Raw response:", responseText);
connectionData = JSON.parse(responseText);
} catch (jsonError) {
console.error("JSON parse error:", jsonError);
throw new Error(
`Invalid JSON response from server. Check if the MCP route is properly configured.`
);
}
if (!connectionData.status) {
throw new Error(
connectionData.message || "Failed to create WebSocket connection"
);
}
const { session_id, websocket_url } = connectionData;
const wsUrl = `${getWebSocketUrl()}${websocket_url}`;
// Create WebSocket connection
const ws = new WebSocket(wsUrl);
wsRef.current = ws;
ws.onopen = () => {
console.log(`MCP WebSocket connected to session ${session_id}`);
setState((prev) => ({
...prev,
connected: true,
connecting: false,
sessionId: session_id,View on GitHub (pinned to 027ecf0a37)
Solutions
- Inspect the raw response body in the Network tab to confirm message is truly absent.
- Check backend logs — the reason for status:false is usually logged even when omitted from the response.
- Verify the MCP server command in server_params runs on the backend host with the same user/env.
- Patch the backend to include the failure reason in the message field so the UI shows the real cause.
Defensive patterns
Strategy: try-catch
Type guard
interface McpSessionResponse { status?: boolean; message?: string; session_id?: string; websocket_url?: string; }
const isMcpSessionResponse = (d: unknown): d is McpSessionResponse =>
typeof d === 'object' && d !== null && 'session_id' in d && 'websocket_url' in d; Try / catch
try {
await connectMcp(serverParams);
} catch (e) {
if (e instanceof Error && e.message === 'Failed to create WebSocket connection') {
// Backend returned status:false with no reason: check server logs
showServerError('MCP session rejected; see backend logs for the reason.');
}
} Prevention
- Make the backend always include a message when returning status:false.
- Log session-creation failures server-side with the exception detail.
- Validate server_params (command exists, port free) before spawning the session.
When it happens
Trigger: POST succeeds (HTTP 200, valid JSON) but the backend response is {status: false} or {status: null} with no message — e.g. the MCP server process failed to start or validation of server_params failed silently server-side.
Common situations: MCP server executable not installed on the backend host; server_params schema accepted but semantically invalid; backend swallowed the underlying exception and returned status:false without message.
Related errors
- HTTP ${response.status}: ${errorText || "Failed to create We
- Invalid JSON response from server. Check if the MCP route is
- Invalid server URL configuration
- connectionData.message || "Failed to create WebSocket connec
- Invalid server URL configuration
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/9d8dabf01178d5e6.
Report an issue: GitHub.