Update protocol version handling

This commit is contained in:
Justin Spahr-Summers
2024-10-21 14:50:44 +01:00
parent 2d55eabb2f
commit eb1024c654
5 changed files with 15 additions and 11 deletions

View File

@@ -2,8 +2,9 @@ from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStre
from pydantic import AnyUrl
from mcp_python.shared.session import BaseSession
from mcp_python.shared.version import SUPPORTED_PROTOCOL_VERSION
from mcp_python.shared.version import SUPPORTED_PROTOCOL_VERSIONS
from mcp_python.types import (
LATEST_PROTOCOL_VERSION,
CallToolResult,
ClientCapabilities,
ClientNotification,
@@ -49,7 +50,7 @@ class ClientSession(
InitializeRequest(
method="initialize",
params=InitializeRequestParams(
protocolVersion=SUPPORTED_PROTOCOL_VERSION,
protocolVersion=LATEST_PROTOCOL_VERSION,
capabilities=ClientCapabilities(
sampling=None, experimental=None
),
@@ -60,7 +61,7 @@ class ClientSession(
InitializeResult,
)
if result.protocolVersion != SUPPORTED_PROTOCOL_VERSION:
if result.protocolVersion not in SUPPORTED_PROTOCOL_VERSIONS:
raise RuntimeError(
"Unsupported protocol version from the server: "
f"{result.protocolVersion}"

View File

@@ -11,8 +11,8 @@ from mcp_python.shared.session import (
BaseSession,
RequestResponder,
)
from mcp_python.shared.version import SUPPORTED_PROTOCOL_VERSION
from mcp_python.types import (
LATEST_PROTOCOL_VERSION,
ClientNotification,
ClientRequest,
CreateMessageResult,
@@ -67,7 +67,7 @@ class ServerSession(
await responder.respond(
ServerResult(
InitializeResult(
protocolVersion=SUPPORTED_PROTOCOL_VERSION,
protocolVersion=LATEST_PROTOCOL_VERSION,
capabilities=self._init_options.capabilities,
serverInfo=Implementation(
name=self._init_options.server_name,

View File

@@ -1 +1,3 @@
SUPPORTED_PROTOCOL_VERSION = 1
from mcp_python.types import LATEST_PROTOCOL_VERSION
SUPPORTED_PROTOCOL_VERSIONS = [1, LATEST_PROTOCOL_VERSION]