Skip to content

feat(mcp): add create_annotation_layer tool#40352

Draft
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:kasiazjc/mcp-create-annotation-layer
Draft

feat(mcp): add create_annotation_layer tool#40352
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:kasiazjc/mcp-create-annotation-layer

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds create_annotation_layer as a new MCP mutation tool that allows AI assistants to create named annotation layers in Superset programmatically.

The tool follows the existing mutation pattern (create_virtual_dataset) and calls the existing CreateAnnotationLayerCommand. It accepts a name (required) and optional descr, validates uniqueness, and returns the created layer's id, name, and descr.

New files:

  • superset/mcp_service/annotation_layer/__init__.py
  • superset/mcp_service/annotation_layer/schemas.pyCreateAnnotationLayerRequest / CreateAnnotationLayerResponse Pydantic schemas
  • superset/mcp_service/annotation_layer/tool/__init__.py
  • superset/mcp_service/annotation_layer/tool/create_annotation_layer.py — the @tool implementation

Modified:

  • superset/mcp_service/app.py — registers the new tool

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend-only change.

TESTING INSTRUCTIONS

  1. Start a Superset instance with MCP enabled
  2. Connect an MCP client and call create_annotation_layer with {"request": {"name": "My Layer"}}
  3. Verify a new annotation layer appears in Superset → Manage → Annotation Layers
  4. Call again with the same name — verify a validation error is returned (name uniqueness)

ADDITIONAL INFORMATION

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

Adds a mutation tool that creates named annotation layers via
CreateAnnotationLayerCommand, following the existing mutation pattern
(create_virtual_dataset). Registers the tool in app.py under the
annotation_layer module.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 52.00000% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.19%. Comparing base (5966bb1) to head (6a49085).

Files with missing lines Patch % Lines
...e/annotation_layer/tool/create_annotation_layer.py 30.00% 21 Missing ⚠️
superset/mcp_service/annotation_layer/schemas.py 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40352      +/-   ##
==========================================
- Coverage   64.20%   64.19%   -0.01%     
==========================================
  Files        2592     2595       +3     
  Lines      139004   139054      +50     
  Branches    32273    32275       +2     
==========================================
+ Hits        89241    89267      +26     
- Misses      48231    48255      +24     
  Partials     1532     1532              
Flag Coverage Δ
hive 39.31% <52.00%> (+0.01%) ⬆️
mysql 58.81% <52.00%> (-0.01%) ⬇️
postgres 58.89% <52.00%> (-0.01%) ⬇️
presto 40.98% <52.00%> (+<0.01%) ⬆️
python 60.45% <52.00%> (-0.01%) ⬇️
sqlite 58.53% <52.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 mutation tool to let MCP clients programmatically create Superset annotation layers by calling the existing CreateAnnotationLayerCommand, and wires the tool into MCP registration.

Changes:

  • Introduces create_annotation_layer MCP tool (mutation) that creates an annotation layer and returns {id, name, descr, error}.
  • Adds Pydantic request/response schemas for the new tool.
  • Registers the new tool in the MCP app import registry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
superset/mcp_service/app.py Registers the new annotation-layer tool via import-time tool registration.
superset/mcp_service/annotation_layer/init.py Adds new MCP service package namespace for annotation-layer tooling.
superset/mcp_service/annotation_layer/schemas.py Defines Pydantic request/response schemas for create_annotation_layer.
superset/mcp_service/annotation_layer/tool/init.py Exposes the tool function for import/registration.
superset/mcp_service/annotation_layer/tool/create_annotation_layer.py Implements the MCP tool wrapper around CreateAnnotationLayerCommand with logging and error mapping.

Comment on lines +30 to +33
name: str = Field(..., description="Unique name for the annotation layer")
descr: str | None = Field(
None, description="Optional description of the annotation layer"
)
Comment on lines +43 to +46
async def create_annotation_layer(
request: CreateAnnotationLayerRequest, ctx: Context
) -> CreateAnnotationLayerResponse:
"""Create a named annotation layer in Superset.
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