This is an automated email from the ASF dual-hosted git repository.
alexandrusoare pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new b64561f3a37 chore(mcp): Simplify chart preview response (#40020)
b64561f3a37 is described below
commit b64561f3a3773fa54db91072ff3b52dedd34ea96
Author: Alexandru Soare <[email protected]>
AuthorDate: Mon May 25 13:16:27 2026 +0300
chore(mcp): Simplify chart preview response (#40020)
---
superset/mcp_service/chart/schemas.py | 17 -----------------
superset/mcp_service/chart/tool/get_chart_preview.py | 20 ++------------------
.../mcp_service/chart/tool/test_get_chart_preview.py | 17 +----------------
3 files changed, 3 insertions(+), 51 deletions(-)
diff --git a/superset/mcp_service/chart/schemas.py
b/superset/mcp_service/chart/schemas.py
index e22c2f2ae3b..a711ce535bb 100644
--- a/superset/mcp_service/chart/schemas.py
+++ b/superset/mcp_service/chart/schemas.py
@@ -2109,23 +2109,6 @@ class ChartPreview(BaseModel):
)
performance: PerformanceMetadata = Field(description="Performance metrics")
- # Backward compatibility fields (populated based on content type)
- format: str | None = Field(
- None, description="Format of the preview (ascii, table, vega_lite)"
- )
- ascii_chart: str | None = Field(
- None, description="ASCII art chart for 'ascii' format"
- )
- table_data: str | None = Field(
- None, description="Formatted table for 'table' format"
- )
- width: int | None = Field(
- None, description="Width (pixels for images, characters for ASCII)"
- )
- height: int | None = Field(
- None, description="Height (pixels for images, lines for ASCII)"
- )
-
# Inherit versioning
schema_version: str = Field("2.0", description="Response schema version")
api_version: str = Field("v1", description="MCP API version")
diff --git a/superset/mcp_service/chart/tool/get_chart_preview.py
b/superset/mcp_service/chart/tool/get_chart_preview.py
index f8da956b66c..32fd1c9bd43 100644
--- a/superset/mcp_service/chart/tool/get_chart_preview.py
+++ b/superset/mcp_service/chart/tool/get_chart_preview.py
@@ -117,7 +117,7 @@ def _sanitize_chart_preview_for_llm_context(
"""Wrap chart preview read-path descriptive fields before LLM exposure."""
payload = chart_preview.model_dump(mode="python")
- for field_name in ("chart_name", "chart_description", "ascii_chart",
"table_data"):
+ for field_name in ("chart_name", "chart_description"):
payload[field_name] = sanitize_for_llm_context(
payload.get(field_name),
field_path=(field_name,),
@@ -1377,22 +1377,6 @@ async def _get_chart_preview_internal( # noqa: C901
performance=performance,
)
- # Add format-specific fields for backward compatibility
- if isinstance(content, ASCIIPreview):
- result.format = "ascii"
- result.ascii_chart = content.ascii_content
- result.width = content.width
- result.height = content.height
- elif isinstance(content, TablePreview):
- result.format = "table"
- result.table_data = content.table_data
- elif isinstance(content, VegaLitePreview):
- result.format = "vega_lite"
- elif isinstance(content, URLPreview):
- result.format = "url"
- result.width = content.width
- result.height = content.height
-
return _sanitize_chart_preview_for_llm_context(result)
except SQLAlchemyError as e:
@@ -1477,7 +1461,7 @@ async def get_chart_preview(
"has_preview_url=%s"
% (
getattr(result, "chart_id", None),
- result.format,
+ getattr(result.content, "type", None),
bool(getattr(result, "preview_url", None)),
)
)
diff --git a/tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
b/tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
index 1a296e8674c..385d05b1a36 100644
--- a/tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
+++ b/tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
@@ -274,13 +274,8 @@ class TestGetChartPreview:
"performance",
]
- # Additional fields that may be present for backward compatibility
+ # Versioning fields
_ = [
- "format",
- "ascii_chart",
- "table_data",
- "width",
- "height",
"schema_version",
"api_version",
]
@@ -756,10 +751,6 @@ class TestChartPreviewSanitization:
high_contrast_available=False,
),
performance=PerformanceMetadata(query_duration_ms=8,
cache_status="miss"),
- format="ascii",
- ascii_chart="North > South",
- width=20,
- height=5,
)
result = _sanitize_chart_preview_for_llm_context(preview)
@@ -770,7 +761,6 @@ class TestChartPreviewSanitization:
"Preview of line: Regional Trend"
)
assert result.content.ascii_content == sanitize_for_llm_context("North
> South")
- assert result.ascii_chart == sanitize_for_llm_context("North > South")
assert result.accessibility.alt_text == sanitize_for_llm_context(
"Preview of Regional Trend"
)
@@ -876,8 +866,6 @@ class TestChartPreviewSanitization:
high_contrast_available=False,
),
performance=PerformanceMetadata(query_duration_ms=9,
cache_status="miss"),
- format="table",
- table_data="Customer | Revenue\nAcme | 100",
)
result = _sanitize_chart_preview_for_llm_context(preview)
@@ -885,9 +873,6 @@ class TestChartPreviewSanitization:
assert result.content.table_data == sanitize_for_llm_context(
"Customer | Revenue\nAcme | 100"
)
- assert result.table_data == sanitize_for_llm_context(
- "Customer | Revenue\nAcme | 100"
- )
assert result.content.row_count == 1
assert result.content.supports_sorting is True