Support MCP StreamableHTTPClientTransport (#1014)

This commit is contained in:
Shreya Keshive
2025-06-13 20:18:06 +00:00
committed by GitHub
parent 491e367f7c
commit 1fa41af918
3 changed files with 12 additions and 105 deletions

View File

@@ -7,12 +7,12 @@
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { parse } from 'shell-quote';
import { MCPServerConfig } from '../config/config.js';
import { DiscoveredMCPTool } from './mcp-tool.js';
import { CallableTool, FunctionDeclaration, mcpToTool } from '@google/genai';
import { ToolRegistry } from './tool-registry.js';
import { WebSocketClientTransport } from './websocket-client-transport.js';
export const MCP_DEFAULT_TIMEOUT_MSEC = 10 * 60 * 1000; // default to 10 minutes
@@ -163,10 +163,12 @@ async function connectAndDiscover(
updateMCPServerStatus(mcpServerName, MCPServerStatus.CONNECTING);
let transport;
if (mcpServerConfig.url) {
if (mcpServerConfig.httpUrl) {
transport = new StreamableHTTPClientTransport(
new URL(mcpServerConfig.httpUrl),
);
} else if (mcpServerConfig.url) {
transport = new SSEClientTransport(new URL(mcpServerConfig.url));
} else if (mcpServerConfig.tcp) {
transport = new WebSocketClientTransport(new URL(mcpServerConfig.tcp));
} else if (mcpServerConfig.command) {
transport = new StdioClientTransport({
command: mcpServerConfig.command,
@@ -180,7 +182,7 @@ async function connectAndDiscover(
});
} else {
console.error(
`MCP server '${mcpServerName}' has invalid configuration: missing url (for SSE), tcp (for websocket), and command (for stdio). Skipping.`,
`MCP server '${mcpServerName}' has invalid configuration: missing httpUrl (for Streamable HTTP), url (for SSE), and command (for stdio). Skipping.`,
);
// Update status to disconnected
updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED);
@@ -260,7 +262,7 @@ async function connectAndDiscover(
if (
transport instanceof StdioClientTransport ||
transport instanceof SSEClientTransport ||
transport instanceof WebSocketClientTransport
transport instanceof StreamableHTTPClientTransport
) {
await transport.close();
}
@@ -321,7 +323,7 @@ async function connectAndDiscover(
if (
transport instanceof StdioClientTransport ||
transport instanceof SSEClientTransport ||
transport instanceof WebSocketClientTransport
transport instanceof StreamableHTTPClientTransport
) {
await transport.close();
}
@@ -341,7 +343,7 @@ async function connectAndDiscover(
if (
transport instanceof StdioClientTransport ||
transport instanceof SSEClientTransport ||
transport instanceof WebSocketClientTransport
transport instanceof StreamableHTTPClientTransport
) {
await transport.close();
// Update status to disconnected