3
3
SSEClientTransport ,
4
4
SseError ,
5
5
} from "@modelcontextprotocol/sdk/client/sse.js" ;
6
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js" ;
6
7
import {
7
8
ClientNotification ,
8
9
ClientRequest ,
@@ -278,15 +279,29 @@ export function useConnection({
278
279
setConnectionStatus ( "error-connecting-to-proxy" ) ;
279
280
return ;
280
281
}
281
- const mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /sse` ) ;
282
- mcpProxyServerUrl . searchParams . append ( "transportType" , transportType ) ;
283
- if ( transportType === "stdio" ) {
284
- mcpProxyServerUrl . searchParams . append ( "command" , command ) ;
285
- mcpProxyServerUrl . searchParams . append ( "args" , args ) ;
286
- mcpProxyServerUrl . searchParams . append ( "env" , JSON . stringify ( env ) ) ;
287
- } else {
288
- mcpProxyServerUrl . searchParams . append ( "url" , sseUrl ) ;
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 ;
289
300
}
301
+ ( mcpProxyServerUrl as URL ) . searchParams . append (
302
+ "transportType" ,
303
+ transportType ,
304
+ ) ;
290
305
291
306
try {
292
307
// Inject auth manually instead of using SSEClientTransport, because we're
@@ -304,14 +319,24 @@ export function useConnection({
304
319
headers [ authHeaderName ] = `Bearer ${ token } ` ;
305
320
}
306
321
307
- const clientTransport = new SSEClientTransport ( mcpProxyServerUrl , {
322
+ // Create appropriate transport
323
+ const transportOptions = {
308
324
eventSourceInit : {
309
- fetch : ( url , init ) => fetch ( url , { ...init , headers } ) ,
325
+ fetch : (
326
+ url : string | URL | globalThis . Request ,
327
+ init : RequestInit | undefined ,
328
+ ) => fetch ( url , { ...init , headers } ) ,
310
329
} ,
311
330
requestInit : {
312
331
headers,
313
332
} ,
314
- } ) ;
333
+ } ;
334
+ const clientTransport =
335
+ transportType === "streamable-http"
336
+ ? new StreamableHTTPClientTransport ( mcpProxyServerUrl as URL , {
337
+ sessionId : undefined ,
338
+ } )
339
+ : new SSEClientTransport ( mcpProxyServerUrl as URL , transportOptions ) ;
315
340
316
341
if ( onNotification ) {
317
342
[
0 commit comments