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:
Bryan Frimin
2026-03-13 19:43:19 +01:00
parent cb6189d7ac
commit 5c889a1d47
2 changed files with 57 additions and 2 deletions

View File

@@ -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 ""
}