@@ -30,6 +30,7 @@ import { arePathsEqual } from "@utils/path"
3030import { secondsToMs } from "@utils/time"
3131import { GlobalFileNames } from "@core/storage/disk"
3232import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
33+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
3334import { ExtensionMessage } from "@shared/ExtensionMessage"
3435
3536// Default timeout for internal MCP data requests in milliseconds; is not the same as the user facing timeout stored as DEFAULT_MCP_TIMEOUT_SECONDS
@@ -38,10 +39,10 @@ const DEFAULT_REQUEST_TIMEOUT_MS = 5000
3839export type McpConnection = {
3940 server : McpServer
4041 client : Client
41- transport : StdioClientTransport | SSEClientTransport
42+ transport : StdioClientTransport | SSEClientTransport | StreamableHTTPClientTransport
4243}
4344
44- export type McpTransportType = "stdio" | "sse"
45+ export type McpTransportType = "stdio" | "sse" | "http"
4546
4647export type McpServerConfig = z . infer < typeof ServerConfigSchema >
4748
@@ -54,22 +55,23 @@ const BaseConfigSchema = z.object({
5455} )
5556
5657const SseConfigSchema = BaseConfigSchema . extend ( {
58+ transportType : z . literal ( "sse" ) ,
5759 url : z . string ( ) . url ( ) ,
58- } ) . transform ( ( config ) => ( {
59- ...config ,
60- transportType : "sse" as const ,
61- } ) )
60+ } )
6261
6362const StdioConfigSchema = BaseConfigSchema . extend ( {
63+ transportType : z . literal ( "stdio" ) ,
6464 command : z . string ( ) ,
6565 args : z . array ( z . string ( ) ) . optional ( ) ,
6666 env : z . record ( z . string ( ) ) . optional ( ) ,
67- } ) . transform ( ( config ) => ( {
68- ...config ,
69- transportType : "stdio" as const ,
70- } ) )
67+ } )
68+
69+ const StreamableHTTPConfigSchema = BaseConfigSchema . extend ( {
70+ transportType : z . literal ( "http" ) ,
71+ url : z . string ( ) . url ( ) ,
72+ } )
7173
72- const ServerConfigSchema = z . union ( [ StdioConfigSchema , SseConfigSchema ] )
74+ const ServerConfigSchema = z . discriminatedUnion ( "transportType" , [ StdioConfigSchema , SseConfigSchema , StreamableHTTPConfigSchema ] )
7375
7476const McpSettingsSchema = z . object ( {
7577 mcpServers : z . record ( ServerConfigSchema ) ,
@@ -183,7 +185,7 @@ export class McpHub {
183185
184186 private async connectToServerRPC (
185187 name : string ,
186- config : z . infer < typeof StdioConfigSchema > | z . infer < typeof SseConfigSchema > ,
188+ config : z . infer < typeof StdioConfigSchema > | z . infer < typeof SseConfigSchema > | z . infer < typeof StreamableHTTPConfigSchema > ,
187189 ) : Promise < void > {
188190 // Remove existing connection if it exists (should never happen, the connection should be deleted beforehand)
189191 this . connections = this . connections . filter ( ( conn ) => conn . server . name !== name )
@@ -200,10 +202,12 @@ export class McpHub {
200202 } ,
201203 )
202204
203- let transport : StdioClientTransport | SSEClientTransport
205+ let transport : StdioClientTransport | SSEClientTransport | StreamableHTTPClientTransport
204206
205207 if ( config . transportType === "sse" ) {
206208 transport = new SSEClientTransport ( new URL ( config . url ) , { } )
209+ } else if ( config . transportType === "http" ) {
210+ transport = new StreamableHTTPClientTransport ( new URL ( config . url ) , { } )
207211 } else {
208212 transport = new StdioClientTransport ( {
209213 command : config . command ,
@@ -297,7 +301,7 @@ export class McpHub {
297301
298302 private async connectToServer (
299303 name : string ,
300- config : z . infer < typeof StdioConfigSchema > | z . infer < typeof SseConfigSchema > ,
304+ config : z . infer < typeof StdioConfigSchema > | z . infer < typeof SseConfigSchema > | z . infer < typeof StreamableHTTPConfigSchema > ,
301305 ) : Promise < void > {
302306 // Remove existing connection if it exists (should never happen, the connection should be deleted beforehand)
303307 this . connections = this . connections . filter ( ( conn ) => conn . server . name !== name )
@@ -314,10 +318,12 @@ export class McpHub {
314318 } ,
315319 )
316320
317- let transport : StdioClientTransport | SSEClientTransport
321+ let transport : StdioClientTransport | SSEClientTransport | StreamableHTTPClientTransport
318322
319323 if ( config . transportType === "sse" ) {
320324 transport = new SSEClientTransport ( new URL ( config . url ) , { } )
325+ } else if ( config . transportType === "http" ) {
326+ transport = new StreamableHTTPClientTransport ( new URL ( config . url ) , { } )
321327 } else {
322328 transport = new StdioClientTransport ( {
323329 command : config . command ,
0 commit comments