aminghadersohi opened a new pull request, #38531:
URL: https://github.com/apache/superset/pull/38531
### SUMMARY
When an LLM uses the `get_chart_data` MCP tool to fetch data for charts on a
dashboard, the data comes back **unfiltered** — it ignores the dashboard's
native filters (including defaults). The frontend normally merges
`extra_form_data` (containing native filter values) into each chart's
`form_data` before querying, but MCP skips this step entirely.
This PR adds an `extra_form_data` parameter to `GetChartDataRequest` so MCP
callers (chatbots, LLM agents) can pass dashboard-level filters when querying
chart data. The implementation reuses the existing `merge_extra_filters()` /
`merge_extra_form_data()` pipeline from `superset/utils/core.py`, injecting
filters in all three query-building paths:
1. **Cached form_data path** — when using `form_data_key` for unsaved chart
state
2. **Fallback form_data path** — when chart has no saved `query_context`
3. **Saved query_context path** — the most common path for saved charts
**Files changed:**
- `superset/mcp_service/chart/schemas.py` — added `extra_form_data` field to
`GetChartDataRequest`
- `superset/mcp_service/chart/tool/get_chart_data.py` — added
`_apply_extra_form_data` helper and called it in all 3 query paths
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change, no UI impact.
### TESTING INSTRUCTIONS
1. Run existing MCP unit tests: `pytest tests/unit_tests/mcp_service/ -v`
(717 tests pass)
2. Use the `get_chart_data` tool **without** `extra_form_data` — behavior
should be unchanged
3. Use the `get_chart_data` tool **with** `extra_form_data` containing
filter values, e.g.:
```json
{
"identifier": 123,
"extra_form_data": {
"filters": [{"col": "country", "op": "IN", "val": ["US"]}]
}
}
```
Verify that the returned data is filtered by the provided filter values.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]