File tree Expand file tree Collapse file tree
packages/plugins/robot/src/mcp Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
8698const 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' ,
You can’t perform that action at this time.
0 commit comments