feat(mcp): add create_plugin tool for registering dynamic plugins#40357
Draft
aminghadersohi wants to merge 1 commit into
Draft
feat(mcp): add create_plugin tool for registering dynamic plugins#40357aminghadersohi wants to merge 1 commit into
aminghadersohi wants to merge 1 commit into
Conversation
Adds a new MCP mutation tool `create_plugin` under `mcp_service/plugin/` that allows admin users to register dynamic (custom) plugins by providing a name, unique key, and bundle URL. The tool checks the DYNAMIC_PLUGINS feature flag and handles duplicate-field errors gracefully. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40357 +/- ##
==========================================
- Coverage 64.20% 64.19% -0.01%
==========================================
Files 2592 2595 +3
Lines 139004 139056 +52
Branches 32273 32275 +2
==========================================
+ Hits 89241 89266 +25
- 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
This PR adds a new MCP mutation tool (create_plugin) to let authorized users register dynamic (custom) plugins via the MCP service, and wires it into MCP app registration and the default instructions.
Changes:
- Introduces
create_pluginMCP tool that createsDynamicPluginrows (with feature-flag gating and duplicate handling). - Adds Pydantic request/response schemas for the tool under
superset/mcp_service/plugin/. - Registers the tool in
superset/mcp_service/app.pyand documents it in the default instructions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| superset/mcp_service/plugin/tool/create_plugin.py | New MCP mutation tool implementation for registering dynamic plugins |
| superset/mcp_service/plugin/tool/init.py | Exports the new tool from the plugin tool package |
| superset/mcp_service/plugin/schemas.py | Adds Pydantic schemas for create_plugin request/response |
| superset/mcp_service/plugin/init.py | Makes the new MCP plugin package discoverable as a Python package |
| superset/mcp_service/app.py | Registers the tool with the MCP app and lists it in default instructions |
Comment on lines
+58
to
+105
| try: | ||
| from sqlalchemy.exc import IntegrityError | ||
|
|
||
| from superset import is_feature_enabled | ||
| from superset.extensions import db | ||
| from superset.models.dynamic_plugins import DynamicPlugin | ||
|
|
||
| if not is_feature_enabled("DYNAMIC_PLUGINS"): | ||
| await ctx.warning("DYNAMIC_PLUGINS feature flag is not enabled") | ||
| return CreatePluginResponse( | ||
| error=( | ||
| "The DYNAMIC_PLUGINS feature flag is not enabled on this instance." | ||
| ) | ||
| ) | ||
|
|
||
| with event_logger.log_context(action="mcp.create_plugin.create"): | ||
| plugin = DynamicPlugin( | ||
| name=request.name, | ||
| key=request.key, | ||
| bundle_url=request.bundle_url, | ||
| ) | ||
| db.session.add(plugin) | ||
| db.session.commit() | ||
|
|
||
| await ctx.info( | ||
| "Dynamic plugin registered: id=%s, key=%r" % (plugin.id, plugin.key) | ||
| ) | ||
|
|
||
| return CreatePluginResponse( | ||
| id=plugin.id, | ||
| name=plugin.name, | ||
| key=plugin.key, | ||
| bundle_url=plugin.bundle_url, | ||
| ) | ||
|
|
||
| except IntegrityError as exc: | ||
| db.session.rollback() | ||
| msg = str(exc.orig) if exc.orig else str(exc) | ||
| await ctx.warning("Plugin creation failed (duplicate field): %s" % (msg,)) | ||
| return CreatePluginResponse( | ||
| error=( | ||
| "A plugin with the same name, key, or bundle_url already exists. " | ||
| "Each field must be unique." | ||
| ) | ||
| ) | ||
| except Exception as exc: | ||
| db.session.rollback() | ||
| await ctx.error( |
Comment on lines
+26
to
+46
| name: str = Field( | ||
| ..., | ||
| min_length=1, | ||
| description="Human-friendly name for the plugin.", | ||
| ) | ||
| key: str = Field( | ||
| ..., | ||
| min_length=1, | ||
| description=( | ||
| "Unique plugin key. Should match the package name from the plugin's " | ||
| "package.json (e.g. '@my-org/my-chart-plugin')." | ||
| ), | ||
| ) | ||
| bundle_url: str = Field( | ||
| ..., | ||
| min_length=1, | ||
| description=( | ||
| "Full URL pointing to the built plugin bundle " | ||
| "(e.g. a CDN-hosted JavaScript file)." | ||
| ), | ||
| ) |
Comment on lines
+47
to
+49
| Requires the DYNAMIC_PLUGINS feature flag to be enabled and admin write | ||
| access to DynamicPlugin. The ``key`` must match the package name from the | ||
| plugin's package.json and be unique across all registered plugins. |
| - add_chart_to_existing_dashboard: Add a chart to an existing dashboard (requires write access) | ||
|
|
||
| Plugin Management: | ||
| - create_plugin: Register a new dynamic plugin by name, key, and bundle URL (requires admin write access and DYNAMIC_PLUGINS feature flag) |
Comment on lines
+32
to
+45
| @tool( | ||
| tags=["mutate"], | ||
| class_permission_name="DynamicPlugin", | ||
| method_permission_name="write", | ||
| annotations=ToolAnnotations( | ||
| title="Register a dynamic plugin", | ||
| readOnlyHint=False, | ||
| destructiveHint=False, | ||
| ), | ||
| ) | ||
| async def create_plugin( | ||
| request: CreatePluginRequest, ctx: Context | ||
| ) -> CreatePluginResponse: | ||
| """Register a new dynamic (custom) plugin in Superset. |
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_pluginthat allows admin users to register dynamic (custom) plugins via the MCP service.The tool lives under
superset/mcp_service/plugin/and follows the established mutation pattern used bycreate_virtual_dataset.Key details:
create_pluginname(required),key(required, unique plugin identifier matching package.json),bundle_url(required, full URL to the built plugin bundle)DynamicPlugin/write— admin-only, same access level as the existingDynamicPluginsViewDYNAMIC_PLUGINSfeature flag is disabledIntegrityErrorgracefully without raisingmcp_service/app.pyand included in the tool listing in instructionsBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change.
TESTING INSTRUCTIONS
DYNAMIC_PLUGINSfeature flag insuperset_config.pycreate_pluginwith validname,key, andbundle_urlcreate_pluginwith a duplicatekeyreturns a structured error (not an exception)create_pluginwithout admin permissions is rejectedADDITIONAL INFORMATION
DYNAMIC_PLUGINSmust be enabled