33 SSEClientTransport ,
44 SseError ,
55} from "@modelcontextprotocol/sdk/client/sse.js" ;
6+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js" ;
67import {
78 ClientNotification ,
89 ClientRequest ,
@@ -278,15 +279,29 @@ export function useConnection({
278279 setConnectionStatus ( "error-connecting-to-proxy" ) ;
279280 return ;
280281 }
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 ;
289300 }
301+ ( mcpProxyServerUrl as URL ) . searchParams . append (
302+ "transportType" ,
303+ transportType ,
304+ ) ;
290305
291306 try {
292307 // Inject auth manually instead of using SSEClientTransport, because we're
@@ -304,14 +319,24 @@ export function useConnection({
304319 headers [ authHeaderName ] = `Bearer ${ token } ` ;
305320 }
306321
307- const clientTransport = new SSEClientTransport ( mcpProxyServerUrl , {
322+ // Create appropriate transport
323+ const transportOptions = {
308324 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 } ) ,
310329 } ,
311330 requestInit : {
312331 headers,
313332 } ,
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 ) ;
315340
316341 if ( onNotification ) {
317342 [
0 commit comments