Skip to content

Commit c146207

Browse files
committed
2 parents 1028263 + 5906433 commit c146207

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

rmcp/core/server.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
"alert",
4545
"emergency",
4646
]
47+
# Supported MCP protocol versions (latest first)
48+
_SUPPORTED_PROTOCOL_VERSIONS = tuple(
49+
dict.fromkeys((_PROTOCOL_VERSION, "2025-06-18"))
50+
)
51+
4752
# Import version from __init__ at runtime to avoid circular imports
4853
from ..registries.prompts import PromptsRegistry
4954
from ..registries.resources import ResourcesRegistry
@@ -466,6 +471,15 @@ async def _handle_initialize(self, params: dict[str, Any]) -> dict[str, Any]:
466471
Returns:
467472
Initialize response with server capabilities
468473
"""
474+
requested_version = params.get("protocolVersion")
475+
if requested_version and requested_version not in _SUPPORTED_PROTOCOL_VERSIONS:
476+
raise ValueError(
477+
"Unsupported protocol version requested: "
478+
f"{requested_version}. Supported versions: "
479+
f"{', '.join(_SUPPORTED_PROTOCOL_VERSIONS)}"
480+
)
481+
protocol_version = requested_version or _PROTOCOL_VERSION
482+
469483
client_info = params.get("clientInfo", {})
470484
logger.info(
471485
f"Initializing MCP connection with client: "
@@ -480,7 +494,7 @@ async def _handle_initialize(self, params: dict[str, Any]) -> dict[str, Any]:
480494
logging=LoggingCapability(),
481495
)
482496
initialize_result = InitializeResult(
483-
protocolVersion=_PROTOCOL_VERSION,
497+
protocolVersion=protocol_version,
484498
capabilities=capabilities,
485499
serverInfo=Implementation(name=self.name, version=self.version),
486500
instructions=self.description or None,
@@ -495,7 +509,7 @@ async def _handle_initialize(self, params: dict[str, Any]) -> dict[str, Any]:
495509
"completion": {},
496510
}
497511
result = {
498-
"protocolVersion": _PROTOCOL_VERSION,
512+
"protocolVersion": protocol_version,
499513
"capabilities": capabilities_dict,
500514
"serverInfo": {"name": self.name, "version": self.version},
501515
}

rmcp/transport/http.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"HTTP transport requires 'fastapi' extras. Install with: pip install rmcp[http]"
2626
) from e
2727
from ..config import get_config
28+
from ..core.server import _SUPPORTED_PROTOCOL_VERSIONS
2829
from .base import Transport
2930

3031
logger = logging.getLogger(__name__)
@@ -219,7 +220,7 @@ def _validate_origin(self, request: Request) -> None:
219220
def _validate_protocol_version(self, request: Request, method: str) -> None:
220221
"""Validate MCP-Protocol-Version header according to MCP specification."""
221222
protocol_version = request.headers.get("mcp-protocol-version")
222-
supported_versions = ("2025-11-25", "2025-06-18")
223+
supported_versions = _SUPPORTED_PROTOCOL_VERSIONS
223224
preferred_version = supported_versions[0]
224225

225226
if method == "initialize":
@@ -325,6 +326,11 @@ async def handle_jsonrpc(request: Request) -> Response:
325326
self._check_session_initialized(session_id, method)
326327
# Track initialize completion
327328
if method == "initialize":
329+
params = message.setdefault("params", {})
330+
if "protocolVersion" not in params and hasattr(
331+
request.state, "protocol_version"
332+
):
333+
params["protocolVersion"] = request.state.protocol_version
328334
self._initialized_sessions.add(session_id)
329335
self._sessions[session_id]["initialized"] = True
330336
# Process through message handler

0 commit comments

Comments
 (0)