11import { IncomingMessage , ServerResponse } from "node:http" ;
22import { Transport } from "../shared/transport.js" ;
3- import { isInitializeRequest , isJSONRPCError , isJSONRPCRequest , isJSONRPCResponse , JSONRPCMessage , JSONRPCMessageSchema , RequestId , SUPPORTED_PROTOCOL_VERSIONS } from "../types.js" ;
3+ import { isInitializeRequest , isJSONRPCError , isJSONRPCRequest , isJSONRPCResponse , JSONRPCMessage , JSONRPCMessageSchema , RequestId , SUPPORTED_PROTOCOL_VERSIONS , DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from "../types.js" ;
44import getRawBody from "raw-body" ;
55import contentType from "content-type" ;
66import { randomUUID } from "node:crypto" ;
@@ -538,17 +538,12 @@ export class StreamableHTTPServerTransport implements Transport {
538538 }
539539
540540 private validateProtocolVersion ( req : IncomingMessage , res : ServerResponse ) : boolean {
541- let protocolVersion = req . headers [ "mcp-protocol-version" ] ;
541+ let protocolVersion = req . headers [ "mcp-protocol-version" ] ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION ;
542542 if ( Array . isArray ( protocolVersion ) ) {
543543 protocolVersion = protocolVersion [ protocolVersion . length - 1 ] ;
544544 }
545-
546- if ( protocolVersion == null || protocolVersion === undefined ) {
547- // If the protocol version is not set, we assume the client supports the implicit protocol version
548- return true ;
549- }
550-
551- protocolVersion = String ( protocolVersion ) . trim ( ) ;
545+
546+
552547 if ( this . protocolVersion !== undefined && this . protocolVersion !== protocolVersion ) {
553548 console . warn ( `Request has header with protocol version ${ protocolVersion } , but version previously negotiated is ${ this . protocolVersion } .` ) ;
554549 }
@@ -557,7 +552,7 @@ export class StreamableHTTPServerTransport implements Transport {
557552 jsonrpc : "2.0" ,
558553 error : {
559554 code : - 32000 ,
560- message : ' Bad Request: Unsupported protocol version'
555+ message : ` Bad Request: Unsupported protocol version (supported versions: ${ SUPPORTED_PROTOCOL_VERSIONS . join ( ", " ) } )`
561556 } ,
562557 id : null
563558 } ) ) ;
0 commit comments