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

   ## SUMMARY
   
   This PR completes Phase 4 of the MCP service implementation by adding 
dashboard generation and chart placement capabilities. AI agents can now create 
new dashboards with charts arranged in grid layouts and add charts to existing 
dashboards with automatic positioning.
   
   **New Dashboard Tools Added (2 tools):**
   - **generate_dashboard**: Creates new dashboards with specified charts in 
row/column grid layout
   - **add_chart_to_existing_dashboard**: Adds charts to existing dashboards 
with automatic positioning
   
   **All Dashboard Tools Now Available (4 total):**
   1. list_dashboards (existing from PR3)
   2. get_dashboard_info (existing from PR3)
   3. generate_dashboard (NEW)
   4. add_chart_to_existing_dashboard (NEW)
   
   **Infrastructure Added:**
   
   - **Dashboard schemas** (342 → 397 lines, +55):
     - Added 4 new schema classes:
       - `GenerateDashboardRequest` - Request schema for creating dashboards
       - `GenerateDashboardResponse` - Response with dashboard ID and URL
       - `AddChartToDashboardRequest` - Request schema for adding charts
       - `AddChartToDashboardResponse` - Response with updated dashboard info
   
   - **Dashboard layout logic**:
     - Automatic grid layout generation (2-column alternating pattern)
     - Chart positioning with configurable row/column placement
     - Layout component management (headers, tabs, charts)
     - Duplicate chart detection and prevention
   
   **Statistics:**
   - **Files Changed**: 5 (3 new, 2 modified)
   - **Lines Added**: ~1,100
     - Tool files: 518 lines
     - Schema additions: 55 lines
     - Test coverage: 450 lines
   - **Tests Added**: 11 new tests (all passing)
     - `test_generate_dashboard_basic`
     - `test_generate_dashboard_missing_charts`
     - `test_generate_dashboard_single_chart`
     - `test_generate_dashboard_many_charts`
     - `test_generate_dashboard_creation_failure`
     - `test_generate_dashboard_minimal_request`
     - `test_add_chart_to_dashboard_basic`
     - `test_add_chart_dashboard_not_found`
     - `test_add_chart_chart_not_found`
     - `test_add_chart_already_in_dashboard`
     - `test_add_chart_empty_dashboard`
   - **All pre-commit hooks passing**
   
   **Builds on:**
   - PR #35163 (MCP service scaffold)
   - PR2 (chart listing and info tools)
   - PR3 (dashboard and dataset listing and info tools)
   - PR4 (advanced chart tools and SQL Lab integration)
   
   ## BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A - This is a backend API enhancement for the MCP service.
   
   ## TESTING INSTRUCTIONS
   
   ### Prerequisites
   1. Ensure you have a running Superset instance with the MCP service enabled
   2. Ensure you have the development environment set up (Python venv activated)
   3. Have at least 2 charts created in your Superset instance for testing
   
   ### Running Unit Tests
   
   ```bash
   # Clear Python cache
   find superset/mcp_service -type d -name __pycache__ -exec rm -rf {} + 
2>/dev/null || true
   find superset/mcp_service -name "*.pyc" -delete 2>/dev/null || true
   
   # Run dashboard generation tests
   pytest 
tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py -v
   
   # Expected: 11 tests passing
   # - TestGenerateDashboard: 6 tests
   # - TestAddChartToExistingDashboard: 5 tests
   ```
   
   ### Pre-Commit Validation
   
   ```bash
   # Stage all files
   git add -A
   
   # Run pre-commit hooks
   pre-commit run --files superset/mcp_service/dashboard/**/*.py 
tests/unit_tests/mcp_service/dashboard/**/*.py
   
   # Expected: All hooks pass (mypy, ruff, pylint, etc.)
   ```
   
   ### Manual Testing (Optional)
   
   If you have an MCP client configured, you can test the new tools:
   
   ```python
   # Generate a new dashboard with charts
   from superset.mcp_service.dashboard.tool.generate_dashboard import 
generate_dashboard
   
   # Add a chart to an existing dashboard
   from superset.mcp_service.dashboard.tool.add_chart_to_existing_dashboard 
import (
       add_chart_to_existing_dashboard
   )
   ```
   
   ## ADDITIONAL INFORMATION
   
   - [ ] Has associated issue: No
   - [ ] Required feature flags: No
   - [ ] Changes UI: No
   - [ ] Includes DB Migration: No
   - [x] Introduces new feature or API: Yes (2 new tools)
   - [ ] Removes existing feature or API: No
   
   **Completes Phase 4 of MCP Implementation:**
   
   Phase 4 focused on dashboard management capabilities, allowing AI agents to:
   1. Create dashboards from scratch with specified charts
   2. Add charts to existing dashboards dynamically
   3. Manage dashboard layouts automatically
   
   **Files Changed Summary:**
   
   **Dashboard Tool Files (2 new):**
   - superset/mcp_service/dashboard/tool/generate_dashboard.py (236 lines)
   - superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py 
(282 lines)
   
   **Updated Files (2 modified):**
   - superset/mcp_service/dashboard/schemas.py (+55 lines, 4 new schemas)
   - superset/mcp_service/dashboard/tool/__init__.py (updated exports)
   
   **Test Files (1 new):**
   - tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py 
(450 lines, 11 tests)
   
   **Key Features:**
   
   1. **generate_dashboard**:
      - Creates dashboards with multiple charts
      - Automatic 2-column grid layout
      - Configurable dashboard title and metadata
      - Returns dashboard ID and URL for access
   
   2. **add_chart_to_existing_dashboard**:
      - Adds charts to existing dashboards
      - Automatic positioning in next available slot
      - Duplicate detection (prevents adding same chart twice)
      - Updates dashboard layout structure
      - Works with empty or populated dashboards
   
   **Pattern Compliance:**
   
   This PR follows the **MINIMAL cherry-pick pattern** established in previous 
PRs:
   - ✅ Copied ONLY the tool files and required schemas
   - ✅ NO prompts, resources, or extra utilities copied
   - ✅ Updated exports in `__init__.py`
   - ✅ Included corresponding test files
   - ✅ All pre-commit hooks passing
   - ✅ All tests passing (11/11)
   
   **Next Steps (Phase 5):**
   
   Future enhancements may include:
   - Advanced dashboard layout options (3-column, custom grids)
   - Dashboard template system
   - Dashboard filter configuration
   - Prompt testing framework for LLM tool usage validation
   


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