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 @@ -52,6 +52,25 @@ export const serializeError = (err: unknown): string => {
5252 }
5353}
5454
55+ const formatToolResult = (
56+ toolResult : string | { type : 'text' ; text : string } | Array < { type : 'text' ; text : string } >
57+ ) => {
58+ let result : any = toolResult
59+ if ( Array . isArray ( result ) && result . length === 1 ) {
60+ result = result [ 0 ]
61+ }
62+
63+ if ( typeof result === 'object' && result . type === 'text' && result . text ) {
64+ result = result . text
65+ }
66+
67+ if ( typeof result === 'string' ) {
68+ return result
69+ }
70+
71+ return JSON . stringify ( result )
72+ }
73+
5574const handleToolCall = async (
5675 res : LLMResponse ,
5776 tools : RequestTool [ ] ,
@@ -99,8 +118,7 @@ const handleToolCall = async (
99118 toolCallResult = serializeError ( error )
100119 }
101120 toolMessages . push ( {
102- type : 'text' ,
103- content : toolCallResult ,
121+ content : formatToolResult ( toolCallResult ) ,
104122 role : 'tool' ,
105123 tool_call_id : tool . id
106124 } )
You can’t perform that action at this time.
0 commit comments