mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-11 20:43:42 +08:00
Add StreamableHttp support
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { MCPClientLogger } from "./logger";
|
||||
import {
|
||||
ListToolsResponse,
|
||||
McpRequestMessage,
|
||||
ServerConfig,
|
||||
isServerSseConfig,
|
||||
} from "./types";
|
||||
import { ListToolsResponse, McpRequestMessage, ServerConfig } from "./types";
|
||||
import { z } from "zod";
|
||||
|
||||
const logger = new MCPClientLogger();
|
||||
@@ -18,11 +13,16 @@ export async function createClient(
|
||||
|
||||
let transport;
|
||||
|
||||
if (isServerSseConfig(config)) {
|
||||
if (config.type === "sse") {
|
||||
const { SSEClientTransport } = await import(
|
||||
"@modelcontextprotocol/sdk/client/sse.js"
|
||||
);
|
||||
transport = new SSEClientTransport(new URL(config.url));
|
||||
} else if (config.type === "streamable") {
|
||||
const { StreamableHTTPClientTransport } = await import(
|
||||
"@modelcontextprotocol/sdk/client/streamableHttp.js"
|
||||
);
|
||||
transport = new StreamableHTTPClientTransport(new URL(config.url));
|
||||
} else {
|
||||
if (EXPORT_MODE) {
|
||||
throw new Error(
|
||||
|
@@ -116,10 +116,15 @@ export interface ServerStatusResponse {
|
||||
|
||||
export const isServerSseConfig = (c?: ServerConfig): c is ServerSseConfig =>
|
||||
c !== null && typeof c === "object" && c.type === "sse";
|
||||
export const isStreamableSseConfig = (c?: ServerConfig): c is ServerSseConfig =>
|
||||
c !== null && typeof c === "object" && c.type === "streamable";
|
||||
export const isServerStdioConfig = (c?: ServerConfig): c is ServerStdioConfig =>
|
||||
c !== null && typeof c === "object" && (!c.type || c.type === "stdio");
|
||||
|
||||
export type ServerConfig = ServerStdioConfig | ServerSseConfig;
|
||||
export type ServerConfig =
|
||||
| ServerStdioConfig
|
||||
| ServerSseConfig
|
||||
| ServerSteamableConfig;
|
||||
|
||||
export interface ServerStdioConfig {
|
||||
type?: "stdio";
|
||||
@@ -136,6 +141,13 @@ export interface ServerSseConfig {
|
||||
status?: "active" | "paused" | "error";
|
||||
}
|
||||
|
||||
export interface ServerSteamableConfig {
|
||||
type: "streamable";
|
||||
url: string;
|
||||
headers?: Record<string, string>;
|
||||
status?: "active" | "paused" | "error";
|
||||
}
|
||||
|
||||
export interface McpConfigData {
|
||||
enableMcp?: boolean;
|
||||
// MCP Server 的配置
|
||||
|
Reference in New Issue
Block a user