@@ -62,6 +62,7 @@ export class SSEClientTransport implements Transport {
62
62
private _eventSourceInit ?: EventSourceInit ;
63
63
private _requestInit ?: RequestInit ;
64
64
private _authProvider ?: OAuthClientProvider ;
65
+ private _protocolVersion ?: string ;
65
66
66
67
onclose ?: ( ) => void ;
67
68
onerror ?: ( error : Error ) => void ;
@@ -99,13 +100,18 @@ export class SSEClientTransport implements Transport {
99
100
}
100
101
101
102
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 > ;
103
106
if ( this . _authProvider ) {
104
107
const tokens = await this . _authProvider . tokens ( ) ;
105
108
if ( tokens ) {
106
- ( headers as Record < string , string > ) [ "Authorization" ] = `Bearer ${ tokens . access_token } ` ;
109
+ headers [ "Authorization" ] = `Bearer ${ tokens . access_token } ` ;
107
110
}
108
111
}
112
+ if ( this . _protocolVersion ) {
113
+ headers [ "mcp-protocol-version" ] = this . _protocolVersion ;
114
+ }
109
115
110
116
return headers ;
111
117
}
@@ -214,7 +220,7 @@ export class SSEClientTransport implements Transport {
214
220
215
221
try {
216
222
const commonHeaders = await this . _commonHeaders ( ) ;
217
- const headers = new Headers ( { ... commonHeaders , ... this . _requestInit ?. headers } ) ;
223
+ const headers = new Headers ( commonHeaders ) ;
218
224
headers . set ( "content-type" , "application/json" ) ;
219
225
const init = {
220
226
...this . _requestInit ,
@@ -249,4 +255,8 @@ export class SSEClientTransport implements Transport {
249
255
throw error ;
250
256
}
251
257
}
258
+
259
+ setProtocolVersion ( version : string ) : void {
260
+ this . _protocolVersion = version ;
261
+ }
252
262
}
0 commit comments