Skip to content

feat(mcp): add get_chart_type_schema tool for on-demand schema discovery#39142

Merged
aminghadersohi merged 3 commits intoapache:masterfrom
aminghadersohi:amin/get-chart-type-schema
Apr 7, 2026
Merged

feat(mcp): add get_chart_type_schema tool for on-demand schema discovery#39142
aminghadersohi merged 3 commits intoapache:masterfrom
aminghadersohi:amin/get-chart-type-schema

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds a new get_chart_type_schema MCP 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 in search_tools responses from ~26k to ~200 chars per tool.

The pattern: lightweight discovery via search_tools, full schema on demand via get_chart_type_schema.

Before: Agents had to read the chart://configs resource (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

  1. Connect to MCP service
  2. Call get_chart_type_schema with each of the 7 chart types: xy, table, pie, pivot_table, mixed_timeseries, handlebars, big_number
  3. Verify each returns a valid JSON Schema with properties and examples
  4. Call with include_examples=false — verify no examples in response
  5. Call with invalid chart_type — verify error lists valid types

ADDITIONAL INFORMATION

  • Supports all 7 chart types from the ChartConfig discriminated union
  • include_examples parameter (default true) controls whether examples are included
  • Invalid chart types return a structured error with valid_chart_types list
  • Module-level TypeAdapter instances avoid repeated schema compilation
  • 16 unit tests covering all types, field checks, error handling, and examples

Copilot AI review requested due to automatic review settings April 6, 2026 23:25
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review bot commented Apr 6, 2026

Code Review Agent Run #80ceb7

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 71730b3..71730b3
    • superset/mcp_service/app.py
    • superset/mcp_service/chart/tool/__init__.py
    • superset/mcp_service/chart/tool/get_chart_type_schema.py
    • tests/unit_tests/mcp_service/chart/tool/test_get_chart_type_schema.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 viz:charts Namespace | Anything related to viz types label Apr 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_schema MCP tool with module-level TypeAdapter caching 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.

Comment thread superset/mcp_service/chart/tool/get_chart_type_schema.py Outdated
Comment thread tests/unit_tests/mcp_service/chart/tool/test_get_chart_type_schema.py Outdated
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 60.86957% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.45%. Comparing base (bf9aff1) to head (92f62c5).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...et/mcp_service/chart/tool/get_chart_type_schema.py 59.09% 9 Missing ⚠️
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              
Flag Coverage Δ
hive 40.08% <60.86%> (+<0.01%) ⬆️
mysql 60.75% <60.86%> (+<0.01%) ⬆️
postgres 60.83% <60.86%> (+<0.01%) ⬆️
presto 40.09% <60.86%> (+<0.01%) ⬆️
python 62.41% <60.86%> (-0.01%) ⬇️
sqlite 60.46% <60.86%> (+<0.01%) ⬆️
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.

Comment thread superset/mcp_service/chart/tool/get_chart_type_schema.py
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
@aminghadersohi aminghadersohi force-pushed the amin/get-chart-type-schema branch from 71730b3 to 3b9aa56 Compare April 6, 2026 23:56
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.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review bot commented Apr 7, 2026

Code Review Agent Run #0f1380

Actionable Suggestions - 0
Additional Suggestions - 1
  • tests/unit_tests/mcp_service/chart/tool/test_get_chart_type_schema.py - 1
    • Incomplete Test Coverage · Line 73-76
      The test `test_examples_match_chart_type` only validates examples for the 'pie' chart type, but to catch potential bugs where examples for other chart types have incorrect `chart_type` values, it should be parametrized to check all valid chart types.
      Code suggestion
       @@ -1,4 +1,6 @@
      -    def test_examples_match_chart_type(self) -> None:
      -        result = _call_schema("pie")
      -        for example in result["examples"]:
      -            assert example["chart_type"] == "pie"
      +    @pytest.mark.parametrize("chart_type", VALID_CHART_TYPES)
      +    def test_examples_match_chart_type(self, chart_type) -> None:
      +        result = _call_schema(chart_type)
      +        for example in result["examples"]:
      +            assert example["chart_type"] == chart_type
Review Details
  • Files reviewed - 4 · Commit Range: 3f15ee3..92f62c5
    • superset/mcp_service/app.py
    • superset/mcp_service/chart/tool/__init__.py
    • superset/mcp_service/chart/tool/get_chart_type_schema.py
    • tests/unit_tests/mcp_service/chart/tool/test_get_chart_type_schema.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

@aminghadersohi aminghadersohi merged commit 5f9fc31 into apache:master Apr 7, 2026
65 checks passed
michael-s-molina pushed a commit that referenced this pull request Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L viz:charts Namespace | Anything related to viz types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants