feat(mcp): add create_report tool for scheduling reports and alerts#40359
Draft
aminghadersohi wants to merge 2 commits into
Draft
feat(mcp): add create_report tool for scheduling reports and alerts#40359aminghadersohi wants to merge 2 commits into
aminghadersohi wants to merge 2 commits into
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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_reportMCP tool (taggedmutate,readOnlyHint=False) with RBAC enforcement viaReportSchedule/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Adds the
create_reportMCP 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 initsuperset/mcp_service/report/schemas.py— Pydantic schemas:RecipientConfig,CreateReportRequest,CreateReportResponsesuperset/mcp_service/report/tool/__init__.py— tool exportsuperset/mcp_service/report/tool/create_report.py— tool implementationTool behavior:
CreateReportScheduleCommand(same command as the RESTPOST /api/v1/report/endpoint)ALERTS_REPORTScreation method so callers can specify arbitrary recipientsdashboard_idorchart_idfor attaching a visualization, plusdatabase_id+sqlfor alert conditionsid, schedule metadata, a management URL, and anerrorfield on failuremutatewithreadOnlyHint=False; permission-checked againstReportSchedule/writeBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only MCP tool, no UI changes.
TESTING INSTRUCTIONS
create_reportvia an MCP client with:{ "name": "Weekly Dashboard Report", "type": "Report", "crontab": "0 9 * * 1", "dashboard_id": 1, "recipients": [{"type": "Email", "target": "user@example.com"}] }idand aurlADDITIONAL INFORMATION