@@ -2,8 +2,12 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
import {
3
3
SSEClientTransport ,
4
4
SseError ,
5
+ SSEClientTransportOptions ,
5
6
} from "@modelcontextprotocol/sdk/client/sse.js" ;
6
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js" ;
7
+ import {
8
+ StreamableHTTPClientTransport ,
9
+ StreamableHTTPClientTransportOptions ,
10
+ } from "@modelcontextprotocol/sdk/client/streamableHttp.js" ;
7
11
import {
8
12
ClientNotification ,
9
13
ClientRequest ,
@@ -279,29 +283,6 @@ export function useConnection({
279
283
setConnectionStatus ( "error-connecting-to-proxy" ) ;
280
284
return ;
281
285
}
282
- let mcpProxyServerUrl ;
283
- switch ( transportType ) {
284
- case "stdio" :
285
- mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /stdio` ) ;
286
- mcpProxyServerUrl . searchParams . append ( "command" , command ) ;
287
- mcpProxyServerUrl . searchParams . append ( "args" , args ) ;
288
- mcpProxyServerUrl . searchParams . append ( "env" , JSON . stringify ( env ) ) ;
289
- break ;
290
-
291
- case "sse" :
292
- mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /sse` ) ;
293
- mcpProxyServerUrl . searchParams . append ( "url" , sseUrl ) ;
294
- break ;
295
-
296
- case "streamable-http" :
297
- mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /mcp` ) ;
298
- mcpProxyServerUrl . searchParams . append ( "url" , sseUrl ) ;
299
- break ;
300
- }
301
- ( mcpProxyServerUrl as URL ) . searchParams . append (
302
- "transportType" ,
303
- transportType ,
304
- ) ;
305
286
306
287
try {
307
288
// Inject auth manually instead of using SSEClientTransport, because we're
@@ -320,17 +301,66 @@ export function useConnection({
320
301
}
321
302
322
303
// Create appropriate transport
323
- const transportOptions = {
324
- eventSourceInit : {
325
- fetch : (
326
- url : string | URL | globalThis . Request ,
327
- init : RequestInit | undefined ,
328
- ) => fetch ( url , { ...init , headers } ) ,
329
- } ,
330
- requestInit : {
331
- headers,
332
- } ,
333
- } ;
304
+ let transportOptions :
305
+ | StreamableHTTPClientTransportOptions
306
+ | SSEClientTransportOptions ;
307
+
308
+ let mcpProxyServerUrl ;
309
+ switch ( transportType ) {
310
+ case "stdio" :
311
+ mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /stdio` ) ;
312
+ mcpProxyServerUrl . searchParams . append ( "command" , command ) ;
313
+ mcpProxyServerUrl . searchParams . append ( "args" , args ) ;
314
+ mcpProxyServerUrl . searchParams . append ( "env" , JSON . stringify ( env ) ) ;
315
+ transportOptions = { } ;
316
+ break ;
317
+
318
+ case "sse" :
319
+ mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /sse` ) ;
320
+ mcpProxyServerUrl . searchParams . append ( "url" , sseUrl ) ;
321
+ transportOptions = {
322
+ authProvider : serverAuthProvider ,
323
+ eventSourceInit : {
324
+ fetch : (
325
+ url : string | URL | globalThis . Request ,
326
+ init : RequestInit | undefined ,
327
+ ) => fetch ( url , { ...init , headers } ) ,
328
+ } ,
329
+ requestInit : {
330
+ headers,
331
+ } ,
332
+ } ;
333
+ break ;
334
+
335
+ case "streamable-http" :
336
+ mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /mcp` ) ;
337
+ mcpProxyServerUrl . searchParams . append ( "url" , sseUrl ) ;
338
+ transportOptions = {
339
+ authProvider : serverAuthProvider ,
340
+ eventSourceInit : {
341
+ fetch : (
342
+ url : string | URL | globalThis . Request ,
343
+ init : RequestInit | undefined ,
344
+ ) => fetch ( url , { ...init , headers } ) ,
345
+ } ,
346
+ requestInit : {
347
+ headers,
348
+ } ,
349
+ // TODO these should be configurable...
350
+ reconnectionOptions : {
351
+ maxReconnectionDelay : 30000 ,
352
+ initialReconnectionDelay : 1000 ,
353
+ reconnectionDelayGrowFactor : 1.5 ,
354
+ maxRetries : 2 ,
355
+ } ,
356
+ } ;
357
+ break ;
358
+ }
359
+ ( mcpProxyServerUrl as URL ) . searchParams . append (
360
+ "transportType" ,
361
+ transportType ,
362
+ ) ;
363
+
334
364
const clientTransport =
335
365
transportType === "streamable-http"
336
366
? new StreamableHTTPClientTransport ( mcpProxyServerUrl as URL , {
0 commit comments