Skip to content

feat(mcp): add create_tag tool#40358

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

feat(mcp): add create_tag tool#40358
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:amin/mcp-create-tag

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds a new MCP mutation tool create_tag that allows AI agents to create custom tags in Superset and optionally apply them to objects (charts, dashboards, datasets, queries) in a single call.

New files:

  • superset/mcp_service/tag/schemas.py — Pydantic request/response schemas (CreateTagRequest, CreateTagResponse)
  • superset/mcp_service/tag/tool/create_tag.py — the create_tag MCP tool
  • superset/mcp_service/tag/tool/__init__.py — module exports
  • superset/mcp_service/tag/__init__.py — package init

The tool follows the established mutation pattern (same as create_virtual_dataset):

  • @tool(tags=["mutate"], class_permission_name="Tag", method_permission_name="write")
  • Uses CreateCustomTagWithRelationshipsCommand (same as the REST API POST /api/v1/tag/)
  • Returns structured CreateTagResponse with tag ID, objects tagged/skipped, and error field
  • Wraps operation with event_logger.log_context

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend MCP tool only.

TESTING INSTRUCTIONS

  1. Start the MCP server
  2. Call create_tag with {"name": "my-tag", "description": "test tag"}
  3. Verify the tag is created and the response includes the tag ID
  4. Optionally provide objects_to_tag: [["chart", 1]] to tag an object at creation time

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Adds a new MCP mutation tool `create_tag` that allows AI agents to
create custom tags in Superset and optionally apply them to charts,
dashboards, datasets, or queries in a single call.

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 53.33333% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.19%. Comparing base (5966bb1) to head (5aa240f).

Files with missing lines Patch % Lines
superset/mcp_service/tag/tool/create_tag.py 27.58% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40358      +/-   ##
==========================================
- Coverage   64.20%   64.19%   -0.01%     
==========================================
  Files        2592     2595       +3     
  Lines      139004   139049      +45     
  Branches    32273    32273              
==========================================
+ Hits        89241    89265      +24     
- Misses      48231    48252      +21     
  Partials     1532     1532              
Flag Coverage Δ
hive 39.31% <53.33%> (+<0.01%) ⬆️
mysql 58.81% <53.33%> (-0.01%) ⬇️
postgres 58.89% <53.33%> (-0.01%) ⬇️
presto 40.98% <53.33%> (+<0.01%) ⬆️
python 60.45% <53.33%> (-0.01%) ⬇️
sqlite 58.53% <53.33%> (-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_tag) to create custom Superset tags and optionally tag multiple objects in one call, wiring the tool into MCP registration and introducing Pydantic request/response schemas.

Changes:

  • Added create_tag MCP mutation tool backed by CreateCustomTagWithRelationshipsCommand.
  • Added Pydantic schemas for create_tag request/response payloads.
  • Registered the new tool in the MCP app’s tool import list.

Reviewed changes

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

Show a summary per file
File Description
superset/mcp_service/tag/tool/create_tag.py Implements the new MCP tool and maps command results into a structured response.
superset/mcp_service/tag/tool/init.py Exposes create_tag from the tag tool package.
superset/mcp_service/tag/schemas.py Defines Pydantic request/response models for the tool.
superset/mcp_service/tag/init.py Initializes the new tag MCP service package.
superset/mcp_service/app.py Imports create_tag to ensure it’s registered with the global MCP instance.

Comment on lines +29 to +37
@tool(
tags=["mutate"],
class_permission_name="Tag",
method_permission_name="write",
annotations=ToolAnnotations(
title="Create a tag",
readOnlyHint=False,
destructiveHint=False,
),
Comment on lines +61 to +70
properties = {
"name": request.name,
"description": request.description or "",
"objects_to_tag": request.objects_to_tag,
}
objects_tagged, objects_skipped = CreateCustomTagWithRelationshipsCommand(
properties
).run()

tag = TagDAO.find_by_name(request.name)
Comment on lines +61 to +66
properties = {
"name": request.name,
"description": request.description or "",
"objects_to_tag": request.objects_to_tag,
}
objects_tagged, objects_skipped = CreateCustomTagWithRelationshipsCommand(
Comment on lines +26 to +45
name: str = Field(
...,
min_length=1,
description=(
"Name for the new tag. Must be unique. "
"Used to identify and reference the tag across Superset."
),
)
description: str | None = Field(
None,
description="Optional human-readable description for the tag.",
)
objects_to_tag: list[tuple[str, int]] = Field(
default_factory=list,
description=(
"Optional list of objects to apply this tag to immediately after creation. "
"Each item is a [object_type, object_id] pair where object_type is one of: "
"'chart', 'dashboard', 'dataset', 'query'."
),
)
Comment on lines +673 to +675
from superset.mcp_service.tag.tool import ( # noqa: F401, E402
create_tag,
)
Comment on lines +39 to +50
async def create_tag(request: CreateTagRequest, ctx: Context) -> CreateTagResponse:
"""Create a new custom tag in Superset, optionally applying it to objects.

Use this tool to create tags for organizing charts, dashboards, datasets,
and queries. Tags can be applied to multiple objects at creation time.

Workflow:
1. Call this tool with a tag name and optional description
2. Optionally provide objects_to_tag to apply the tag immediately
3. Use the returned ``id`` to reference the tag in future operations
"""
await ctx.info("Creating tag: name=%r" % (request.name,))
Comment on lines +82 to +88
return CreateTagResponse(
id=tag.id if tag else None,
name=request.name,
description=request.description,
objects_tagged=list(objects_tagged),
objects_skipped=list(objects_skipped),
)
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