fix(mcp): expose query context to Jinja macros - #42822
Draft
aminghadersohi wants to merge 3 commits into
Draft
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #42822 +/- ##
==========================================
- Coverage 65.73% 65.73% -0.01%
==========================================
Files 2843 2844 +1
Lines 162653 162665 +12
Branches 37239 37239
==========================================
+ Hits 106919 106923 +4
- Misses 53642 53649 +7
- Partials 2092 2093 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
aminghadersohi
force-pushed
the
aminghadersohi/mcp-jinja-form-data
branch
from
August 6, 2026 06:38
993cf12 to
f96ad00
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
The chart data API makes its query request available through Flask's global form-data fallback because Jinja macros such as
filter_values,get_filters, andurl_paramread query inputs from that context. Programmatically constructed MCP queries skipped that step, so virtual datasets and metrics using those macros could fail despite the equivalent API query succeeding.This extracts the API's form-data assignment into a shared helper and uses it for
get_chart_dataandquery_dataset. MCP query contexts are represented in the same datasource/queries/form-data shape consumed by the existing Jinja lookup path; no synthetic request context or duplicated macro-specific behavior is introduced.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable; this is a backend-only query execution fix.
TESTING INSTRUCTIONS
pytest -q tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py(136 passed)pytest -q tests/unit_tests/mcp_service(3318 passed; one unrelated existing health-check smoke failure because the test environment has no version string configured)uvx pre-commit run --files superset/charts/data/api.py superset/charts/data/form_data.py superset/mcp_service/chart/tool/get_chart_data.py superset/mcp_service/dataset/tool/query_dataset.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.pypre-commit run --all-files(Python checks passed; frontend-only hooks could not complete because frontend dependencies such asglobandpostcss-styled-syntaxare not installed; the formatter also reported pre-existing frontend formatting drift)The regression tests execute
filter_valuesandget_filtersduring an MCPquery_datasetcall and coverurl_paramplus implicit dataset lookup formetric()using chart-shaped query context.ADDITIONAL INFORMATION
Blast radius
This affects only MCP chart and dataset query execution plus the existing chart-data API context assignment. It does not change authorization, RLS, workspace isolation, schemas, migrations, feature flags, or non-MCP query behavior.
Risk & rollback
Risk is limited to the Flask-global form-data payload used while compiling MCP queries. The payload is built from the already validated query context and matches the existing API representation. Rollback is a revert of this commit.
Review guidance
Start with
superset/charts/data/form_data.py, then verify the two MCP call sites populate it immediately beforeChartDataCommandexecution. The tests document the request-dependent macro boundary.Eval evidence
No model or prompt evaluation was run because this change does not modify tool schemas, descriptions, prompts, model routing, or generated responses. The deterministic MCP regression coverage passes 136/136; the full MCP unit suite passes 3318/3319 with the environment-only health-check failure described above.
Cost & latency delta
No model parameters, prompts, or tool payload schemas changed, so token and model-cost delta is zero. The added work serializes the already-built query objects once per affected call; no external request or database query is added.
Prompt / non-determinism
No prompt, model routing, or non-deterministic behavior changed.