Repository navigation
feat(mcp): add restore_chart and restore_dashboard tools - #41842
Conversation
Expose the soft-delete restore capability (apache#40128, apache#40129) to MCP clients. The tools delegate to Restore{Chart,Dashboard}Command for ownership and is-trashed validation, accept numeric ID or UUID (resolved via find_by_id_or_uuid with skip_visibility_filter, keeping the RBAC base_filter in effect), and return distinct NotFound vs NotDeleted error types. Like the REST restore endpoints they are not gated on SOFT_DELETE so rows trashed while the flag was on stay recoverable. 12 unit tests. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8
Code Review Agent Run #702b65Actionable Suggestions - 0Additional Suggestions - 1
Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #41842 +/- ##
==========================================
- Coverage 64.88% 64.81% -0.07%
==========================================
Files 2742 2748 +6
Lines 153378 153773 +395
Branches 35168 35200 +32
==========================================
+ Hits 99516 99665 +149
- Misses 51958 52198 +240
- Partials 1904 1910 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Lots of bot comments here to assess/address/refute/resolve, if you don't mind sorting them out. |
Chart names and dashboard titles are user-controlled text; wrap them via sanitize_for_llm_context before composing response messages and the restored_name field, matching the convention in the get/list and manage_native_filters paths (review: codeant). Also annotate the test fixtures. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8
|
Sorted — all 8 threads triaged and resolved. Applied: LLM-context sanitization of chart/dashboard names in the restore responses (matching the get/list convention) and fixture annotations. Disputed in-thread: the two suggestions to reorder the NotDeleted check behind an ownership gate — BaseRestoreCommand.validate itself checks deleted_at before raise_for_ownership, so the tool mirrors the REST endpoint's exact semantics; and the logger/local annotation nits (not repo convention). |
|
Bito Automatic Review Failed - Technical Failure |
|
Cross-reference: per the discussion on #41472, this PR is the confirmed companion to the delete tools — the maintainer opted to keep them as a reviewed-together pair (and endorsed the restore_* naming, matching the REST route). |
…ls landed); align editor-rights wording with the restore command
Mirror the delete-tools hardening: identifier lookups return a structured LookupFailed response on database errors instead of escaping the tool, and raw SQLAlchemyError text no longer reaches the client (generic message; full exception in server logs). With a test. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8
Code Review Agent Run #fc60c9Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
aminghadersohi
left a comment
There was a problem hiding this comment.
RBAC + soft-delete-state verdict: sound — both tools delegate entirely to RestoreChartCommand/RestoreDashboardCommand → BaseRestoreCommand.validate(), which enforces ownership via raise_for_editorship after the not-found/not-deleted check (verified against superset/commands/restore.py); no bypass logic added by the tools. codeant's 8 threads are already triaged: prompt-injection sanitization and raw-DB-error masking are fixed at this HEAD; the type-annotation and NotDeleted-ordering declines are correctly justified against current source. One thread (base_filter in the pre-lookup) is reopened below — the author's stated resolution doesn't match superset/commands/restore.py at this HEAD, though the effect is over-restrictive (false NotFound), not a security escalation. Remaining findings are test-coverage gaps in recently-added error branches. Author is an external CONTRIBUTOR — leaving this at COMMENT for a maintainer to approve.
BaseRestoreCommand.validate passes skip_base_filter=True by design so an editor's own trash stays reachable after a lost base_filter grant; the tools' pre-lookup keeping base_filter enabled was stricter than the command it wraps and could return a false NotFound for a legitimate editor (review: aminghadersohi). Also close the flagged coverage gaps: LookupFailed branch (chart), SQLAlchemyError masking and DashboardSlugConflictError passthrough (dashboard). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8
… tools Mirror the delete-tools hardening: reject boolean identifiers (bool subclasses int; identifier=true would coerce to ID 1) and move the try/except inside event_logger.log_context so failed restore attempts are recorded in the audit log (review: codeant). With tests. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8
Code Review Agent Run #76dbc4Actionable Suggestions - 0Additional Suggestions - 1
Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Co-authored-by: Greg Neighbors <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
…e for list_datasets The MCP server can create datasets but cannot delete them, so an agent that creates exploratory virtual datasets has no way to clean them up. Charts and dashboards already have delete, restore and trash listing (apache#41472, apache#41842, apache#41855), and dataset soft-delete landed in apache#40130, but the MCP side of it was never added. - delete_dataset: delete by numeric ID or UUID via DeleteDatasetCommand, which enforces editorship. The response reports whether the row went to trash (SOFT_DELETE) or was removed permanently, plus the number of charts and dashboards built on the dataset, counted the same way as GET /api/v1/dataset/<pk>/related_objects so inaccessible objects are not disclosed. - restore_dataset: restore a trashed dataset via RestoreDatasetCommand, with distinct NotFound, NotDeleted and LogicalDuplicate errors. The lookup uses the same filter bypasses as the command. - list_datasets: deleted_state ('include' / 'only') reusing DatasetDeletedStateFilter, so trashed datasets can be found and restored. DatasetInfo gains deleted_at. Co-Authored-By: Claude Opus 5 <[email protected]>
…e for list_datasets The MCP server can create datasets but cannot delete them, so an agent that creates exploratory virtual datasets has no way to clean them up. Charts and dashboards already have delete, restore and trash listing (apache#41472, apache#41842, was never added. - delete_dataset: delete by numeric ID or UUID via DeleteDatasetCommand, which enforces editorship. The response reports whether the row went to trash (SOFT_DELETE) or was removed permanently, plus the number of charts and dashboards built on the dataset, counted the same way as GET /api/v1/dataset/<pk>/related_objects so inaccessible objects are not disclosed. - restore_dataset: restore a trashed dataset via RestoreDatasetCommand, with distinct NotFound, NotDeleted and LogicalDuplicate errors. The lookup uses the same filter bypasses as the command. - list_datasets: deleted_state ('include' / 'only') reusing DatasetDeletedStateFilter, so trashed datasets can be found and restored. DatasetInfo gains deleted_at. Co-Authored-By: Claude Opus 5 <[email protected]>
SUMMARY
Adds
restore_chartandrestore_dashboardMCP tools, exposing the soft-delete restore capability introduced in #40129 / #40128 to MCP clients. With soft-delete rolling out behind theSOFT_DELETEfeature flag, an LLM agent can trash a chart or dashboard via the REST-backed delete flows (and, pending #41472, via MCP delete tools) but has no way to undo it — these tools close that loop.Design notes:
Restore{Chart,Dashboard}Command— ownership checks, the "is actually soft-deleted" guard, and transactional wrapping all live in the existing command layer; the tools add no new authorization logic.find_by_id_or_uuid(..., skip_visibility_filter=True). Matching the command's own lookup semantics, the visibility filter is the only bypass — the DAObase_filterstays in effect, so rows the user can't see in the live UI stay hidden, and ownership is then enforced by the command.SOFT_DELETE— mirroring the RESTPOST /api/v1/chart/<uuid>/restoreendpoint, restore stays available even if the flag is later disabled, so rows trashed while it was on remain recoverable.NotFoundvsNotDeleted("is not in trash; nothing to restore") error types, and the establishedpermission_denied: true/ "do not retry; ask the user" convention for ownership failures.Part of a series filling out MCP resource-lifecycle coverage (delete: #41472).
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (MCP service tools; no UI changes)
TESTING INSTRUCTIONS
Unit tests (12 new, run through the async FastMCP client like the other tool tests):
pytest tests/unit_tests/mcp_service/chart/tool/test_restore_chart.py \ tests/unit_tests/mcp_service/dashboard/tool/test_restore_dashboard.pyManual: with
FEATURE_FLAGS = {"SOFT_DELETE": True}, delete a chart you own (UI or API), then call therestore_chartMCP tool with its numeric ID or UUID — the chart reappears in list/detail endpoints. Calling it again returnserror_type: "NotDeleted". Calling it on someone else's trashed chart returnspermission_denied: true.ADDITIONAL INFORMATION
SOFT_DELETE(to produce trashed rows; the restore tools themselves are not gated)🤖 Generated with Claude Code
https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8