From a9a38f88bba242d09a1c0f7d8d9a633df3a8a9da Mon Sep 17 00:00:00 2001 From: Phantom <59059173+EurFelux@users.noreply.github.com> Date: Wed, 3 Sep 2025 21:30:26 +0800 Subject: [PATCH] fix: transform parameters when adding mcp by json (#9850) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(mcp): 添加 streamable_http 类型并转换为 streamableHttp 为了兼容其他配置,添加 streamable_http 类型并在解析时自动转换为 streamableHttp * feat(mcp): 根据URL自动推断服务器类型 当未显式指定服务器类型时,通过检查URL后缀自动设置合适的类型(mcp或sse) * feat(mcp): 添加http类型支持并映射到streamableHttp --- src/renderer/src/types/mcp.ts | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/types/mcp.ts b/src/renderer/src/types/mcp.ts index b2e44180d8..18fd6683f2 100644 --- a/src/renderer/src/types/mcp.ts +++ b/src/renderer/src/types/mcp.ts @@ -16,7 +16,21 @@ export type MCPConfigSample = z.infer * 允许 inMemory 作为合法字段,需要额外校验 name 是否 builtin */ export const McpServerTypeSchema = z - .union([z.literal('stdio'), z.literal('sse'), z.literal('streamableHttp'), z.literal('inMemory')]) + .union([ + z.literal('stdio'), + z.literal('sse'), + z.literal('streamableHttp'), + z.literal('http'), + z.literal('streamable_http'), + z.literal('inMemory') + ]) + .transform((type) => { + if (type === 'streamable_http' || type === 'http') { + return 'streamableHttp' + } else { + return type + } + }) .default('stdio') // 大多数情况下默认使用 stdio /** * 定义单个 MCP 服务器的配置。 @@ -174,6 +188,26 @@ export const McpServerConfigSchema = z message: 'Server type is inMemory but this is not a builtin MCP server, which is not allowed' } ) + .transform((schema) => { + // 显式传入的type会覆盖掉从url推断的逻辑 + if (!schema.type) { + const url = schema.baseUrl ?? schema.url ?? null + if (url !== null) { + if (url.endsWith('/mcp')) { + return { + ...schema, + type: 'streamableHttp' + } as const + } else if (url.endsWith('/sse')) { + return { + ...schema, + type: 'sse' + } as const + } + } + } + return schema + }) /** * 将服务器别名(字符串ID)映射到其配置的对象。 * 例如: { "my-tools": { command: "...", args: [...] }, "github": { ... } }