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