From c91f4069386ad724b275f537ee0f0af2af5a6a1c Mon Sep 17 00:00:00 2001 From: Max <224885523+maxisbey@users.noreply.github.com> Date: Tue, 2 Jun 2026 17:27:41 +0100 Subject: [PATCH] Require protocol_version to be a string (#2763) --- 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 aa3e50e0..9cdf717c 100644 --- a/src/mcp/client/streamable_http.py +++ b/src/mcp/client/streamable_http.py @@ -120,7 +120,7 @@ class StreamableHTTPTransport: 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 34800ba1..e9d39ef6 100644 --- a/src/mcp/types/_types.py +++ b/src/mcp/types/_types.py @@ -304,7 +304,7 @@ class ServerCapabilities(MCPModel): 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 @@ -322,7 +322,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