Skip to content

feat(mcp): add create_theme tool#40355

Draft
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:amin/mcp-create-theme
Draft

feat(mcp): add create_theme tool#40355
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:amin/mcp-create-theme

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds a create_theme mutation 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"]) with class_permission_name="Theme" and method_permission_name="write"
  • Validates input via ThemePostSchema (same schema as the REST API POST /api/v1/theme/) to ensure theme name is non-empty and json_data is valid, sanitized Ant Design token JSON
  • Creates the theme with is_system=False (user-created, same as REST API)
  • Returns a typed CreateThemeResponse with the new theme's id, theme_name, and json_data, or an error field on validation failure

New files:

  • superset/mcp_service/theme/__init__.py
  • superset/mcp_service/theme/schemas.pyCreateThemeRequest / CreateThemeResponse Pydantic models
  • superset/mcp_service/theme/tool/__init__.py
  • superset/mcp_service/theme/tool/create_theme.py — tool implementation

app.py updated to import and register the tool.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend-only change.

TESTING INSTRUCTIONS

  1. Start the MCP server (python -m superset.mcp_service)
  2. Connect an MCP client and call create_theme with:
    {
      "theme_name": "My Blue Theme",
      "json_data": "{\"token\": {\"colorPrimary\": \"#1677ff\"}}"
    }
  3. Verify the response includes a non-null id
  4. Confirm the theme appears in Superset under Settings → Themes

Unit test: run pytest tests/unit_tests/mcp_service/ to exercise existing fixtures.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

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
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 46.00000% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.19%. Comparing base (5966bb1) to head (c94b579).

Files with missing lines Patch % Lines
superset/mcp_service/theme/tool/create_theme.py 25.00% 27 Missing ⚠️
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              
Flag Coverage Δ
hive 39.30% <46.00%> (+<0.01%) ⬆️
mysql 58.80% <46.00%> (-0.02%) ⬇️
postgres 58.88% <46.00%> (-0.02%) ⬇️
presto 40.97% <46.00%> (+<0.01%) ⬆️
python 60.44% <46.00%> (-0.02%) ⬇️
sqlite 58.52% <46.00%> (-0.01%) ⬇️
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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_theme FastMCP tool that validates with ThemePostSchema, 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.theme package.
  • 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:
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.

2 participants