11import { experimental_createMCPClient , type Tool } from "ai"
2- import { Experimental_StdioMCPTransport } from "ai/mcp-stdio"
2+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
3+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
4+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
35import { App } from "../app/app"
46import { Config } from "../config/config"
57import { Log } from "../util/log"
@@ -32,15 +34,28 @@ export namespace MCP {
3234 }
3335 log . info ( "found" , { key, type : mcp . type } )
3436 if ( mcp . type === "remote" ) {
35- const client = await experimental_createMCPClient ( {
36- name : key ,
37- transport : {
38- type : "sse" ,
39- url : mcp . url ,
40- headers : mcp . headers ,
41- } ,
42- } ) . catch ( ( ) => { } )
43- if ( ! client ) {
37+ const transports = [
38+ new StreamableHTTPClientTransport ( new URL ( mcp . url ) , {
39+ requestInit : {
40+ headers : mcp . headers ,
41+ } ,
42+ } ) ,
43+ new SSEClientTransport ( new URL ( mcp . url ) , {
44+ requestInit : {
45+ headers : mcp . headers ,
46+ } ,
47+ } ) ,
48+ ]
49+ for ( const transport of transports ) {
50+ const client = await experimental_createMCPClient ( {
51+ name : key ,
52+ transport,
53+ } ) . catch ( ( ) => { } )
54+ if ( ! client ) continue
55+ clients [ key ] = client
56+ break
57+ }
58+ if ( ! clients [ key ] )
4459 Bus . publish ( Session . Event . Error , {
4560 error : {
4661 name : "UnknownError" ,
@@ -49,16 +64,13 @@ export namespace MCP {
4964 } ,
5065 } ,
5166 } )
52- continue
53- }
54- clients [ key ] = client
5567 }
5668
5769 if ( mcp . type === "local" ) {
5870 const [ cmd , ...args ] = mcp . command
5971 const client = await experimental_createMCPClient ( {
6072 name : key ,
61- transport : new Experimental_StdioMCPTransport ( {
73+ transport : new StdioClientTransport ( {
6274 stderr : "ignore" ,
6375 command : cmd ,
6476 args,
0 commit comments