fix: transform parameters when adding mcp by json (#9850)

* fix(mcp): 添加 streamable_http 类型并转换为 streamableHttp

为了兼容其他配置,添加 streamable_http 类型并在解析时自动转换为 streamableHttp

* feat(mcp): 根据URL自动推断服务器类型

当未显式指定服务器类型时,通过检查URL后缀自动设置合适的类型(mcp或sse)

* feat(mcp): 添加http类型支持并映射到streamableHttp
This commit is contained in:
Phantom 2025-09-03 21:30:26 +08:00 committed by GitHub
parent aca1fcad18
commit a9a38f88bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,7 +16,21 @@ export type MCPConfigSample = z.infer<typeof MCPConfigSampleSchema>
* 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": { ... } }