1
1
import { IncomingMessage , ServerResponse } from "node:http" ;
2
2
import { 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" ;
4
4
import getRawBody from "raw-body" ;
5
5
import contentType from "content-type" ;
6
6
import { randomUUID } from "node:crypto" ;
@@ -538,17 +538,12 @@ export class StreamableHTTPServerTransport implements Transport {
538
538
}
539
539
540
540
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 ;
542
542
if ( Array . isArray ( protocolVersion ) ) {
543
543
protocolVersion = protocolVersion [ protocolVersion . length - 1 ] ;
544
544
}
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
+
552
547
if ( this . protocolVersion !== undefined && this . protocolVersion !== protocolVersion ) {
553
548
console . warn ( `Request has header with protocol version ${ protocolVersion } , but version previously negotiated is ${ this . protocolVersion } .` ) ;
554
549
}
@@ -557,7 +552,7 @@ export class StreamableHTTPServerTransport implements Transport {
557
552
jsonrpc : "2.0" ,
558
553
error : {
559
554
code : - 32000 ,
560
- message : ' Bad Request: Unsupported protocol version'
555
+ message : ` Bad Request: Unsupported protocol version (supported versions: ${ SUPPORTED_PROTOCOL_VERSIONS . join ( ", " ) } )`
561
556
} ,
562
557
id : null
563
558
} ) ) ;
0 commit comments