feat(mcp): add duplicate_dashboard tool#40959
Conversation
Adds a duplicate_dashboard MCP tool that clones an existing dashboard via CopyDashboardCommand. The source dashboard can be identified by numeric ID, UUID, or slug. By default the copy references the same charts; duplicate_slices=true deep-copies every chart into new objects owned by the caller. The tool builds the required json_metadata payload (source metadata plus a positions key from position_json), mirroring what the frontend "Save as" flow sends to the /copy/ endpoint. The new title is sanitized for XSS, and the tool is excluded from MCP response caching.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40959 +/- ##
==========================================
+ Coverage 64.19% 64.31% +0.12%
==========================================
Files 2655 2658 +3
Lines 143925 145812 +1887
Branches 33181 33522 +341
==========================================
+ Hits 92386 93785 +1399
- Misses 49919 50350 +431
- Partials 1620 1677 +57
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:
|
Code Review Agent Run #e866e5Actionable Suggestions - 0Additional Suggestions - 2
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 |
SUMMARY
Adds a new
duplicate_dashboardMCP 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:
CopyDashboardCommand(the same backend used by the frontend "Save as" flow on/api/v1/dashboard/<id>/copy/).DashboardDAO.get_by_id_or_slug, which applies dashboard access filters).DashboardCopySchema's copy data contract requiresjson_metadata; the tool builds it server-side from the source dashboard's current state (json_metadataplus apositionskey fromposition_json), mirroring exactly what the frontend "Save as" sends.json_metadatais 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.generate_dashboard(nh3-basedsanitize_user_input), with a warning surfaced when content is stripped and a hard error when the title sanitizes to nothing.DASHBOARD_RBAC), and copy failures; errors are wrapped for LLM-context safety.mutatetool (class_permission_name="Dashboard",method_permission_name="write") and added toMCP_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
duplicate_dashboardwith{"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."duplicate_slices": true— verify the new dashboard contains new chart objects (different chart IDs) with the same layout.pytest tests/unit_tests/mcp_service/dashboard/tool/test_duplicate_dashboard.pyADDITIONAL INFORMATION