Skip to content

fix(mcp): default chart previews to ascii - #39719

Merged
richardfogaca merged 3 commits into
apache:masterfrom
richardfogaca:richardfogaca/chart-preview-supported-default
Apr 28, 2026
Merged

richardfogaca merged 3 commits into
apache:masterfrom
richardfogaca:richardfogaca/chart-preview-supported-default

Conversation

@richardfogaca

@richardfogaca richardfogaca commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

get_chart_preview was defaulting to format=url, but URL-based screenshot previews are not supported by the tool. As a result, a normal/default call could fail with UnsupportedFormat before returning any useful preview.

This PR changes the default preview format to ascii, which is already supported, so callers get a text-based visual preview by default instead of an error.

When a user asks the chatbot to show a visual preview of a chart, the LLM may call get_chart_preview without explicitly setting a format. Before this change, that default path used url and failed with:

URL-based screenshot previews are not supported.
Use the explore_url to view the chart interactively, or try formats: 'ascii', 'table', or 'vega_lite'.

The chatbot could recover, but the first tool call still produced an error and the user did not get the preview they asked for.

get_chart_preview supports multiple preview formats through format-specific strategies:

  • url returns an Explore link.
  • ascii queries the chart data and renders a lightweight text preview.
  • table queries the chart data and renders a text table.
  • vega_lite builds a Vega-Lite specification.

The default format matters because callers often omit optional parameters. With the previous default, a normal call selected the URL path, which does not provide screenshot rendering and could fail with UnsupportedFormat.

With this change, the default path selects the existing ASCII strategy instead. That strategy uses the saved chart configuration, runs the chart data query, and returns preview content directly in the tool response. The response still includes the Explore URL for opening the full chart interactively.

Changes included:

  • Changed GetChartPreviewRequest.format default from url to ascii.
  • Updated the schema description so the default behavior is clear to LLM/tool callers.
  • Updated the MCP app instructions so get_chart_preview is not described as image-URL-only.
  • Removed get_chart_preview from the response-size guard exclusion list.
    • This matters because ascii and table previews can contain chart data, so they should be protected by the normal response-size limits.
  • Updated tests for the new default.
  • Added coverage to ensure chart preview responses are size-checked by default.

This does not implement URL screenshot generation. The url format still returns an explore link where supported, but it is no longer the default path.

This also does not guarantee every chart type can produce an ASCII preview. Unsupported chart configurations can still return chart-specific errors. The fix is specifically for the unsupported default url format.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable. This is an MCP tool behavior change with text-based output.

TESTING INSTRUCTIONS

Run focused MCP tests:

PYENV_VERSION=superset pytest \
  tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py \
  tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py::TestGenerateChart::test_preview_formats \
  tests/unit_tests/mcp_service/chart/tool/test_update_chart.py::TestUpdateChart::test_update_chart_preview_formats \
  tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py \
  tests/unit_tests/mcp_service/test_middleware.py::TestCreateResponseSizeGuardMiddleware::test_default_config_checks_chart_preview \
  -q

Expected result:

36 passed

Manual verification performed through the local chatbot flow:

  • Prompt: Show me a visual preview of chart 11
  • Tool called: get_chart_preview
  • MCP log showed: format=ascii
  • Result: chatbot returned a formatted chart preview without UnsupportedFormat

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

@codecov

codecov Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.47%. Comparing base (3aa99c5) to head (9cef8ba).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #39719   +/-   ##
=======================================
  Coverage   64.47%   64.47%           
=======================================
  Files        2566     2566           
  Lines      134027   134027           
  Branches    31121    31121           
=======================================
  Hits        86410    86410           
  Misses      46122    46122           
  Partials     1495     1495           
Flag Coverage Δ
hive 39.72% <100.00%> (ø)
mysql 60.15% <100.00%> (ø)
postgres 60.23% <100.00%> (ø)
presto 41.49% <100.00%> (ø)
python 61.79% <100.00%> (ø)
sqlite 59.86% <100.00%> (ø)
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.

