File tree Expand file tree Collapse file tree 7 files changed +22
-17
lines changed
Expand file tree Collapse file tree 7 files changed +22
-17
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,9 @@ export class Client<
166166 this . _serverCapabilities = result . capabilities ;
167167 this . _serverVersion = result . serverInfo ;
168168 // HTTP transports must set the protocol version in each header after initialization.
169- transport . protocolVersion = result . protocolVersion ;
169+ if ( transport . setProtocolVersion ) {
170+ transport . setProtocolVersion ( result . protocolVersion ) ;
171+ }
170172
171173 this . _instructions = result . instructions ;
172174
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ export class SSEClientTransport implements Transport {
6262 private _eventSourceInit ?: EventSourceInit ;
6363 private _requestInit ?: RequestInit ;
6464 private _authProvider ?: OAuthClientProvider ;
65- protocolVersion ?: string ;
65+ private _protocolVersion ?: string ;
6666
6767 onclose ?: ( ) => void ;
6868 onerror ?: ( error : Error ) => void ;
@@ -109,8 +109,8 @@ export class SSEClientTransport implements Transport {
109109 headers [ "Authorization" ] = `Bearer ${ tokens . access_token } ` ;
110110 }
111111 }
112- if ( this . protocolVersion ) {
113- headers [ "mcp-protocol-version" ] = this . protocolVersion ;
112+ if ( this . _protocolVersion ) {
113+ headers [ "mcp-protocol-version" ] = this . _protocolVersion ;
114114 }
115115
116116 return headers ;
@@ -255,4 +255,8 @@ export class SSEClientTransport implements Transport {
255255 throw error ;
256256 }
257257 }
258+
259+ setProtocolVersion ( version : string ) : void {
260+ this . _protocolVersion = version ;
261+ }
258262}
Original file line number Diff line number Diff line change @@ -124,7 +124,7 @@ export class StreamableHTTPClientTransport implements Transport {
124124 private _authProvider ?: OAuthClientProvider ;
125125 private _sessionId ?: string ;
126126 private _reconnectionOptions : StreamableHTTPReconnectionOptions ;
127- protocolVersion ?: string ;
127+ private _protocolVersion ?: string ;
128128
129129 onclose ?: ( ) => void ;
130130 onerror ?: ( error : Error ) => void ;
@@ -174,8 +174,8 @@ export class StreamableHTTPClientTransport implements Transport {
174174 if ( this . _sessionId ) {
175175 headers [ "mcp-session-id" ] = this . _sessionId ;
176176 }
177- if ( this . protocolVersion ) {
178- headers [ "mcp-protocol-version" ] = this . protocolVersion ;
177+ if ( this . _protocolVersion ) {
178+ headers [ "mcp-protocol-version" ] = this . _protocolVersion ;
179179 }
180180
181181 return new Headers (
@@ -520,4 +520,11 @@ export class StreamableHTTPClientTransport implements Transport {
520520 throw error ;
521521 }
522522 }
523+
524+ setProtocolVersion ( version : string ) : void {
525+ this . _protocolVersion = version ;
526+ }
527+ get protocolVersion ( ) : string | undefined {
528+ return this . _protocolVersion ;
529+ }
523530}
Original file line number Diff line number Diff line change @@ -254,9 +254,6 @@ export class Server<
254254 const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS . includes ( requestedVersion )
255255 ? requestedVersion
256256 : LATEST_PROTOCOL_VERSION ;
257- if ( this . transport ) {
258- this . transport . protocolVersion = protocolVersion ;
259- }
260257
261258 return {
262259 protocolVersion,
Original file line number Diff line number Diff line change @@ -17,8 +17,6 @@ const MAXIMUM_MESSAGE_SIZE = "4mb";
1717export class SSEServerTransport implements Transport {
1818 private _sseResponse ?: ServerResponse ;
1919 private _sessionId : string ;
20-
21- protocolVersion ?: string ;
2220 onclose ?: ( ) => void ;
2321 onerror ?: ( error : Error ) => void ;
2422 onmessage ?: ( message : JSONRPCMessage , extra ?: { authInfo ?: AuthInfo } ) => void ;
Original file line number Diff line number Diff line change @@ -111,7 +111,6 @@ export class StreamableHTTPServerTransport implements Transport {
111111 private _onsessioninitialized ?: ( sessionId : string ) => void ;
112112
113113 sessionId ?: string ;
114- protocolVersion ?: string ;
115114 onclose ?: ( ) => void ;
116115 onerror ?: ( error : Error ) => void ;
117116 onmessage ?: ( message : JSONRPCMessage , extra ?: { authInfo ?: AuthInfo } ) => void ;
Original file line number Diff line number Diff line change @@ -77,9 +77,7 @@ export interface Transport {
7777 sessionId ?: string ;
7878
7979 /**
80- * The protocol version used for the connection.
81- *
82- * Only set after the initialize response was received.
80+ * Sets the protocol version used for the connection (called when the initialize response is received).
8381 */
84- protocolVersion ?: string ;
82+ setProtocolVersion ?: ( version : string ) => void ;
8583}
You can’t perform that action at this time.
0 commit comments