Skip to content

feat(mcp): add restore_chart and restore_dashboard tools - #41842

Merged
rusackas merged 7 commits into
apache:masterfrom
gkneighb:feat/mcp-restore-chart-dashboard
Jul 15, 2026
Merged

rusackas merged 7 commits into
apache:masterfrom
gkneighb:feat/mcp-restore-chart-dashboard

Conversation

@gkneighb

@gkneighb gkneighb commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

Adds restore_chart and restore_dashboard MCP tools, exposing the soft-delete restore capability introduced in #40129 / #40128 to MCP clients. With soft-delete rolling out behind the SOFT_DELETE feature 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:

  • Delegates to 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.
  • Accepts numeric ID or UUID. The restore commands are UUID-keyed, but MCP list/info/delete tools deal in numeric IDs, so the tools resolve the identifier via find_by_id_or_uuid(..., skip_visibility_filter=True). Matching the command's own lookup semantics, the visibility filter is the only bypass — the DAO base_filter stays in effect, so rows the user can't see in the live UI stay hidden, and ownership is then enforced by the command.
  • Not gated on SOFT_DELETE — mirroring the REST POST /api/v1/chart/<uuid>/restore endpoint, restore stays available even if the flag is later disabled, so rows trashed while it was on remain recoverable.
  • LLM-friendly errors — distinct NotFound vs NotDeleted ("is not in trash; nothing to restore") error types, and the established permission_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.py

Manual: with FEATURE_FLAGS = {"SOFT_DELETE": True}, delete a chart you own (UI or API), then call the restore_chart MCP tool with its numeric ID or UUID — the chart reappears in list/detail endpoints. Calling it again returns error_type: "NotDeleted". Calling it on someone else's trashed chart returns permission_denied: true.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: SOFT_DELETE (to produce trashed rows; the restore tools themselves are not gated)
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

https://claude.ai/code/session_014z1fQxTadTEvpCJLx9WnB8

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
@dosubot dosubot Bot added api Related to the REST API dashboard Namespace | Anything related to the Dashboard labels Jul 7, 2026
@bito-code-review

bito-code-review Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #702b65

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/mcp_service/dashboard/tool/restore_dashboard.py - 1
    • Missing sanitization for dashboard name · Line 111-111
      The `dashboard_name` at line 111 is interpolated into the error message string but is not passed through `escape_llm_context_delimiters`. This contrasts with the identifier sanitization at line 100. For consistency and safety when dashboard titles contain LLM delimiter characters (e.g., ```), sanitize dashboard_name the same way.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/mcp_service/dashboard/tool/restore_dashboard.py - 1
  • superset/mcp_service/dashboard/schemas.py - 1
Review Details
  • Files reviewed - 9 · Commit Range: 77f1406..77f1406
    • superset/mcp_service/app.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/chart/tool/__init__.py
    • superset/mcp_service/chart/tool/restore_chart.py
    • superset/mcp_service/dashboard/schemas.py
    • superset/mcp_service/dashboard/tool/__init__.py
    • superset/mcp_service/dashboard/tool/restore_dashboard.py
    • tests/unit_tests/mcp_service/chart/tool/test_restore_chart.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_restore_dashboard.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot removed the api Related to the REST API label Jul 7, 2026
@codecov

codecov Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 37.50000% with 85 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.81%. Comparing base (5e6b29d) to head (1c6e35b).
⚠️ Report is 48 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/chart/tool/restore_chart.py 28.84% 37 Missing ⚠️
...et/mcp_service/dashboard/tool/restore_dashboard.py 28.84% 37 Missing ⚠️
superset/mcp_service/dashboard/schemas.py 42.85% 8 Missing ⚠️
superset/mcp_service/chart/schemas.py 81.25% 3 Missing ⚠️
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     
Flag Coverage Δ
hive 39.06% <37.50%> (-0.02%) ⬇️
mysql 57.86% <37.50%> (-0.11%) ⬇️
postgres 57.91% <37.50%> (-0.12%) ⬇️
presto 41.04% <37.50%> (-0.03%) ⬇️
python 59.29% <37.50%> (-0.12%) ⬇️
sqlite 57.52% <37.50%> (-0.11%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas

rusackas commented Jul 7, 2026

Copy link
Copy Markdown
Member

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

netlify Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 5396679
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a52ef5291b4cc00086f2704
😎 Deploy Preview https://deploy-preview-41842--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@gkneighb

gkneighb commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

Bito Automatic Review Failed - Technical Failure

Bito encountered technical difficulties while generating code feedback . To retry, type /review in a comment and save. If the issue persists, contact [email protected] and provide the following details:

Agent Run ID: b4325210-4978-4857-9db1-269d16d1b7ad

@gkneighb

Copy link
Copy Markdown
Contributor Author

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
@bito-code-review

bito-code-review Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #fc60c9

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/mcp_service/dashboard/tool/restore_dashboard.py - 1
    • CWE-209: Inconsistent error_type in catch block · Line 101-110
      Capture the exception in the lookup handler (e.g., `except SQLAlchemyError as ex:`) and set `error_type=type(ex).__name__` to match the pattern used in the command-level handler.
Review Details
  • Files reviewed - 4 · Commit Range: 77f1406..2ab66a2
    • superset/mcp_service/chart/tool/restore_chart.py
    • superset/mcp_service/dashboard/tool/restore_dashboard.py
    • tests/unit_tests/mcp_service/chart/tool/test_restore_chart.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_restore_dashboard.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@bito-code-review

bito-code-review Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #76dbc4

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/mcp_service/chart/schemas.py - 1
    • Semantic duplication of validator · Line 2738-2745
      The `reject_bool_identifier` validator is semantically duplicated — identical code already exists in `DeleteChartRequest` (line 2782) in the same file, and in two dashboard request classes. Consider extracting to a reusable utility function to prevent divergence.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/mcp_service/chart/tool/restore_chart.py - 1
Review Details
  • Files reviewed - 6 · Commit Range: 2ab66a2..1c6e35b
    • superset/mcp_service/chart/tool/restore_chart.py
    • superset/mcp_service/dashboard/tool/restore_dashboard.py
    • tests/unit_tests/mcp_service/chart/tool/test_restore_chart.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_restore_dashboard.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/dashboard/schemas.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@gkneighb gkneighb mentioned this pull request Jul 15, 2026
1 of 9 tasks
@rusackas
rusackas merged commit 8ce6d42 into apache:master Jul 15, 2026
59 checks passed
rdg0 pushed a commit to rdg0/superset that referenced this pull request Jul 20, 2026
tien238lnd added a commit to tien238lnd/superset that referenced this pull request Sep 17, 2026
…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]>
tien238lnd added a commit to tien238lnd/superset that referenced this pull request Sep 23, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboard Namespace | Anything related to the Dashboard size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants