mirror of
https://github.com/apache/superset.git
synced 2026-05-22 00:05:15 +00:00
FastMCP converts tool return values into ToolResult objects before middleware sees them. The actual data (e.g. DashboardInfo) is serialized as a JSON string inside content[0].text. The ResponseSizeGuardMiddleware was operating on the ToolResult wrapper instead of the actual payload, causing two problems: 1. Token estimation was double-serializing (the JSON string inside text gets escaped again), producing inflated estimates 2. Truncation phases (truncate charts list, truncate strings, etc.) could not find the right keys because they were looking at the ToolResult structure, not the dashboard/chart/dataset data This caused get_dashboard_info to produce broken truncated responses for dashboards with many charts — the middleware would char-truncate content[0].text mid-JSON instead of intelligently reducing the payload. The fix extracts the payload from content[0].text, parses it back to a dict, runs the 5-phase truncation on the actual data, then re-wraps the result into a ToolResult.