Skip to content

Commit 2af0b90

Browse files
committed
MCP: Fix protocol version mismatch warnings at startup
Older MCP clients (2024-11-05 spec) send `protocolVersion` in the JSON body of `initialize`, not as an HTTP header. The server only checked the header, defaulted to `2025-03-26`, and negotiated to`2025-11-25` — causing mismatch warnings on every subsequent request. Now falls back to the body value when the header is absent.
1 parent 2f7bff1 commit 2af0b90

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

apps/desktop/src-tauri/src/mcp/server.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,22 @@ async fn process_request<R: Runtime>(
389389
*session_guard = Some(session_id.clone());
390390
}
391391

392-
// Negotiate protocol version (use latest supported or client's version if older)
393-
let negotiated = if client_version == PROTOCOL_VERSION || client_version == DEFAULT_PROTOCOL_VERSION {
392+
// Negotiate protocol version (use latest supported or client's version if older).
393+
// Older clients (2024-11-05 spec) send protocolVersion in the JSON body only,
394+
// not the HTTP header. Fall back to the body value when the header is absent.
395+
let effective_version = if client_version == DEFAULT_PROTOCOL_VERSION {
396+
request
397+
.params
398+
.get("protocolVersion")
399+
.and_then(|v| v.as_str())
400+
.unwrap_or(client_version)
401+
} else {
402+
client_version
403+
};
404+
let negotiated = if effective_version == PROTOCOL_VERSION || effective_version == DEFAULT_PROTOCOL_VERSION {
394405
PROTOCOL_VERSION.to_string()
395406
} else {
396-
client_version.to_string()
407+
effective_version.to_string()
397408
};
398409

399410
if let Ok(mut version_guard) = state.negotiated_version.write() {

0 commit comments

Comments
 (0)