Skip to content

Commit e580d97

Browse files
committed
fix: call tool failed
1 parent 418ef0e commit e580d97

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

packages/plugins/robot/src/Main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export default {
408408
},
409409
{
410410
label: '页面搭建场景',
411-
description: '如何生成表单嵌进我的网站?',
411+
description: '给当前页面中添加一个问卷调查表单',
412412
icon: h('span', { style: { fontSize: '18px' } as CSSProperties }, '')
413413
},
414414
{

packages/plugins/robot/src/mcp/utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,26 @@ const handleToolCall = async (
7575
formatPretty: true
7676
}
7777
currentMessage.renderContent.push(currentToolMessage)
78-
const toolCallResult = await useMcpServer().callTool(name, parsedArgs)
78+
let toolCallResult
79+
let toolCallStatus
80+
try {
81+
toolCallStatus = 'success'
82+
toolCallResult = (await useMcpServer().callTool(name, parsedArgs)).content
83+
} catch (error) {
84+
toolCallStatus = 'failed'
85+
toolCallResult = JSON.stringify(error)
86+
}
7987
toolMessages.push({
8088
type: 'text',
81-
content: toolCallResult.content,
89+
content: toolCallResult,
8290
role: 'tool',
8391
tool_call_id: tool.id
8492
})
8593

86-
currentMessage.renderContent.at(-1)!.status = 'success'
94+
currentMessage.renderContent.at(-1)!.status = toolCallStatus
8795
currentMessage.renderContent.at(-1)!.content = {
8896
params: parsedArgs,
89-
result: toolCallResult.content
97+
result: toolCallResult
9098
}
9199
}
92100
currentMessage.renderContent.push({ type: 'loading', content: '' })

0 commit comments

Comments
 (0)