gkneighb opened a new pull request, #43569:
URL: https://github.com/apache/superset/pull/43569
### SUMMARY
Adds a `generate_chart` MCP plugin for the **treemap** chart type
(`viz_type: treemap_v2`), so the MCP `generate_chart` tool can produce
treemaps. Treemap is a shipped Superset viz type that had no MCP plugin; this
closes that gap.
The plugin mirrors the frontend Treemap `buildQuery` contract: one `metric`
sizing the tiles plus an ordered `groupby` hierarchy — the first column is the
outermost level and each subsequent column nests inside it. When
`sort_by_metric` is set (the frontend default), tiles are ordered by the metric
descending.
Follows the established plugin pattern (`pie`/`funnel`/`gauge`/`waterfall`)
— a config schema, a `map_*_config` mapper, a plugin class, and registration:
- **`TreemapChartConfig`** — `metric` required and a non-empty ordered
`groupby` list (the hierarchy); optional `sort_by_metric`, `row_limit`,
`filters`, `color_scheme`. Added to the `ChartConfig` discriminated union and
the `get_chart_type_schema` adapters. `groupby` entries may not be
`saved_metric`/`sql_expression` (dimensions, not metrics).
- **`map_treemap_config`** — maps the config to `form_data`, preserving
`groupby` order as the nesting hierarchy; saved metrics pass through as a bare
name string, ad-hoc metrics as SIMPLE/SQL adhoc objects.
- **`TreemapChartPlugin`** — registered in the plugin registry; `treemap_v2`
was already present in the recommendation category map.
The field set is intentionally minimal (core query contract). Cosmetic
controls (label type, upper labels, number/date format) are left for a
follow-up.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend/MCP only, no UI change.
### TESTING INSTRUCTIONS
`pytest tests/unit_tests/mcp_service/chart/test_treemap_chart.py` — 15 unit
tests cover schema validation (required non-empty `groupby`, hierarchy order
preserved, `groupby`-not-a-metric, extra-field rejection), `ChartConfig` union
dispatch, `form_data` mapping
(viz_type/groupby-order/metric/sort/filters/saved-metric), and registry
integration (registration, `resolve_viz_type`, `display_name`, `pre_validate`).
To exercise end-to-end: call the `generate_chart` MCP tool with
`{"chart_type": "treemap_v2", "groupby": [{"name": "region"}, {"name":
"product"}], "metric": {"name": "revenue", "aggregate": "SUM"}}`.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]