@@ -142,6 +142,18 @@ export interface WebStandardStreamableHTTPServerTransportOptions {
142142 * client reconnection timing for polling behavior.
143143 */
144144 retryInterval ?: number ;
145+
146+ /**
147+ * List of protocol versions that this transport will accept.
148+ * Used to validate the mcp-protocol-version header in incoming requests.
149+ *
150+ * Note: When using Server.connect(), the server automatically passes its
151+ * supportedProtocolVersions to the transport, so you typically don't need
152+ * to set this option directly.
153+ *
154+ * @default SUPPORTED_PROTOCOL_VERSIONS
155+ */
156+ supportedProtocolVersions ?: string [ ] ;
145157}
146158
147159/**
@@ -220,6 +232,7 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
220232 private _allowedOrigins ?: string [ ] ;
221233 private _enableDnsRebindingProtection : boolean ;
222234 private _retryInterval ?: number ;
235+ private _supportedProtocolVersions : string [ ] ;
223236
224237 sessionId ?: string ;
225238 onclose ?: ( ) => void ;
@@ -236,6 +249,7 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
236249 this . _allowedOrigins = options . allowedOrigins ;
237250 this . _enableDnsRebindingProtection = options . enableDnsRebindingProtection ?? false ;
238251 this . _retryInterval = options . retryInterval ;
252+ this . _supportedProtocolVersions = options . supportedProtocolVersions ?? SUPPORTED_PROTOCOL_VERSIONS ;
239253 }
240254
241255 /**
@@ -249,6 +263,14 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
249263 this . _started = true ;
250264 }
251265
266+ /**
267+ * Sets the supported protocol versions for header validation.
268+ * Called by the server during connect() to pass its supported versions.
269+ */
270+ setSupportedProtocolVersions ( versions : string [ ] ) : void {
271+ this . _supportedProtocolVersions = versions ;
272+ }
273+
252274 /**
253275 * Helper to create a JSON error response
254276 */
@@ -848,11 +870,11 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
848870 private validateProtocolVersion ( req : Request ) : Response | undefined {
849871 const protocolVersion = req . headers . get ( 'mcp-protocol-version' ) ;
850872
851- if ( protocolVersion !== null && ! SUPPORTED_PROTOCOL_VERSIONS . includes ( protocolVersion ) ) {
873+ if ( protocolVersion !== null && ! this . _supportedProtocolVersions . includes ( protocolVersion ) ) {
852874 return this . createJsonErrorResponse (
853875 400 ,
854876 - 32_000 ,
855- `Bad Request: Unsupported protocol version: ${ protocolVersion } (supported versions: ${ SUPPORTED_PROTOCOL_VERSIONS . join ( ', ' ) } )`
877+ `Bad Request: Unsupported protocol version: ${ protocolVersion } (supported versions: ${ this . _supportedProtocolVersions . join ( ', ' ) } )`
856878 ) ;
857879 }
858880 return undefined ;
0 commit comments