@richardfogaca richardfogaca self-assigned this Apr 28, 2026
@richardfogaca
richardfogaca marked this pull request as ready for review April 28, 2026 12:30
Copilot AI review requested due to automatic review settings April 28, 2026 12:30

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 the MCP chart preview tool defaults so a standard get_chart_preview call returns an in-response text preview (instead of defaulting to a URL path that can fail), and ensures chart preview responses are subject to the response-size guard.

Changes:

  • Defaulted GetChartPreviewRequest.format from url to ascii and updated schema/instructions text accordingly.
  • Removed get_chart_preview from the response-size guard exclusion list.
  • Updated/added unit tests to reflect the new default and configuration behavior.

Reviewed changes

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

Show a summary per file
File Description
superset/mcp_service/chart/schemas.py Changes preview request default format and updates schema description text.
superset/mcp_service/app.py Updates MCP “default instructions” text to reflect non-URL preview output.
superset/mcp_service/mcp_config.py Removes get_chart_preview from response-size guard excluded tools.
tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py Updates unit test expectation for the new default format.
tests/unit_tests/mcp_service/test_middleware.py Adds a test asserting chart preview is not excluded from size-guard config.
Comments suppressed due to low confidence (1)

superset/mcp_service/chart/schemas.py:1760

  • The width field description still references "url/base64 formats", but GetChartPreviewRequest.format no longer includes any base64 option. Please update the width/height descriptions (or the supported format list) so the schema docs don’t advertise a non-existent format.
        ),
    )
    width: int | None = Field(
        default=800,
        description="Preview image width in pixels (for url/base64 formats)",

Comment thread tests/unit_tests/mcp_service/test_middleware.py Outdated
@bito-code-review

Copy link
Copy Markdown
Contributor

The suggestion improves the test by verifying runtime behavior of the middleware factory with default config, ensuring get_chart_preview is size-checked and health_check remains excluded.

tests/unit_tests/mcp_service/test_middleware.py

def test_default_config_checks_chart_preview(self) -> None:
        """Should size-check chart preview responses by default."""
        mock_config = {"MCP_RESPONSE_SIZE_CONFIG": MCP_RESPONSE_SIZE_CONFIG}
        middleware = create_response_size_guard_middleware(mock_config)
        assert "get_chart_preview" not in middleware.excluded_tools
        assert "health_check" in middleware.excluded_tools

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Apr 28, 2026

@aminghadersohi aminghadersohi 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.

The fix is correct and the test hardening is solid — good call on the follow-up commit to address the Copilot/Bito feedback.

A few pre-existing stale descriptions in URLPreview that were partially touched in this PR worth cleaning up as a follow-up:

  • URLPreview.width/height (schemas.py:1780-1781) still say "Image width/height in pixels" — but the url format now returns an Explore link, not an image.
  • URLPreview.supports_interaction=False, description="Static image, no interaction" (schemas.py:1782-1784) contradicts the fact that the Explore URL is fully interactive.
  • The tool docstring in get_chart_preview.py:978-989 still describes the tool as URL/image-only ("URLs for LLM embedding", "screenshot endpoints", etc.) — this could mislead LLMs into expecting image output.

None of these are blockers — they're pre-existing and outside this PR's direct scope. Happy to see them cleaned up in a follow-up.

…rt-preview-supported-default

# Conflicts:
#	tests/unit_tests/mcp_service/test_middleware.py
@bito-code-review

bito-code-review Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #a7801e

Actionable Suggestions - 0
Review Details
  • Files reviewed - 5 · Commit Range: ff11a2d..9cef8ba
    • superset/mcp_service/app.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/mcp_config.py
    • tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
    • tests/unit_tests/mcp_service/test_middleware.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

@richardfogaca
richardfogaca merged commit d0abb66 into apache:master Apr 28, 2026
69 of 73 checks passed
@richardfogaca
richardfogaca deleted the richardfogaca/chart-preview-supported-default branch April 28, 2026 16:30
@richardfogaca

Copy link
Copy Markdown
Contributor Author

@aminghadersohi Richard's agent here. Thanks for calling out the stale chart preview descriptions.

I opened a follow-up draft PR to address those notes: #39731

It updates the URLPreview metadata and chart preview guidance so the MCP schema/docstrings describe Explore URLs as interactive links, not static screenshot/image outputs.

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
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