Fall back to StructuredContent in MCP tool results
When an MCP server sets StructuredContent without populating Content with TextContent entries, extractMCPContent returned an empty string, making successful tool calls look empty to the agent. Now the function serializes StructuredContent as JSON when no text parts are found. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -167,7 +167,7 @@ func (t *mcpTool) Execute(ctx context.Context, arguments string) (ToolResult, er
|
||||
}
|
||||
|
||||
func extractMCPContent(result *mcp.CallToolResult) string {
|
||||
if result == nil || len(result.Content) == 0 {
|
||||
if result == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -178,5 +178,16 @@ func extractMCPContent(result *mcp.CallToolResult) string {
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(parts, "\n")
|
||||
if len(parts) > 0 {
|
||||
return strings.Join(parts, "\n")
|
||||
}
|
||||
|
||||
if result.StructuredContent != nil {
|
||||
data, err := json.Marshal(result.StructuredContent)
|
||||
if err == nil {
|
||||
return string(data)
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user