{"record":{"id":"d53972d1513e38bb","repo":"Hmbown/CodeWhale","slug":"mcp-server-initialize-result-omitted-protocolversion","errorCode":null,"errorMessage":"MCP server '{}' initialize result omitted protocolVersion","messagePattern":"MCP server '(.+?)' initialize result omitted protocolVersion","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":1894,"sourceCode":"                }\n            }\n        }))\n        .await?;\n\n        let response = self.recv(init_id).await?;\n        let result = response_result(\n            &response,\n            \"initialize\",\n            self.config.reviewed_plugin.is_some(),\n        )?;\n        // Per spec, a server that cannot speak the advertised revision answers\n        // with one it does support. Accept any dated revision we still\n        // implement; anything else ends the handshake.\n        let negotiated = result\n            .and_then(|result| result.get(\"protocolVersion\"))\n            .and_then(|version| version.as_str())\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"MCP server '{}' initialize result omitted protocolVersion\",\n                    self.name\n                )\n            })?;\n        anyhow::ensure!(\n            MCP_SUPPORTED_PROTOCOL_VERSIONS.contains(&negotiated),\n            \"MCP server '{}' negotiated unsupported protocol version '{negotiated}' (supported: {})\",\n            self.name,\n            MCP_SUPPORTED_PROTOCOL_VERSIONS.join(\", \")\n        );\n        self.transport.set_protocol_version(negotiated);\n        self.server_capabilities = McpServerCapabilities::from_initialize_response(&response);\n\n        // Send initialized notification (no id, no response expected)\n        self.send(serde_json::json!({\n            \"jsonrpc\": \"2.0\",\n            \"method\": \"notifications/initialized\"\n        }))","sourceCodeStart":1876,"sourceCodeEnd":1912,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L1876-L1912","documentation":"During MCP initialization, the client requires the server's initialize result to include a protocolVersion string so a version can be negotiated. If the field is absent (or not a string), the handshake fails — without it the client cannot know which protocol revision the server speaks and cannot safely proceed.","triggerScenarios":"Server's initialize response JSON lacks a \"protocolVersion\" key, has it as null, or as a non-string value (number/object); happens when connecting to a non-conformant or partially implemented MCP server.","commonSituations":"Connecting to a home-grown or beta MCP server that skips the field, an HTTP proxy stripping/rewriting the JSON body, pointing the client at an endpoint that isn't actually MCP (wrong port/path), or a server implementing an older pre-versioning draft of the spec.","solutions":["Upgrade the MCP server to a version that returns protocolVersion in its initialize result.","Verify you are pointing at the correct MCP endpoint (right port/path, actual MCP server behind any proxy).","Inspect the raw initialize response (log the JSON) to confirm whether the field is missing or mistyped.","If you own the server, add protocolVersion from MCP_SUPPORTED_PROTOCOL_VERSIONS to the initialize result."],"exampleFix":"// before (server-side)\njson!({ \"capabilities\": {...} })\n// after\njson!({ \"protocolVersion\": \"2025-06-18\", \"capabilities\": {...} })","handlingStrategy":"try-catch","validationCode":"// verify the endpoint answers a real MCP initialize before full connect\nlet probe = raw_initialize(endpoint).await?;\nif probe.get(\"protocolVersion\").and_then(|v| v.as_str()).is_none() {\n    return Err(\"endpoint is not a conformant MCP server\");\n}","typeGuard":"fn has_protocol_version(result: &serde_json::Value) -> bool {\n    result.get(\"protocolVersion\").and_then(|v| v.as_str()).is_some()\n}","tryCatchPattern":"match client.initialize().await {\n    Err(e) if e.to_string().contains(\"omitted protocolVersion\") => {\n        log_raw_initialize_response();\n        Err(anyhow!(\"server is not MCP-conformant; upgrade the server\"))\n    }\n    other => other,\n}","preventionTips":["Conformance-test any custom MCP server's initialize response","Ensure proxies don't rewrite or strip JSON-RPC response fields","Pin server versions known to implement the MCP handshake","Log raw initialize payloads in debug mode for fast diagnosis"],"tags":["mcp","handshake","protocol","versioning"],"backgroundTag":"unexpected-response-shape","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}