Skip to content

docs(mcp): document all 7 generate_chart chart_type values, fix stale config comment#41599

Open
aminghadersohi wants to merge 4 commits into
apache:masterfrom
aminghadersohi:amin/sc-106049/mcp-generate-chart-docstring
Open

docs(mcp): document all 7 generate_chart chart_type values, fix stale config comment#41599
aminghadersohi wants to merge 4 commits into
apache:masterfrom
aminghadersohi:amin/sc-106049/mcp-generate-chart-docstring

Conversation

@aminghadersohi

@aminghadersohi aminghadersohi commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

The generate_chart MCP tool's docstring only documented chart_type='xy' and chart_type='table', even though the underlying schema (ChartConfig discriminated union) has supported 5 additional chart types since #38375, #38402, and #38403: pie, pivot_table, mixed_timeseries, handlebars, and big_number.

Because the docstring is the primary signal an LLM client sees before calling the tool, models reaching for natural chart-type names like 'line', 'bar', or 'pie' directly as the chart_type value (instead of as a kind sub-field of chart_type='xy', or simply being unaware 'pie' was a valid discriminator at all) would hit the raw Pydantic discriminator validation error and loop through retries until timing out.

This PR only touches docstrings/comments — no schema, validation, or behavior changes:

  • generate_chart docstring now lists all 7 valid chart_type values with their required fields
  • Clarifies that kind (line/bar/area/scatter) is a sub-field of chart_type='xy', not a chart_type itself
  • Adds a natural-language → chart_type lookup table
  • Adds a pie chart example (previously only xy and table had examples)
  • Fixes a stale comment in MCP_TOOL_SEARCH_CONFIG that described include_schemas=False as the default; it has defaulted to True since fix(mcp): restore typed ChartConfig in tool schemas for LLM visibility #39732 (to keep discriminated-union chart configs visible to LLMs without a second round trip)

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — docstring/comment-only change, not user-facing UI.

TESTING INSTRUCTIONS

  1. ruff format --check / ruff check pass on both changed files
  2. Pre-commit hooks (mypy, ruff, pylint, docstring-first check) pass
  3. No tests assert on the literal docstring/comment text; existing tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py suite is unaffected since only documentation (not schema or logic) changed

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@aminghadersohi aminghadersohi changed the title docs(mcp): document all 7 generate_chart chart_type values docs(mcp): document all 7 generate_chart chart_type values, fix stale config comment Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.77%. Comparing base (bc80d13) to head (69de943).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41599      +/-   ##
==========================================
- Coverage   64.79%   64.77%   -0.02%     
==========================================
  Files        2740     2739       -1     
  Lines      153135   152912     -223     
  Branches    35127    35029      -98     
==========================================
- Hits        99221    99048     -173     
+ Misses      52017    51964      -53     
- Partials     1897     1900       +3     
Flag Coverage Δ
hive 39.07% <ø> (ø)
mysql 58.00% <ø> (ø)
postgres 58.05% <ø> (-0.01%) ⬇️
presto 41.04% <ø> (ø)
python 59.44% <ø> (-0.01%) ⬇️
sqlite 57.66% <ø> (ø)
unit 100.00% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

The generate_chart tool's docstring only described chart_type='xy'
and 'table', even though the schema has supported 'pie',
'pivot_table', 'mixed_timeseries', 'handlebars', and 'big_number'
since apache#38375/apache#38402/apache#38403. LLM clients calling chart_type='line' or
'bar' (a 'kind' value, not a chart_type) hit the raw Pydantic
discriminator error and looped through retries until timeout.

Lists all 7 valid chart_type values with their required fields, adds
a natural-language lookup table, and adds a pie chart example.
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.
@aminghadersohi aminghadersohi force-pushed the amin/sc-106049/mcp-generate-chart-docstring branch from 4ce61b7 to 27df454 Compare July 10, 2026 03:13
@aminghadersohi aminghadersohi requested a review from Copilot July 10, 2026 20:29
@aminghadersohi aminghadersohi marked this pull request as ready for review July 10, 2026 20:29
@dosubot dosubot Bot added the doc:developer Developer documentation label Jul 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates MCP documentation to reduce chart-creation retries by making generate_chart’s supported chart_type discriminator values explicit and by correcting a stale comment about tool search schema inclusion defaults.

Changes:

  • Expand generate_chart docstring to document all supported chart_type discriminator values and required fields, plus add a natural-language lookup and a pie example.
  • Update MCP_TOOL_SEARCH_CONFIG comment to reflect that include_schemas defaults to True (so discriminated-union schemas remain visible in search_tools).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
superset/mcp_service/mcp_config.py Refreshes include_schemas/summary-mode documentation to match current defaults.
superset/mcp_service/chart/tool/generate_chart.py Improves generate_chart docstring to list all valid chart_type values and provide clearer guidance/examples.

Comment on lines 111 to +115
IMPORTANT: The 'chart_type' field in the config is a DISCRIMINATOR that determines
which chart configuration schema to use. It MUST be included and MUST match the
other fields in your configuration:
other fields in your configuration. There are exactly 7 valid chart_type values
— NOT 'line', 'bar', 'mixed_timeseries', etc. Those are 'kind' values WITHIN
chart_type='xy' (see below), not chart_type values themselves:
@bito-code-review

Copy link
Copy Markdown
Contributor

The docstring in superset/mcp_service/chart/tool/generate_chart.py indeed contains a contradiction regarding mixed_timeseries. While the docstring lists mixed_timeseries as a valid chart_type in the bulleted list, the introductory text claims there are "exactly 7 valid chart_type values" and explicitly states that mixed_timeseries is NOT a valid chart_type value, which is confusing.

To resolve this, the docstring should be updated to clarify that mixed_timeseries IS a valid chart_type value, consistent with its inclusion in the list and the ChartConfig discriminated union. The introductory text should be corrected to reflect the actual list of valid types.

superset/mcp_service/chart/tool/generate_chart.py

IMPORTANT: The 'chart_type' field in the config is a DISCRIMINATOR that determines
    which chart configuration schema to use. It MUST be included and MUST match the
    other fields in your configuration. There are valid chart_type values:

    - chart_type='xy' for charts with x and y axes (line, bar, area, scatter).
      Required fields: y (x is optional — defaults to dataset's primary
      datetime column). Use 'kind' to pick line/bar/area/scatter
      (default kind='line').

    - chart_type='table' for tabular visualizations.
      Required fields: columns

    - chart_type='pie' for pie/donut charts.
      Required fields: dimension, metric

    - chart_type='pivot_table' for pivot table visualizations.
      Required fields: rows, metrics (columns is optional, for cross-tabs)

    - chart_type='mixed_timeseries' for dual-axis time-series charts.
      Required fields: x, y (primary metrics), y_secondary (secondary metrics)

    - chart_type='handlebars' for custom template-based visualizations.
      Required fields: handlebars_template

    - chart_type='big_number' for single KPI metric displays.
      Required fields: metric

@bito-code-review

bito-code-review Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #6e6727

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/mcp_service/mcp_config.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: 2e4fc86..69de943
    • superset/mcp_service/chart/tool/generate_chart.py
    • superset/mcp_service/mcp_config.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants