feat(mcp): add create_tag tool#40358
Draft
aminghadersohi wants to merge 1 commit into
Draft
Conversation
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 Report❌ Patch coverage is
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
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_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_tagMCP mutation tool backed byCreateCustomTagWithRelationshipsCommand. - Added Pydantic schemas for
create_tagrequest/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), | ||
| ) |
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 new MCP mutation tool
create_tagthat 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— thecreate_tagMCP toolsuperset/mcp_service/tag/tool/__init__.py— module exportssuperset/mcp_service/tag/__init__.py— package initThe tool follows the established mutation pattern (same as
create_virtual_dataset):@tool(tags=["mutate"], class_permission_name="Tag", method_permission_name="write")CreateCustomTagWithRelationshipsCommand(same as the REST APIPOST /api/v1/tag/)CreateTagResponsewith tag ID, objects tagged/skipped, and error fieldevent_logger.log_contextBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend MCP tool only.
TESTING INSTRUCTIONS
create_tagwith{"name": "my-tag", "description": "test tag"}objects_to_tag: [["chart", 1]]to tag an object at creation timeADDITIONAL INFORMATION