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