aminghadersohi commented on code in PR #40357:
URL: https://github.com/apache/superset/pull/40357#discussion_r3328080569


##########
superset/mcp_service/plugin/tool/create_plugin.py:
##########
@@ -0,0 +1,108 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import logging
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.plugin.schemas import (
+    CreatePluginRequest,
+    CreatePluginResponse,
+)
+
+logger = logging.getLogger(__name__)
+
+
+@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.

Review Comment:
   Fixed: Added `tests/unit_tests/mcp_service/plugin/tool/test_plugin_tools.py` 
with async tool tests (via `fastmcp.Client`) and sync schema tests covering 
feature-flag gating, RBAC, success, IntegrityError, not-found, and 
unexpected-error paths for both tools.



##########
superset/mcp_service/plugin/tool/update_plugin.py:
##########
@@ -0,0 +1,116 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import logging
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.plugin.schemas import (
+    UpdatePluginRequest,
+    UpdatePluginResponse,
+)
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="DynamicPlugin",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Update a dynamic plugin",
+        readOnlyHint=False,
+        destructiveHint=True,
+    ),
+)
+async def update_plugin(
+    request: UpdatePluginRequest, ctx: Context
+) -> UpdatePluginResponse:
+    """Update an existing dynamic plugin's name, key, or bundle URL.
+
+    Requires admin write access to DynamicPlugin and the DYNAMIC_PLUGINS
+    feature flag to be enabled. At least one of ``name``, ``key``, or
+    ``bundle_url`` must be provided; only the supplied fields are changed.
+
+    Use ``create_plugin`` to look up the plugin ID if you only know the key.
+    """
+    await ctx.info("Updating dynamic plugin: id=%s" % (request.id,))
+
+    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 UpdatePluginResponse(
+                error=(
+                    "The DYNAMIC_PLUGINS feature flag is not enabled on this 
instance."
+                )
+            )
+
+        with event_logger.log_context(action="mcp.update_plugin.lookup"):
+            plugin = db.session.get(DynamicPlugin, request.id)
+
+        if plugin is None:
+            await ctx.warning("Plugin not found: id=%s" % (request.id,))
+            return UpdatePluginResponse(
+                error="No plugin found with id=%d. "
+                "Use the plugin ID returned by create_plugin." % request.id
+            )

Review Comment:
   Fixed: The not-found error message now directs users to the Custom Plugins 
UI (`Settings → Custom Plugins`) to look up the plugin ID, rather than pointing 
to `create_plugin`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to