aminghadersohi opened a new pull request, #38411:
URL: https://github.com/apache/superset/pull/38411
### SUMMARY
Adds a new MCP tool `save_sql_query` that saves a SQL query as a named saved
query,
making it available in the Saved Queries list and directly openable in SQL
Lab via a URL.
This enables the workflow:
1. `execute_sql(database_id, sql)` — run and verify the query
2. `save_sql_query(database_id, sql, label)` — persist it with a name
**Features:**
- Validates database exists and user has access before saving
- Creates a `SavedQuery` record with label, description, schema, catalog,
and template parameters
- Returns saved query ID and SQL Lab URL (`/sqllab?savedQueryId=N`)
- Follows existing MCP tool patterns (`@tool`, `@parse_request`, event
logging)
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only MCP tool, no UI modifications.
### TESTING INSTRUCTIONS
1. Run the unit tests:
```bash
pytest tests/unit_tests/mcp_service/sql_lab/tool/test_save_sql_query.py -v
```
2. Verify all 7 tests pass covering:
- Valid request creation with required fields only
- Request with all optional fields (description, schema, catalog,
template_parameters)
- Empty SQL rejection
- Empty label rejection
- SQL whitespace stripping
- Response structure validation
- Error response structure
3. To test via MCP (if connected):
```
Use save_sql_query tool with database_id, sql, and label parameters
```
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]