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
4853from ..registries .prompts import PromptsRegistry
4954from ..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 }
0 commit comments