Revert "fix(mcp): 修复了mcp无法调用功能的问题 (#3047)"

This reverts commit c44f3b8a3d37b95407e7581d66c0cc36c51d1c6b.
This commit is contained in:
kangfenmao 2025-03-09 11:11:25 +08:00
parent aa33f0242a
commit 9c9f200874

View File

@ -52,11 +52,8 @@ export function openAIToolsToMcpTool(
if (!tool) {
return undefined
}
// 创建工具对象的副本,而不是直接修改原对象
return {
...tool,
inputSchema: JSON.parse(llmTool.function.arguments)
}
tool.inputSchema = JSON.parse(llmTool.function.arguments)
return tool
}
export async function callMCPTool(tool: MCPTool): Promise<any> {
@ -85,12 +82,9 @@ export function anthropicToolUseToMcpTool(mcpTools: MCPTool[] | undefined, toolU
if (!tool) {
return undefined
}
// 创建工具对象的副本,而不是直接修改原对象
return {
...tool,
// @ts-ignore ignore type as it it unknow
inputSchema: toolUse.input
}
tool.inputSchema = toolUse.input
return tool
}
export function mcpToolsToGeminiTools(mcpTools: MCPTool[] | undefined): geminiToool[] {
@ -126,12 +120,9 @@ export function geminiFunctionCallToMcpTool(
if (!tool) {
return undefined
}
// 创建工具对象的副本,而不是直接修改原对象
return {
...tool,
// @ts-ignore schema is not a valid property
inputSchema: fcall.args
}
tool.inputSchema = fcall.args
return tool
}
export function upsertMCPToolResponse(
@ -140,35 +131,15 @@ export function upsertMCPToolResponse(
onChunk: ({ mcpToolResponse }: ChunkCallbackData) => void
) {
try {
// 创建一个新数组,不修改原数组
const newResults: MCPToolResponse[] = []
let found = false
// 复制原数组中的元素到新数组如果找到匹配的工具ID则更新
for (const item of results) {
if (item.tool.id === resp.tool.id) {
// 找到匹配的工具,添加更新后的对象
newResults.push({ ...item, response: resp.response, status: resp.status })
found = true
} else {
// 否则添加原对象的副本
newResults.push({ ...item })
for (const ret of results) {
if (ret.tool.id == resp.tool.id) {
ret.response = resp.response
ret.status = resp.status
return
}
}
// 如果没有找到匹配的工具ID添加新的响应
if (!found) {
newResults.push({ ...resp })
}
// 调用回调函数,传递新数组
onChunk({
text: '',
mcpToolResponse: newResults
})
} catch (error) {
console.error('Error in upsertMCPToolResponse:', error)
// 出错时仍然调用回调,但使用原数组
results.push(resp)
} finally {
onChunk({
text: '',
mcpToolResponse: results
@ -180,13 +151,11 @@ export function filterMCPTools(
mcpTools: MCPTool[] | undefined,
enabledServers: MCPServer[] | undefined
): MCPTool[] | undefined {
console.log('filterMCPTools', mcpTools, enabledServers)
if (mcpTools) {
if (enabledServers) {
mcpTools = mcpTools.filter((t) => enabledServers.some((m) => m.name === t.serverName))
} else {
// TODO enabledServers 存在bug传入一直为undefined
// mcpTools = []
mcpTools = []
}
}
return mcpTools