@@ -14,11 +14,13 @@ import {
1414} from "@modelcontextprotocol/sdk/client/stdio.js" ;
1515import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js" ;
1616import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js" ;
17+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js" ;
1718import express from "express" ;
1819import { findActualExecutable } from "spawn-rx" ;
1920import mcpProxy from "./mcpProxy.js" ;
2021
2122const SSE_HEADERS_PASSTHROUGH = [ "authorization" ] ;
23+ const STREAMABLE_HTTP_HEADERS_PASSTHROUGH = [ "authorization" ] ;
2224
2325const defaultEnvironment = {
2426 ...getDefaultEnvironment ( ) ,
@@ -94,6 +96,29 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
9496
9597 console . log ( "Connected to SSE transport" ) ;
9698 return transport ;
99+ } else if ( transportType === "streamable - http ") {
100+ const headers : HeadersInit = { } ;
101+
102+ for ( const key of STREAMABLE_HTTP_HEADERS_PASSTHROUGH ) {
103+ if ( req . headers [ key ] === undefined ) {
104+ continue ;
105+ }
106+
107+ const value = req . headers [ key ] ;
108+ headers [ key ] = Array . isArray ( value ) ? value [ value . length - 1 ] : value ;
109+ }
110+
111+ const transport = new StreamableHTTPClientTransport (
112+ new URL ( query . url as string ) ,
113+ {
114+ requestInit : {
115+ headers,
116+ } ,
117+ } ,
118+ ) ;
119+ await transport . start ( ) ;
120+ console . log ( "Connected to Streamable HTTP transport" ) ;
121+ return transport ;
97122 } else {
98123 console . error ( `Invalid transport type: ${ transportType } ` ) ;
99124 throw new Error ( "Invalid transport type specified" ) ;
0 commit comments