Skip to content

feat(mcp): add create_report tool for scheduling reports and alerts#40359

Draft
aminghadersohi wants to merge 2 commits into
apache:masterfrom
aminghadersohi:amin/mcp-create-report
Draft

feat(mcp): add create_report tool for scheduling reports and alerts#40359
aminghadersohi wants to merge 2 commits into
apache:masterfrom
aminghadersohi:amin/mcp-create-report

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds the create_report MCP mutation tool that allows AI assistants to create scheduled report and alert definitions in Superset via the Model Context Protocol.

New files:

  • superset/mcp_service/report/__init__.py — module init
  • superset/mcp_service/report/schemas.py — Pydantic schemas: RecipientConfig, CreateReportRequest, CreateReportResponse
  • superset/mcp_service/report/tool/__init__.py — tool export
  • superset/mcp_service/report/tool/create_report.py — tool implementation

Tool behavior:

  • Wraps CreateReportScheduleCommand (same command as the REST POST /api/v1/report/ endpoint)
  • Uses ALERTS_REPORTS creation method so callers can specify arbitrary recipients
  • Accepts dashboard_id or chart_id for attaching a visualization, plus database_id + sql for alert conditions
  • Supports Email, Slack, SlackV2, and Webhook recipient types
  • Returns structured response with id, schedule metadata, a management URL, and an error field on failure
  • Tagged mutate with readOnlyHint=False; permission-checked against ReportSchedule/write

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend-only MCP tool, no UI changes.

TESTING INSTRUCTIONS

  1. Start the MCP server with a valid Superset instance
  2. Call create_report via an MCP client with:
    {
      "name": "Weekly Dashboard Report",
      "type": "Report",
      "crontab": "0 9 * * 1",
      "dashboard_id": 1,
      "recipients": [{"type": "Email", "target": "user@example.com"}]
    }
  3. Verify the response includes a non-null id and a url
  4. Check the Superset admin UI under Alerts & Reports — the new schedule should appear

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

Adds the `create_report` MCP mutation tool that wraps
`CreateReportScheduleCommand`, allowing AI assistants to schedule
dashboard/chart email reports and SQL-condition alerts via the MCP
protocol.
- Move recipient_type_map outside the loop (MEDIUM)
- Add inline import comment explaining circular-import deferral (NIT)
- Simplify report_url to /report/list/ (NIT)
- Add unit tests: schema validation, happy path, validation error,
  create failed error, alert type with property inspection
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 55.78947% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.59%. Comparing base (5966bb1) to head (1c7d1ae).

Files with missing lines Patch % Lines
superset/mcp_service/report/tool/create_report.py 25.00% 27 Missing ⚠️
superset/mcp_service/report/schemas.py 73.21% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40359      +/-   ##
==========================================
- Coverage   64.20%   63.59%   -0.61%     
==========================================
  Files        2592     2595       +3     
  Lines      139004   139099      +95     
  Branches    32273    32278       +5     
==========================================
- Hits        89241    88461     -780     
- Misses      48231    49106     +875     
  Partials     1532     1532              
Flag Coverage Δ
hive 39.32% <55.78%> (+0.02%) ⬆️
mysql 58.81% <55.78%> (-0.01%) ⬇️
postgres 58.89% <55.78%> (-0.01%) ⬇️
presto 40.99% <55.78%> (+0.02%) ⬆️
python 59.13% <55.78%> (-1.33%) ⬇️
sqlite 58.53% <55.78%> (-0.01%) ⬇️
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new MCP mutation tool, create_report, enabling MCP clients (AI assistants) to create Superset Alerts & Reports schedules by invoking the existing CreateReportScheduleCommand (the same command used by the REST API).

Changes:

  • Introduces superset.mcp_service.report.tool.create_report MCP tool (tagged mutate, readOnlyHint=False) with RBAC enforcement via ReportSchedule/write.
  • Adds Pydantic request/response schemas for the tool under superset/mcp_service/report/schemas.py.
  • Adds unit tests covering schema validation and several tool execution paths.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
superset/mcp_service/app.py Registers the new MCP tool by importing it into the MCP app initialization module.
superset/mcp_service/report/__init__.py Adds the new report MCP service package.
superset/mcp_service/report/schemas.py Defines Pydantic schemas for create_report request/response and recipient config.
superset/mcp_service/report/tool/__init__.py Exposes the create_report tool for import/registration.
superset/mcp_service/report/tool/create_report.py Implements the MCP tool wrapping CreateReportScheduleCommand and returning a management URL/error payload.
tests/unit_tests/mcp_service/report/__init__.py Adds the unit test package for report MCP service.
tests/unit_tests/mcp_service/report/tool/__init__.py Adds the unit test package for report MCP tools.
tests/unit_tests/mcp_service/report/tool/test_create_report.py Adds schema and tool-invocation tests for create_report.

Comment on lines +28 to +46
@pytest.fixture
def mcp_server():
return mcp


def _make_mock_schedule(
id: int = 1,
name: str = "Weekly Report",
schedule_type: str = "Report",
crontab: str = "0 9 * * 1",
active: bool = True,
) -> MagicMock:
schedule = MagicMock()
schedule.id = id
schedule.name = name
schedule.type = schedule_type
schedule.crontab = crontab
schedule.active = active
return schedule
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.

2 participants