Skip to content

Commit d7228f7

Browse files
committed
fix: review
1 parent 0f1caa0 commit d7228f7

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ const parseArgs = (args: string) => {
8383
}
8484
}
8585

86+
const serializeError = (err: unknown): string => {
87+
if (err instanceof Error) {
88+
return JSON.stringify({ name: err.name, message: err.message })
89+
}
90+
if (typeof err === 'string') return err
91+
try {
92+
return JSON.stringify(err)
93+
} catch {
94+
return String(err)
95+
}
96+
}
97+
8698
const handleToolCall = async (
8799
res: LLMResponse,
88100
tools: RequestTool[],
@@ -119,14 +131,15 @@ const handleToolCall = async (
119131
formatPretty: true
120132
}
121133
currentMessage.renderContent.push(currentToolMessage)
122-
let toolCallResult
123-
let toolCallStatus
134+
let toolCallResult: string
135+
let toolCallStatus: 'success' | 'failed'
124136
try {
137+
const resp = await useMcpServer().callTool(name, parsedArgs)
125138
toolCallStatus = 'success'
126-
toolCallResult = (await useMcpServer().callTool(name, parsedArgs)).content
139+
toolCallResult = resp.content
127140
} catch (error) {
128141
toolCallStatus = 'failed'
129-
toolCallResult = JSON.stringify(error)
142+
toolCallResult = serializeError(error)
130143
}
131144
toolMessages.push({
132145
type: 'text',

0 commit comments

Comments
 (0)