Require protocol_version to be a string (#2763)

This commit is contained in:
Max 2026-06-02 17:27:41 +01:00 • committed by GitHub
commit c91f406938
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -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)

View file

@ -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