Skip to content

feat(mcp): add remove_chart_from_dashboard tool#40958

Open
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:mcp-remove-chart-from-dashboard
Open

feat(mcp): add remove_chart_from_dashboard tool#40958
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:mcp-remove-chart-from-dashboard

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

SUMMARY

Adds a new MCP tool, remove_chart_from_dashboard, the missing inverse of add_chart_to_existing_dashboard. Without it, agents that add a wrong chart to a dashboard have no recovery path.

The tool:

  • Removes all CHART layout components referencing the chart from position_json (a chart can appear under multiple tabs), and prunes ROW/COLUMN containers left empty by the removal so no orphaned wrapper nodes remain. TAB/TABS/GRID/ROOT containers are intentionally never pruned.
  • Explicitly passes the updated slices relationship (ORM objects with the removed chart excluded) to UpdateDashboardCommand, since updating position_json alone does not sync dashboard.slices.
  • Cleans stale chart references from json_metadata: expanded_slices, timed_refresh_immune_slices, and filter_scopes (both filter-chart keys and per-column immune lists). When metadata changed, the new layout is included under "positions" so DashboardDAO.set_dash_metadata takes its legacy branch that preserves and re-scopes filter_scopes instead of dropping them.
  • Error cases: dashboard not found, no edit permission (permission_denied=True so the LLM informs the user instead of attempting a workaround), and chart not present in the dashboard.
  • Annotated with ToolAnnotations(readOnlyHint=False, destructiveHint=True) and tags=["mutate"] / Dashboard-write RBAC, mirroring add_chart_to_existing_dashboard (same authorization, command write, and post-write eager re-fetch patterns).

The chart itself is not deleted — it remains available to other dashboards.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (MCP service tool, no UI changes)

TESTING INSTRUCTIONS

  1. Run the unit tests: pytest tests/unit_tests/mcp_service/dashboard/tool/test_remove_chart_from_dashboard.py
  2. Or manually via an MCP client connected to the MCP service:
    • Call add_chart_to_existing_dashboard with a dashboard_id/chart_id, then remove_chart_from_dashboard with the same arguments.
    • Verify the chart disappears from the dashboard, the layout has no empty leftover rows/columns, and json_metadata no longer references the chart.

Tests cover: dashboard not found, permission denied, chart not in dashboard, simple grid removal with empty-row pruning, chart inside a COLUMN (sibling kept; lone chart prunes COLUMN+ROW), chart under multiple tabs (all occurrences removed, tabs kept), json_metadata cleanup, chart attached to slices but absent from layout, and malformed-metadata robustness.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • 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

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.83333% with 133 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.29%. Comparing base (f79a88c) to head (8f2823f).
⚠️ Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
...vice/dashboard/tool/remove_chart_from_dashboard.py 14.47% 130 Missing ⚠️
superset/mcp_service/dashboard/schemas.py 80.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40958      +/-   ##
==========================================
+ Coverage   64.19%   64.29%   +0.10%     
==========================================
  Files        2655     2658       +3     
  Lines      143925   145858    +1933     
  Branches    33181    33536     +355     
==========================================
+ Hits        92386    93783    +1397     
- Misses      49919    50398     +479     
- Partials     1620     1677      +57     
Flag Coverage Δ
hive 39.74% <20.83%> (+0.28%) ⬆️
mysql 58.58% <20.83%> (+0.39%) ⬆️
postgres 58.65% <20.83%> (+0.39%) ⬆️
presto 41.36% <20.83%> (+0.31%) ⬆️
python 60.08% <20.83%> (+0.35%) ⬆️
sqlite 58.28% <20.83%> (+0.40%) ⬆️
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.

@aminghadersohi aminghadersohi marked this pull request as ready for review June 12, 2026 21:16
@bito-code-review

bito-code-review Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #19fe4a

Actionable Suggestions - 0
Filtered by Review Rules

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

  • superset/mcp_service/dashboard/tool/remove_chart_from_dashboard.py - 1
Review Details
  • Files reviewed - 5 · Commit Range: 8f2823f..8f2823f
    • superset/mcp_service/app.py
    • superset/mcp_service/dashboard/schemas.py
    • superset/mcp_service/dashboard/tool/__init__.py
    • superset/mcp_service/dashboard/tool/remove_chart_from_dashboard.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_remove_chart_from_dashboard.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant