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


##########
superset/mcp_service/dashboard/tool/delete_dashboard.py:
##########
@@ -0,0 +1,144 @@
+# 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.
+
+"""
+MCP tool: delete_dashboard
+
+This tool permanently deletes a dashboard. It requires an explicit
+``confirm=true`` safety gate so callers must state destructive intent.
+"""
+
+import logging
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.dashboard.schemas import (
+    DeleteDashboardRequest,
+    DeleteDashboardResponse,
+    DeletedDashboardSummary,
+)
+
+logger = logging.getLogger(__name__)

Review Comment:
   Declining this one: the codebase convention throughout 
`superset/mcp_service` (and superset generally) is an unannotated `logger = 
logging.getLogger(__name__)` — mypy infers `logging.Logger` and passes in CI. 
Annotating only this module would deviate from every sibling tool file.



##########
superset/mcp_service/dashboard/tool/delete_dashboard.py:
##########
@@ -0,0 +1,144 @@
+# 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.
+
+"""
+MCP tool: delete_dashboard
+
+This tool permanently deletes a dashboard. It requires an explicit
+``confirm=true`` safety gate so callers must state destructive intent.
+"""
+
+import logging
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.dashboard.schemas import (
+    DeleteDashboardRequest,
+    DeleteDashboardResponse,
+    DeletedDashboardSummary,
+)
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="Dashboard",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Delete dashboard",
+        readOnlyHint=False,
+        destructiveHint=True,
+    ),
+)
+async def delete_dashboard(
+    request: DeleteDashboardRequest, ctx: Context
+) -> DeleteDashboardResponse:
+    """
+    Permanently delete a dashboard by ID. The charts on the dashboard are
+    NOT deleted — only the dashboard itself. This action cannot be undone,
+    so the tool refuses to run unless ``confirm=true`` is explicitly passed.
+    """
+    from superset.commands.dashboard.delete import DeleteDashboardCommand
+    from superset.commands.dashboard.exceptions import (
+        DashboardDeleteFailedError,
+        DashboardForbiddenError,
+        DashboardNotFoundError,
+    )
+    from superset.daos.dashboard import DashboardDAO
+
+    if not request.confirm:
+        await ctx.warning(
+            "Deletion of dashboard %s not confirmed" % (request.dashboard_id,)
+        )
+        return DeleteDashboardResponse(
+            deleted=False,
+            dashboard=None,
+            error=(
+                f"Deletion not confirmed. Deleting dashboard "
+                f"{request.dashboard_id} is permanent and cannot be undone. "
+                "Re-run with confirm=true to proceed."
+            ),
+        )
+
+    summary: DeletedDashboardSummary | None = None
+    try:
+        with 
event_logger.log_context(action="mcp.delete_dashboard.validation"):
+            dashboard = DashboardDAO.find_by_id(request.dashboard_id)

Review Comment:
   Declining: the type is inferred from `DashboardDAO.find_by_id`'s return 
annotation (`Dashboard | None`), and mypy validates the narrowing (the `if not 
dashboard` guard) without an explicit local annotation. This matches the style 
of the other dashboard tools in this module.



-- 
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