diff --git a/service/src/mcp/client.dto.ts b/service/src/mcp/client.dto.ts index 0235354..cd30ce0 100644 --- a/service/src/mcp/client.dto.ts +++ b/service/src/mcp/client.dto.ts @@ -1,5 +1,6 @@ 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 { Implementation } from "@modelcontextprotocol/sdk/types"; export interface GetPromptOption { @@ -17,9 +18,9 @@ export interface CallToolOption { } // 定义连接类型 -export type ConnectionType = 'STDIO' | 'SSE'; +export type ConnectionType = 'STDIO' | 'SSE' | 'STREAMABLE_HTTP'; -export type McpTransport = StdioClientTransport | SSEClientTransport; +export type McpTransport = StdioClientTransport | SSEClientTransport | StreamableHTTPClientTransport; export type IServerVersion = Implementation | undefined; // 定义命令行参数接口 diff --git a/service/src/mcp/client.service.ts b/service/src/mcp/client.service.ts index 1721f2a..29ebe99 100644 --- a/service/src/mcp/client.service.ts +++ b/service/src/mcp/client.service.ts @@ -2,6 +2,7 @@ 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 type { McpOptions, McpTransport, IServerVersion, ToolCallResponse, ToolCallContent } from './client.dto'; import { PostMessageble } from "../hook/adapter"; import { createOcrWorker, saveBase64ImageData } from "./ocr.service"; @@ -52,10 +53,21 @@ export class McpClient { throw new Error('URL is required for SSE connection'); } this.transport = new SSEClientTransport( - new URL(this.options.url) + new URL(this.options.url), + { + // authProvider: + } ); break; + + case 'STREAMABLE_HTTP': + if (!this.options.url) { + throw new Error('URL is required for STREAMABLE_HTTP connection'); + } + this.transport = new StreamableHTTPClientTransport( + new URL(this.options.url) + ); default: throw new Error(`Unsupported connection type: ${this.options.connectionType}`); }