feat(mcp): add create_theme tool#40355
Draft
aminghadersohi wants to merge 1 commit into
Draft
Conversation
Adds the `create_theme` mutation tool under `superset/mcp_service/theme/` so AI agents can create Superset themes with custom Ant Design token styling via the Model Context Protocol. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40355 +/- ##
==========================================
- Coverage 64.20% 64.19% -0.01%
==========================================
Files 2592 2595 +3
Lines 139004 139054 +50
Branches 32273 32273
==========================================
+ Hits 89241 89264 +23
- Misses 48231 48258 +27
Partials 1532 1532
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new MCP “mutate” tool (create_theme) to let MCP clients create Superset themes backed by the existing Theme REST API validation/sanitization logic (Ant Design token JSON), and registers the tool with the MCP app.
Changes:
- Introduces
create_themeFastMCP tool that validates withThemePostSchema, writes a non-system Theme row, and returns a typed response. - Adds Pydantic request/response models for the tool under a new
superset.mcp_service.themepackage. - Registers the tool by importing it in
superset/mcp_service/app.py.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
superset/mcp_service/theme/tool/create_theme.py |
Implements the create_theme mutation tool (validation, DB insert, logging, response). |
superset/mcp_service/theme/tool/__init__.py |
Exposes create_theme for convenient package import/registration. |
superset/mcp_service/theme/schemas.py |
Adds Pydantic request/response schemas for the new tool. |
superset/mcp_service/theme/__init__.py |
Declares the new theme MCP subpackage. |
superset/mcp_service/app.py |
Imports create_theme so it gets registered on server startup. |
Comment on lines
+673
to
+675
| from superset.mcp_service.theme.tool import ( # noqa: F401, E402 | ||
| create_theme, | ||
| ) |
Comment on lines
+30
to
+41
| theme_name: str = Field( | ||
| ..., | ||
| description="Name of the theme to create.", | ||
| ) | ||
| json_data: str = Field( | ||
| ..., | ||
| description=( | ||
| "JSON string containing the theme configuration. " | ||
| "Must be valid Ant Design theme token JSON, e.g. " | ||
| '\'{"token": {"colorPrimary": "#1677ff"}}\'.' | ||
| ), | ||
| ) |
Comment on lines
+33
to
+45
| @tool( | ||
| tags=["mutate"], | ||
| class_permission_name="Theme", | ||
| method_permission_name="write", | ||
| annotations=ToolAnnotations( | ||
| title="Create theme", | ||
| readOnlyHint=False, | ||
| destructiveHint=False, | ||
| ), | ||
| ) | ||
| async def create_theme( | ||
| request: CreateThemeRequest, ctx: Context | ||
| ) -> CreateThemeResponse: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Adds a
create_thememutation tool to the Superset MCP service, allowing AI agents to create themes with custom Ant Design token styling.The tool follows the existing mutation tool pattern (same as
create_virtual_dataset):@tool(tags=["mutate"])withclass_permission_name="Theme"andmethod_permission_name="write"ThemePostSchema(same schema as the REST APIPOST /api/v1/theme/) to ensure theme name is non-empty andjson_datais valid, sanitized Ant Design token JSONis_system=False(user-created, same as REST API)CreateThemeResponsewith the new theme'sid,theme_name, andjson_data, or anerrorfield on validation failureNew files:
superset/mcp_service/theme/__init__.pysuperset/mcp_service/theme/schemas.py—CreateThemeRequest/CreateThemeResponsePydantic modelssuperset/mcp_service/theme/tool/__init__.pysuperset/mcp_service/theme/tool/create_theme.py— tool implementationapp.pyupdated to import and register the tool.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change.
TESTING INSTRUCTIONS
python -m superset.mcp_service)create_themewith:{ "theme_name": "My Blue Theme", "json_data": "{\"token\": {\"colorPrimary\": \"#1677ff\"}}" }idUnit test: run
pytest tests/unit_tests/mcp_service/to exercise existing fixtures.ADDITIONAL INFORMATION