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

   ### SUMMARY
   
   Adds a new `duplicate_dashboard` MCP tool to the Superset MCP service. The 
canonical AI workflow this enables: "create a regional/staging variant of this 
dashboard" — clone a template dashboard, then edit the copy.
   
   Design:
   - Wraps the existing `CopyDashboardCommand` (the same backend used by the 
frontend "Save as" flow on `/api/v1/dashboard/<id>/copy/`).
   - The source dashboard can be identified by numeric ID, UUID, or slug 
(resolved via `DashboardDAO.get_by_id_or_slug`, which applies dashboard access 
filters).
   - `DashboardCopySchema`'s copy data contract requires `json_metadata`; the 
tool builds it server-side from the source dashboard's current state 
(`json_metadata` plus a `positions` key from `position_json`), mirroring 
exactly what the frontend "Save as" sends. `json_metadata` is intentionally not 
exposed as a tool parameter.
   - `duplicate_slices: bool = false` — when true, every chart on the source 
dashboard is deep-copied into a new chart object owned by the caller; when 
false the copy references the same charts.
   - The new title is sanitized for XSS using the same pattern as 
`generate_dashboard` (nh3-based `sanitize_user_input`), with a warning surfaced 
when content is stripped and a hard error when the title sanitizes to nothing.
   - Structured error responses for source-not-found, access-denied, forbidden 
(`DASHBOARD_RBAC`), and copy failures; errors are wrapped for LLM-context 
safety.
   - Registered as a `mutate` tool (`class_permission_name="Dashboard"`, 
`method_permission_name="write"`) and added to 
`MCP_CACHE_CONFIG["excluded_tools"]` so responses are never cached.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A — MCP service tool, no UI changes.
   
   ### TESTING INSTRUCTIONS
   
   1. Start the MCP service and connect an MCP client.
   2. Call `duplicate_dashboard` with `{"dashboard_id": <existing 
id|uuid|slug>, "dashboard_title": "My Copy"}` — verify a new dashboard is 
created referencing the same charts, and the returned URL opens it.
   3. Call again with `"duplicate_slices": true` — verify the new dashboard 
contains new chart objects (different chart IDs) with the same layout.
   4. Verify error responses for a non-existent dashboard ID and for a 
dashboard the user cannot access.
   5. Run unit tests: `pytest 
tests/unit_tests/mcp_service/dashboard/tool/test_duplicate_dashboard.py`
   
   ### 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