Skip to content

Commit 09b7f75

Browse files
committed
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.
1 parent 616476f commit 09b7f75

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/mcp/client/streamable_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _maybe_extract_protocol_version_from_message(self, message: JSONRPCMessage)
120120
try:
121121
# Parse the result as InitializeResult for type safety
122122
init_result = InitializeResult.model_validate(message.result, by_name=False)
123-
self.protocol_version = str(init_result.protocol_version)
123+
self.protocol_version = init_result.protocol_version
124124
logger.info(f"Negotiated protocol version: {self.protocol_version}")
125125
except Exception: # pragma: no cover
126126
logger.warning("Failed to parse initialization response as InitializeResult", exc_info=True)

src/mcp/types/_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class TaskStatusNotification(Notification[TaskStatusNotificationParams, Literal[
545545
class InitializeRequestParams(RequestParams):
546546
"""Parameters for the initialize request."""
547547

548-
protocol_version: str | int
548+
protocol_version: str
549549
"""The latest version of the Model Context Protocol that the client supports."""
550550
capabilities: ClientCapabilities
551551
client_info: Implementation
@@ -563,7 +563,7 @@ class InitializeRequest(Request[InitializeRequestParams, Literal["initialize"]])
563563
class InitializeResult(Result):
564564
"""After receiving an initialize request from the client, the server sends this."""
565565

566-
protocol_version: str | int
566+
protocol_version: str
567567
"""The version of the Model Context Protocol that the server wants to use."""
568568
capabilities: ServerCapabilities
569569
server_info: Implementation

0 commit comments

Comments
 (0)