{"record":{"id":"88ccb184d3977dcd","repo":"ruvnet/ruflo","slug":"mcp-initialization-failed-initresponse-error-me","errorCode":null,"errorMessage":"MCP initialization failed: ${initResponse.error.message}","messagePattern":"MCP initialization failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ruflo/src/ruvocal/src/lib/stores/wasmMcp.ts","lineNumber":98,"sourceCode":"\ttry {\n\t\t// Load WASM module\n\t\tconst wasm = await loadWasm();\n\t\tif (!wasm) {\n\t\t\tthrow new Error(\"Failed to load WASM module\");\n\t\t}\n\n\t\t// Create MCP server and gallery instances\n\t\tconst mcpServer = new wasm.WasmMcpServer();\n\t\tconst gallery = new wasm.WasmGallery();\n\n\t\t// Initialize the MCP server\n\t\tconst initResponse = callMcpInternal(mcpServer, \"initialize\", {\n\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\tclientInfo: { name: \"ruvocal-ui\", version: \"1.0.0\" },\n\t\t});\n\n\t\tif (initResponse.error) {\n\t\t\tthrow new Error(`MCP initialization failed: ${initResponse.error.message}`);\n\t\t}\n\n\t\t// Load persisted filesystem state from IndexedDB\n\t\tawait syncFromIndexedDB(mcpServer);\n\n\t\t// Check for persisted active template\n\t\tconst savedTemplateId = await idb.getSetting<string>(\"activeTemplateId\");\n\t\tlet templateName: string | null = null;\n\n\t\tif (savedTemplateId) {\n\t\t\ttry {\n\t\t\t\tconst template = gallery.get(savedTemplateId);\n\t\t\t\tgallery.setActive(savedTemplateId);\n\t\t\t\ttemplateName = template.name;\n\t\t\t} catch {\n\t\t\t\t// Template not found, ignore\n\t\t\t}\n\t\t}","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/ruflo/src/ruvocal/src/lib/stores/wasmMcp.ts#L80-L116","documentation":"Thrown by initWasmMcp() after the WASM module loaded and a WasmMcpServer was constructed, when the JSON-RPC \"initialize\" call (protocolVersion 2024-11-05, clientInfo ruvocal-ui) returns an error object. The thrown message forwards initResponse.error.message so the underlying server-side reason is visible.","triggerScenarios":"The WASM MCP server rejects the initialize handshake: unsupported protocolVersion, missing required clientInfo fields, an internal server exception during init, or a version skew between the glue JS and the compiled WASM binary.","commonSituations":"Upgraded only the JS glue but not the .wasm (or vice versa) so protocolVersion expectations diverge; the WASM build was compiled with a different MCP protocol version; a persisted IndexedDB state from an older version causes init to fail on reload.","solutions":["Read initResponse.error.message in the error text — it names the exact rejection reason.","Confirm protocolVersion \"2024-11-05\" matches what the WASM binary was built against.","Clear IndexedDB wasm-mcp state (syncFromIndexedDB runs right after init and can re-trigger older-shape data) and retry.","Rebuild and redeploy the WASM package so glue and binary are from the same commit.","If the error is transient (memory pressure in the worker), expose a retry around initWasmMcp with one re-load attempt."],"exampleFix":"// before\nif (initResponse.error) throw new Error(`MCP initialization failed: ${initResponse.error.message}`);\n// after\nif (initResponse.error) {\n  throw new Error(`MCP initialization failed: ${initResponse.error.message} (code=${initResponse.error.code ?? \"?\"})`,);\n}","handlingStrategy":"try-catch","validationCode":"const PROTOCOL = \"2024-11-05\";\nfunction validClientInfo(ci: unknown): ci is { name: string; version: string } {\n  return !!ci && typeof (ci as { name: string }).name === \"string\" && typeof (ci as { version: string }).version === \"string\";\n}\nconst clientInfo = { name: \"ruvocal-ui\", version: \"1.0.0\" };\nif (!validClientInfo(clientInfo)) throw new Error(\"clientInfo missing name/version\");","typeGuard":"interface McpError { code?: number; message?: string; data?: unknown }\nfunction isMcpError(r: unknown): r is { error: McpError } {\n  return typeof r === \"object\" && r !== null && \"error\" in (r as object);\n}","tryCatchPattern":"try {\n  await initWasmMcp();\n} catch (e) {\n  const msg = String((e as Error)?.message ?? e);\n  if (msg.startsWith(\"MCP initialization failed\")) {\n    // often a version skew — clear persisted state and retry once\n    await clearWasmIndexedDB();\n    await initWasmMcp();\n  } else throw e;\n}","preventionTips":["Keep the WASM binary and the JS glue on the same build commit so protocolVersion contracts match.","Wrap init in a single retry after clearing IndexedDB, since stale persisted state can re-trigger init failures.","Log initResponse.error.code alongside message to classify handshake failures."],"tags":["wasm","mcp","rpc","initialization","handshake"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}