feat(mcp): add get_chart_type_schema tool for on-demand schema discovery#39142
Conversation
Code Review Agent Run #80ceb7Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
There was a problem hiding this comment.
Pull request overview
Adds an MCP chart discovery tool that returns full per-chart-type JSON Schema (and optional examples) on demand, complementing prior work that compressed chart config schemas in search_tools responses.
Changes:
- Introduces
get_chart_type_schemaMCP tool with module-levelTypeAdaptercaching and per-type examples. - Registers the new tool in the chart tool package exports and the MCP app tool import list.
- Adds unit tests validating schema presence, key fields, examples inclusion/omission, and invalid chart_type behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
superset/mcp_service/chart/tool/get_chart_type_schema.py |
Adds the new tool implementation, adapters, valid type list, and examples payloads. |
superset/mcp_service/chart/tool/__init__.py |
Exports the new tool for chart tool module consumers. |
superset/mcp_service/app.py |
Imports the new tool so it registers with the global MCP instance. |
tests/unit_tests/mcp_service/chart/tool/test_get_chart_type_schema.py |
Adds unit tests for the tool’s schema/example behavior and error case. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39142 +/- ##
==========================================
- Coverage 64.45% 64.45% -0.01%
==========================================
Files 2540 2541 +1
Lines 131639 131662 +23
Branches 30515 30517 +2
==========================================
+ Hits 84849 84863 +14
- Misses 45324 45333 +9
Partials 1466 1466
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add a new MCP tool that returns the full JSON Schema and examples for a specific chart type. This enables lazy-loading: search_tools stays lightweight (~200 chars per tool) while agents can fetch the full schema on demand when they need to construct a chart config. Supports all 7 chart types: xy, table, pie, pivot_table, mixed_timeseries, handlebars, big_number. Each type includes working examples. Invalid chart types return a helpful error listing valid options.
- Change tag from "read" to "discovery" to match other schema tools - Factor tool logic into _get_chart_type_schema_impl pure helper - Tests call the impl directly instead of reimplementing logic
71730b3 to
3b9aa56
Compare
Handlebars default query_mode is "aggregate" which requires metrics. The example only has columns, so set query_mode to "raw" to make the example actually executable.
Code Review Agent Run #0f1380Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
SUMMARY
Adds a new
get_chart_type_schemaMCP tool that returns the full JSON Schema and working examples for a specific chart type. This is the companion to PR #39018 which compressed chart config schemas insearch_toolsresponses from ~26k to ~200 chars per tool.The pattern: lightweight discovery via
search_tools, full schema on demand viaget_chart_type_schema.Before: Agents had to read the
chart://configsresource (static blob with all types) or guess the schema from tool descriptions.After: Agents call
get_chart_type_schema("pie")and get the exact Pydantic JSON Schema + examples for that specific type.BEFORE/AFTER SCREENSHOTS OR GIFS
N/A — backend-only tool, no UI changes.
TESTING INSTRUCTIONS
get_chart_type_schemawith each of the 7 chart types:xy,table,pie,pivot_table,mixed_timeseries,handlebars,big_numberpropertiesandexamplesinclude_examples=false— verify no examples in responsechart_type— verify error lists valid typesADDITIONAL INFORMATION
ChartConfigdiscriminated unioninclude_examplesparameter (default true) controls whether examples are includedvalid_chart_typeslistTypeAdapterinstances avoid repeated schema compilation