From 09b7f7569bc15e55ee6032d290daed62107926e7 Mon Sep 17 00:00:00 2001 From: Max Isbey <224885523+maxisbey@users.noreply.github.com> Date: Tue, 2 Jun 2026 15:59:59 +0000 Subject: [PATCH] Require protocol_version to be a string The MCP schema defines protocolVersion as a plain string. The int variant only existed for compatibility with pre-release protocol negotiation (before 2024-10-07 date-based versioning), which sent protocolVersion: 1. Integer versions can never successfully negotiate against the supported version list, so accepting them only changed the failure mode. This matches the TypeScript SDK, which made the same change in November 2024. --- src/mcp/client/streamable_http.py | 2 +- src/mcp/types/_types.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mcp/client/streamable_http.py b/src/mcp/client/streamable_http.py index aa3e50e07e..9cdf717c73 100644 --- a/src/mcp/client/streamable_http.py +++ b/src/mcp/client/streamable_http.py @@ -120,7 +120,7 @@ def _maybe_extract_protocol_version_from_message(self, message: JSONRPCMessage) try: # Parse the result as InitializeResult for type safety init_result = InitializeResult.model_validate(message.result, by_name=False) - self.protocol_version = str(init_result.protocol_version) + self.protocol_version = init_result.protocol_version logger.info(f"Negotiated protocol version: {self.protocol_version}") except Exception: # pragma: no cover logger.warning("Failed to parse initialization response as InitializeResult", exc_info=True) diff --git a/src/mcp/types/_types.py b/src/mcp/types/_types.py index 9005d253af..3f84818958 100644 --- a/src/mcp/types/_types.py +++ b/src/mcp/types/_types.py @@ -545,7 +545,7 @@ class TaskStatusNotification(Notification[TaskStatusNotificationParams, Literal[ class InitializeRequestParams(RequestParams): """Parameters for the initialize request.""" - protocol_version: str | int + protocol_version: str """The latest version of the Model Context Protocol that the client supports.""" capabilities: ClientCapabilities client_info: Implementation @@ -563,7 +563,7 @@ class InitializeRequest(Request[InitializeRequestParams, Literal["initialize"]]) class InitializeResult(Result): """After receiving an initialize request from the client, the server sends this.""" - protocol_version: str | int + protocol_version: str """The version of the Model Context Protocol that the server wants to use.""" capabilities: ServerCapabilities server_info: Implementation