@@ -24,6 +24,14 @@ function maybeBundleImport<T>(moduleName: string): T {
2424
2525const { apiRequest } = maybeBundleImport < BridgeClientModule > ( 'api/bridge-client' ) ;
2626
27+ const LATEST_LEGACY_MCP_PROTOCOL_VERSION = '2025-11-25' ;
28+ const SUPPORTED_LEGACY_MCP_PROTOCOL_VERSIONS = new Set ( [
29+ LATEST_LEGACY_MCP_PROTOCOL_VERSION ,
30+ '2025-06-18' ,
31+ '2025-03-26' ,
32+ '2024-11-05'
33+ ] ) ;
34+
2735interface JsonRpcRequest {
2836 jsonrpc : '2.0' ;
2937 id ?: number | string ;
@@ -56,6 +64,13 @@ function jsonRpcError(id: number | string | null, code: number, message: string)
5664 sendJsonRpc ( { jsonrpc : '2.0' , id, error : { code, message } } ) ;
5765}
5866
67+ function negotiateLegacyProtocolVersion ( requestedVersion : unknown ) : string {
68+ return typeof requestedVersion === 'string' &&
69+ SUPPORTED_LEGACY_MCP_PROTOCOL_VERSIONS . has ( requestedVersion )
70+ ? requestedVersion
71+ : LATEST_LEGACY_MCP_PROTOCOL_VERSION ;
72+ }
73+
5974function operationsToMcpTools ( operations : HtkOperation [ ] ) : any [ ] {
6075 return operations . map ( op => ( {
6176 name : op . name . replace ( / \. / g, '_' ) ,
@@ -362,9 +377,13 @@ async function runMcpServer(): Promise<void> {
362377
363378 function handleMessage ( msg : JsonRpcRequest ) : void {
364379 switch ( msg . method ) {
365- case 'initialize' :
380+ case 'initialize' : {
381+ const protocolVersion = negotiateLegacyProtocolVersion (
382+ msg . params ?. protocolVersion
383+ ) ;
384+
366385 jsonRpcResult ( msg . id ! , {
367- protocolVersion : '2024-11-05' ,
386+ protocolVersion,
368387 capabilities : {
369388 tools : { listChanged : true }
370389 } ,
@@ -374,6 +393,7 @@ async function runMcpServer(): Promise<void> {
374393 }
375394 } ) ;
376395 break ;
396+ }
377397
378398 case 'ping' :
379399 jsonRpcResult ( msg . id ! , { } ) ;
0 commit comments