Skip to content

feat(mcp): add create_saved_query MCP tool#40361

Draft
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:amin/mcp-create-saved-query
Draft

feat(mcp): add create_saved_query MCP tool#40361
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:amin/mcp-create-saved-query

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds a create_saved_query mutation tool to the MCP service so AI assistants can persist SQL queries to the Saved Queries list.

New files:

  • superset/commands/query/create.pyCreateSavedQueryCommand validates database access (existence + security) and creates the record via SavedQueryDAO
  • superset/commands/query/exceptions.py — adds SavedQueryCreateFailedError
  • superset/mcp_service/saved_query/ — new module with Pydantic request/response schemas and the @tool-decorated create_saved_query function
  • superset/mcp_service/app.py — registers the tool and updates LLM instructions

Tool signature:

create_saved_query(label, sql, db_id, schema?, description?, template_parameters?)
→ { id, label, sql, db_id, schema, description, url, error? }

Follows the same mutation pattern as create_virtual_dataset.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend MCP tool only.

TESTING INSTRUCTIONS

  1. Start the MCP server with a running Superset instance
  2. Connect an MCP client (e.g., Claude Desktop)
  3. Call create_saved_query with a valid db_id, label, and sql
  4. Verify the saved query appears in /savedqueryview/list/ and can be opened in SQL Lab via the returned URL
  5. Call with an invalid db_id and verify a structured error is returned (no exception thrown to the client)

ADDITIONAL INFORMATION

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

Adds a `create_saved_query` mutation tool to the MCP service so AI
assistants can persist SQL queries to the Saved Queries list.

- `superset/commands/query/create.py`: new `CreateSavedQueryCommand`
  that validates database access then creates the record via DAO
- `superset/commands/query/exceptions.py`: adds
  `SavedQueryCreateFailedError`
- `superset/mcp_service/saved_query/`: new module with Pydantic schemas
  and the `@tool`-decorated `create_saved_query` function
- `superset/mcp_service/app.py`: registers the tool and updates the
  LLM instructions

Shortcut: #107311
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 35.51402% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.17%. Comparing base (5966bb1) to head (c5fa96c).

Files with missing lines Patch % Lines
superset/commands/query/create.py 0.00% 35 Missing ⚠️
...mcp_service/saved_query/tool/create_saved_query.py 24.32% 28 Missing ⚠️
superset/mcp_service/saved_query/schemas.py 80.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40361      +/-   ##
==========================================
- Coverage   64.20%   64.17%   -0.03%     
==========================================
  Files        2592     2596       +4     
  Lines      139004   139111     +107     
  Branches    32273    32281       +8     
==========================================
+ Hits        89241    89279      +38     
- Misses      48231    48300      +69     
  Partials     1532     1532              
Flag Coverage Δ
hive 39.29% <35.51%> (-0.01%) ⬇️
mysql 58.77% <35.51%> (-0.04%) ⬇️
postgres 58.85% <35.51%> (-0.04%) ⬇️
presto 40.96% <35.51%> (-0.01%) ⬇️
python 60.41% <35.51%> (-0.05%) ⬇️
sqlite 58.49% <35.51%> (-0.04%) ⬇️
unit 100.00% <ø> (ø)

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.

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.

1 participant