@@ -106,10 +106,8 @@ export class SSEClientTransport implements Transport {
106
106
return await this . _startOrAuth ( ) ;
107
107
}
108
108
109
- private async _commonHeaders ( ) : Promise < HeadersInit > {
110
- const headers = {
111
- ...this . _requestInit ?. headers ,
112
- } as HeadersInit & Record < string , string > ;
109
+ private async _commonHeaders ( ) : Promise < Headers > {
110
+ const headers : HeadersInit = { } ;
113
111
if ( this . _authProvider ) {
114
112
const tokens = await this . _authProvider . tokens ( ) ;
115
113
if ( tokens ) {
@@ -120,24 +118,24 @@ export class SSEClientTransport implements Transport {
120
118
headers [ "mcp-protocol-version" ] = this . _protocolVersion ;
121
119
}
122
120
123
- return headers ;
121
+ return new Headers (
122
+ { ...headers , ...this . _requestInit ?. headers }
123
+ ) ;
124
124
}
125
125
126
126
private _startOrAuth ( ) : Promise < void > {
127
- const fetchImpl = ( this ?. _eventSourceInit ?. fetch ?? this . _fetch ?? fetch ) as typeof fetch
127
+ const fetchImpl = ( this ?. _eventSourceInit ?. fetch ?? this . _fetch ?? fetch ) as typeof fetch
128
128
return new Promise ( ( resolve , reject ) => {
129
129
this . _eventSource = new EventSource (
130
130
this . _url . href ,
131
131
{
132
132
...this . _eventSourceInit ,
133
133
fetch : async ( url , init ) => {
134
- const headers = await this . _commonHeaders ( )
134
+ const headers = await this . _commonHeaders ( ) ;
135
+ headers . set ( "Accept" , "text/event-stream" ) ;
135
136
const response = await fetchImpl ( url , {
136
137
...init ,
137
- headers : new Headers ( {
138
- ...headers ,
139
- Accept : "text/event-stream"
140
- } )
138
+ headers,
141
139
} )
142
140
143
141
if ( response . status === 401 && response . headers . has ( 'www-authenticate' ) ) {
@@ -238,8 +236,7 @@ const fetchImpl = (this?._eventSourceInit?.fetch ?? this._fetch ?? fetch) as typ
238
236
}
239
237
240
238
try {
241
- const commonHeaders = await this . _commonHeaders ( ) ;
242
- const headers = new Headers ( commonHeaders ) ;
239
+ const headers = await this . _commonHeaders ( ) ;
243
240
headers . set ( "content-type" , "application/json" ) ;
244
241
const init = {
245
242
...this . _requestInit ,
0 commit comments