@@ -62,6 +62,7 @@ export class SSEClientTransport implements Transport {
6262 private _eventSourceInit ?: EventSourceInit ;
6363 private _requestInit ?: RequestInit ;
6464 private _authProvider ?: OAuthClientProvider ;
65+ private _protocolVersion ?: string ;
6566
6667 onclose ?: ( ) => void ;
6768 onerror ?: ( error : Error ) => void ;
@@ -99,13 +100,18 @@ export class SSEClientTransport implements Transport {
99100 }
100101
101102 private async _commonHeaders ( ) : Promise < HeadersInit > {
102- const headers : HeadersInit = { ...this . _requestInit ?. headers } ;
103+ const headers = {
104+ ...this . _requestInit ?. headers ,
105+ } as HeadersInit & Record < string , string > ;
103106 if ( this . _authProvider ) {
104107 const tokens = await this . _authProvider . tokens ( ) ;
105108 if ( tokens ) {
106- ( headers as Record < string , string > ) [ "Authorization" ] = `Bearer ${ tokens . access_token } ` ;
109+ headers [ "Authorization" ] = `Bearer ${ tokens . access_token } ` ;
107110 }
108111 }
112+ if ( this . _protocolVersion ) {
113+ headers [ "mcp-protocol-version" ] = this . _protocolVersion ;
114+ }
109115
110116 return headers ;
111117 }
@@ -214,7 +220,7 @@ export class SSEClientTransport implements Transport {
214220
215221 try {
216222 const commonHeaders = await this . _commonHeaders ( ) ;
217- const headers = new Headers ( { ... commonHeaders , ... this . _requestInit ?. headers } ) ;
223+ const headers = new Headers ( commonHeaders ) ;
218224 headers . set ( "content-type" , "application/json" ) ;
219225 const init = {
220226 ...this . _requestInit ,
@@ -249,4 +255,8 @@ export class SSEClientTransport implements Transport {
249255 throw error ;
250256 }
251257 }
258+
259+ setProtocolVersion ( version : string ) : void {
260+ this . _protocolVersion = version ;
261+ }
252262}
0 commit comments