aminghadersohi opened a new pull request, #40958:
URL: https://github.com/apache/superset/pull/40958

   ### 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](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [x] Introduces new feature or API
   - [ ] Removes existing feature or API


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