prepare for stream http
This commit is contained in:
parent
d63b0abaf0
commit
8a8b17cb3f
@ -1,5 +1,6 @@
|
|||||||
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||||
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
||||||
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||||
import { Implementation } from "@modelcontextprotocol/sdk/types";
|
import { Implementation } from "@modelcontextprotocol/sdk/types";
|
||||||
|
|
||||||
export interface GetPromptOption {
|
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;
|
export type IServerVersion = Implementation | undefined;
|
||||||
|
|
||||||
// 定义命令行参数接口
|
// 定义命令行参数接口
|
||||||
|
@ -2,6 +2,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|||||||
|
|
||||||
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||||
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.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 type { McpOptions, McpTransport, IServerVersion, ToolCallResponse, ToolCallContent } from './client.dto';
|
||||||
import { PostMessageble } from "../hook/adapter";
|
import { PostMessageble } from "../hook/adapter";
|
||||||
import { createOcrWorker, saveBase64ImageData } from "./ocr.service";
|
import { createOcrWorker, saveBase64ImageData } from "./ocr.service";
|
||||||
@ -52,10 +53,21 @@ export class McpClient {
|
|||||||
throw new Error('URL is required for SSE connection');
|
throw new Error('URL is required for SSE connection');
|
||||||
}
|
}
|
||||||
this.transport = new SSEClientTransport(
|
this.transport = new SSEClientTransport(
|
||||||
new URL(this.options.url)
|
new URL(this.options.url),
|
||||||
|
{
|
||||||
|
// authProvider:
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
break;
|
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:
|
default:
|
||||||
throw new Error(`Unsupported connection type: ${this.options.connectionType}`);
|
throw new Error(`Unsupported connection type: ${this.options.connectionType}`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user