mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 12:51:26 +08:00
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:
parent
aca1fcad18
commit
a9a38f88bb
@ -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": { ... } }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user