@@ -42,10 +42,6 @@ import type {
4242} from "../mcp/20251125/types.js" ;
4343import {
4444 LATEST_PROTOCOL_VERSION ,
45- PROTOCOL_VERSION_2024_10_07 ,
46- PROTOCOL_VERSION_2024_11_05 ,
47- PROTOCOL_VERSION_2025_03_26 ,
48- PROTOCOL_VERSION_2025_06_18 ,
4945 SUPPORTED_PROTOCOL_VERSIONS ,
5046} from "../mcp/versions.js" ;
5147import type { PromptConfig , RegisteredPrompt } from "../prompts/types.js" ;
@@ -432,37 +428,27 @@ export class MCPServer {
432428 } ) ;
433429 }
434430
435- const protocolVersion = parseResult . data . params . protocolVersion ;
436-
437- switch ( protocolVersion ) {
438- case LATEST_PROTOCOL_VERSION :
439- case PROTOCOL_VERSION_2025_06_18 :
440- case PROTOCOL_VERSION_2025_03_26 :
441- case PROTOCOL_VERSION_2024_11_05 :
442- case PROTOCOL_VERSION_2024_10_07 : {
443- const initResponse : InitializeResult = {
444- protocolVersion : protocolVersion ,
445- capabilities : this . getCapabilities ( ) ,
446- serverInfo : {
447- name : this . name ,
448- version : this . version ,
449- } ,
450- ...( this . instructions ? { instructions : this . instructions } : { } ) ,
451- } ;
452-
453- return newJSONRPCReponse ( { id : request . id , result : initResponse } ) ;
454- }
455- default : {
456- return newJSONRPCError ( {
457- id : request . id ,
458- code : ErrorCode . InvalidParams ,
459- message : `Unsupported protocol version: ${ protocolVersion } - supported versions: ${ SUPPORTED_PROTOCOL_VERSIONS } ` ,
460- data : {
461- supportedVersions : SUPPORTED_PROTOCOL_VERSIONS ,
462- } ,
463- } ) ;
464- }
465- }
431+ // The MCP spec defines that a server should attempt to negotiate
432+ // the highest protocol version it supports:
433+ // https://modelcontextprotocol.info/specification/2024-11-05/basic/lifecycle/#version-negotiation
434+ const requestedVersion = parseResult . data . params . protocolVersion ;
435+ const negotiatedVersion = SUPPORTED_PROTOCOL_VERSIONS . includes (
436+ requestedVersion
437+ )
438+ ? requestedVersion
439+ : LATEST_PROTOCOL_VERSION ;
440+
441+ const initResponse : InitializeResult = {
442+ protocolVersion : negotiatedVersion ,
443+ capabilities : this . getCapabilities ( ) ,
444+ serverInfo : {
445+ name : this . name ,
446+ version : this . version ,
447+ } ,
448+ ...( this . instructions ? { instructions : this . instructions } : { } ) ,
449+ } ;
450+
451+ return newJSONRPCReponse ( { id : request . id , result : initResponse } ) ;
466452 }
467453
468454 private async handleToolListRequest (
0 commit comments