Files
superset2/superset
Amin Ghadersohi 5348b92e3a fix(mcp): unwrap ToolResult payload before truncation in ResponseSizeGuardMiddleware
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.
2026-04-23 00:54:24 +00:00
..