Skip to content

fix(mcp): restore typed ChartConfig in tool schemas for LLM visibility#39732

Merged
aminghadersohi merged 6 commits into
apache:masterfrom
aminghadersohi:aminghadersohi/revert-dict-config-to-chartconfig
Apr 28, 2026
Merged

fix(mcp): restore typed ChartConfig in tool schemas for LLM visibility#39732
aminghadersohi merged 6 commits into
apache:masterfrom
aminghadersohi:aminghadersohi/revert-dict-config-to-chartconfig

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

Summary

PR #39018 changed the config field from ChartConfig (typed discriminated union) to Dict[str, Any] in chart request schemas to reduce token usage. This removed all chart config structure from the JSON Schema exposed to LLMs, causing validation errors:

  • Wrong field names (e.g., column instead of name for x-axis)
  • Missing required fields (e.g., x.name)
  • Wrong types (e.g., dict instead of list for y)

Also flips include_schemas default to True so search_tools results include full compacted inputSchema instead of the parameters_hint summary which only shows "request" (the top-level wrapper name).

Changes

  • Revert config field type from Dict[str, Any] back to ChartConfig in GenerateChartRequest, GenerateExploreLinkRequest, UpdateChartRequest, UpdateChartPreviewRequest
  • Remove now-redundant parse_chart_config() calls in tool bodies (Pydantic validates the discriminated union at request parse time)
  • Remove dead code: _coerce_config_to_dict, _CHART_CONFIG_DESCRIPTION, _CHART_CONFIG_ADAPTER, parse_chart_config
  • Set include_schemas=True in MCP_TOOL_SEARCH_CONFIG default

Token cost

~12k tokens added back for chart tools. Justified: failed retries from broken schemas cost far more tokens than the larger schema.

Test plan

  • Existing MCP chart unit tests pass
  • JSON Schema for GenerateChartRequest includes full discriminated union
  • LLM can generate charts without multiple retries via MCP

PR apache#39018 changed the config field from ChartConfig (discriminated union)
to Dict[str, Any] in GenerateChartRequest, GenerateExploreLinkRequest,
UpdateChartRequest, and UpdateChartPreviewRequest. This removed all chart
config structure from the JSON Schema exposed to LLMs, causing them to
fail with validation errors (wrong field names, missing required fields,
invalid types).

Also flips include_schemas default to True so search_tools results
include full compacted inputSchema instead of the parameters_hint
summary (which only shows "request" — the top-level wrapper name).

Changes:
- Revert config field type from Dict[str, Any] back to ChartConfig
- Remove now-redundant parse_chart_config() calls in tool bodies
  (Pydantic validates the discriminated union at request parse time)
- Remove dead code: _coerce_config_to_dict, _CHART_CONFIG_DESCRIPTION,
  _CHART_CONFIG_ADAPTER, parse_chart_config
- Set include_schemas=True in MCP_TOOL_SEARCH_CONFIG default
@bito-code-review

bito-code-review Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #0d3f3e

Actionable Suggestions - 0
Review Details
  • Files reviewed - 7 · Commit Range: 2213cae..2213cae
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/chart/tool/generate_chart.py
    • superset/mcp_service/chart/tool/update_chart.py
    • superset/mcp_service/chart/tool/update_chart_preview.py
    • superset/mcp_service/chart/validation/pipeline.py
    • superset/mcp_service/explore/tool/generate_explore_link.py
    • superset/mcp_service/mcp_config.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added the change:backend Requires changing the backend label Apr 28, 2026
Remove parse_chart_config imports and update tests to validate
ChartConfig through Pydantic request models instead of the
removed parse_chart_config() function.
@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.49%. Comparing base (d0abb66) to head (4d1faff).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/chart/tool/generate_chart.py 0.00% 2 Missing ⚠️
superset/mcp_service/chart/validation/pipeline.py 0.00% 2 Missing ⚠️
superset/mcp_service/chart/tool/update_chart.py 0.00% 1 Missing ⚠️
...set/mcp_service/chart/tool/update_chart_preview.py 0.00% 1 Missing ⚠️
.../mcp_service/explore/tool/generate_explore_link.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #39732      +/-   ##
==========================================
+ Coverage   64.47%   64.49%   +0.02%     
==========================================
  Files        2566     2566              
  Lines      134027   133960      -67     
  Branches    31121    31116       -5     
==========================================
- Hits        86410    86394      -16     
+ Misses      46122    46071      -51     
  Partials     1495     1495              
Flag Coverage Δ
hive 39.74% <36.36%> (+0.01%) ⬆️
mysql 60.19% <36.36%> (+0.04%) ⬆️
postgres 60.27% <36.36%> (+0.04%) ⬆️
presto 41.51% <36.36%> (+0.01%) ⬆️
python 61.83% <36.36%> (+0.04%) ⬆️
sqlite 59.90% <36.36%> (+0.04%) ⬆️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Convert dict-style config access (config["key"]) back to attribute
access (config.key) in test files to match the restored ChartConfig
typed field. Update include_schemas default assertion to True.
…error code expectations

- Replace request.config.get("chart_type", "unknown") with
  request.config.chart_type in generate_chart and generate_explore_link
- Update test_pipeline_error_surface to expect VALIDATION_ERROR
  (the error code produced by SchemaValidator when Pydantic catches
  invalid config fields at parse time)
The error message from SchemaValidator is now generic; the field name
appears in details instead of message.
@netlify

netlify Bot commented Apr 28, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 3c94851
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69f11ac45e48300008526e82
😎 Deploy Preview https://deploy-preview-39732--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

generate_chart debug log called config.keys() expecting a dict,
but config is now a typed Pydantic model.
@aminghadersohi aminghadersohi merged commit 4b42f82 into apache:master Apr 28, 2026
65 checks passed
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

bestlong pushed a commit to bestlong/superset that referenced this pull request May 7, 2026
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
aminghadersohi added a commit to aminghadersohi/superset that referenced this pull request Jul 1, 2026
MCP_TOOL_SEARCH_CONFIG has defaulted include_schemas to True since
apache#39732 (to keep discriminated-union chart configs visible to LLMs
without a second round trip), but the comment above it still
described include_schemas=False as the default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants