From 9a92372c3e7a196545ac97d24d4dbfa7b62f61df Mon Sep 17 00:00:00 2001 From: Phantom <59059173+EurFelux@users.noreply.github.com> Date: Thu, 4 Sep 2025 11:41:26 +0800 Subject: [PATCH] refactor(mcp): use includes http to detect streamable http type mcp server (#9865) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor(mcp): 简化 McpServerTypeSchema 的类型校验逻辑 将联合类型替换为字符串校验并优化 http 相关类型的转换 --- src/renderer/src/types/mcp.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/types/mcp.ts b/src/renderer/src/types/mcp.ts index 18fd6683f2..cfc7271714 100644 --- a/src/renderer/src/types/mcp.ts +++ b/src/renderer/src/types/mcp.ts @@ -16,22 +16,18 @@ export type MCPConfigSample = z.infer * 允许 inMemory 作为合法字段,需要额外校验 name 是否 builtin */ export const McpServerTypeSchema = z - .union([ - z.literal('stdio'), - z.literal('sse'), - z.literal('streamableHttp'), - z.literal('http'), - z.literal('streamable_http'), - z.literal('inMemory') - ]) + .string() .transform((type) => { - if (type === 'streamable_http' || type === 'http') { + if (type.includes('http')) { return 'streamableHttp' } else { return type } }) - .default('stdio') // 大多数情况下默认使用 stdio + .pipe( + z.union([z.literal('stdio'), z.literal('sse'), z.literal('streamableHttp'), z.literal('inMemory')]).default('stdio') // 大多数情况下默认使用 stdio + ) + /** * 定义单个 MCP 服务器的配置。 * FIXME: 为了兼容性,暂时允许用户编辑任意字段,这可能会导致问题。