Skip to content

feat(mcp): add list and get tools for saved queries and query history#40301

Closed
aminghadersohi wants to merge 2 commits into
masterfrom
mcp-queries-99978
Closed

feat(mcp): add list and get tools for saved queries and query history#40301
aminghadersohi wants to merge 2 commits into
masterfrom
mcp-queries-99978

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds four new MCP tools across two new domains (saved_query/ and query/):

  • list_saved_queries — List saved SQL queries owned by the current user with filtering (label, db_id, schema), search, and pagination
  • get_saved_query_info — Get saved query details by numeric ID or UUID
  • list_queries — List SQL query history with filtering (status, database_id, schema), defaulting to most-recent-first (ordered by start_time desc, page_size 25)
  • get_query_info — Get query history details by numeric ID

Both domains follow the existing database/, dataset/, chart/, and dashboard/ patterns: ModelListCore/ModelGetInfoCore for reuse, Pydantic schemas with field-level serialization context, @tool decorators with RBAC, and event_logger instrumentation.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend API tools only

TESTING INSTRUCTIONS

# Run unit tests for the new tools
pytest tests/unit_tests/mcp_service/saved_query/
pytest tests/unit_tests/mcp_service/query/

ADDITIONAL INFORMATION

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 67.22408% with 98 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.84%. Comparing base (f09fd63) to head (2f738a3).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/query/tool/list_queries.py 33.33% 20 Missing ⚠️
...mcp_service/saved_query/tool/list_saved_queries.py 33.33% 20 Missing ⚠️
superset/mcp_service/query/schemas.py 83.15% 15 Missing and 1 partial ⚠️
superset/mcp_service/saved_query/schemas.py 82.02% 15 Missing and 1 partial ⚠️
superset/mcp_service/query/tool/get_query_info.py 43.47% 13 Missing ⚠️
...p_service/saved_query/tool/get_saved_query_info.py 43.47% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40301      +/-   ##
==========================================
- Coverage   64.15%   63.84%   -0.32%     
==========================================
  Files        2592     2600       +8     
  Lines      138861   140228    +1367     
  Branches    32208    32494     +286     
==========================================
+ Hits        89085    89523     +438     
- Misses      48244    49140     +896     
- Partials     1532     1565      +33     
Flag Coverage Δ
hive 39.18% <67.22%> (-0.15%) ⬇️
mysql 58.29% <67.22%> (-0.57%) ⬇️
postgres 58.37% <67.22%> (-0.57%) ⬇️
presto 40.82% <67.22%> (-0.18%) ⬇️
python 59.90% <67.22%> (-0.60%) ⬇️
sqlite 58.02% <67.22%> (-0.56%) ⬇️
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.

@aminghadersohi aminghadersohi force-pushed the mcp-queries-99978 branch 6 times, most recently from f7cb7ab to 4c646e9 Compare May 21, 2026 19:19
aminghadersohi and others added 2 commits May 21, 2026 20:44
Implements list_saved_queries, get_saved_query_info, list_queries, and
get_query_info MCP tools in new saved_query/ and query/ domains.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aminghadersohi aminghadersohi marked this pull request as ready for review May 22, 2026 02:15
@dosubot dosubot Bot added the api Related to the REST API label May 22, 2026
@aminghadersohi aminghadersohi requested a review from geido May 22, 2026 02:17
@aminghadersohi
Copy link
Copy Markdown
Contributor Author

Closing in favor of #40346 (branch renamed to follow amin/feature-description convention).

Copy link
Copy Markdown
Contributor

@bito-code-review bito-code-review Bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #a1ef76

Actionable Suggestions - 1
  • superset/mcp_service/saved_query/tool/list_saved_queries.py - 1
Additional Suggestions - 2
  • superset/mcp_service/saved_query/tool/list_saved_queries.py - 2
    • Docstring may mislead users · Line 62-68
      The docstring states 'Returns saved queries owned by the current user' which implies default ownership filtering, but this is only true when ownership filters are explicitly applied. The docstring should clarify the default behavior.
      Code suggestion
      --- superset/mcp_service/saved_query/tool/list_saved_queries.py (lines 62-68) ---
       62:     """List saved SQL queries with filtering and search.
       63: 
       64:     Returns saved queries accessible to the current user, including label, SQL,
       65:     database ID, and schema. Use created_by_me or owned_by_me filters to
       66:     return only queries created by or owned by the current user.
       67: 
       68:     Sortable columns for order_column: id, label, db_id, schema,
       69:     changed_on, created_on
       70:     """
    • Unused parameter in serializer · Line 97-100
      The `_serialize_saved_query` function signature includes an unused `cols` parameter; consider either using it for field filtering or removing it and updating its caller accordingly.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/unit_tests/mcp_service/saved_query/tool/test_saved_query_tools.py - 2
  • superset/mcp_service/query/tool/get_query_info.py - 1
Review Details
  • Files reviewed - 17 · Commit Range: 5de1fb7..2f738a3
    • superset/mcp_service/app.py
    • superset/mcp_service/query/__init__.py
    • superset/mcp_service/query/schemas.py
    • superset/mcp_service/query/tool/__init__.py
    • superset/mcp_service/query/tool/get_query_info.py
    • superset/mcp_service/query/tool/list_queries.py
    • superset/mcp_service/saved_query/__init__.py
    • superset/mcp_service/saved_query/schemas.py
    • superset/mcp_service/saved_query/tool/__init__.py
    • superset/mcp_service/saved_query/tool/get_saved_query_info.py
    • superset/mcp_service/saved_query/tool/list_saved_queries.py
    • tests/unit_tests/mcp_service/query/__init__.py
    • tests/unit_tests/mcp_service/query/tool/__init__.py
    • tests/unit_tests/mcp_service/query/tool/test_query_tools.py
    • tests/unit_tests/mcp_service/saved_query/__init__.py
    • tests/unit_tests/mcp_service/saved_query/tool/__init__.py
    • tests/unit_tests/mcp_service/saved_query/tool/test_saved_query_tools.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +117 to +125
result = list_tool.run_tool(
filters=request.filters,
search=request.search,
select_columns=request.select_columns,
order_column=request.order_column,
order_direction=request.order_direction,
page=max(request.page - 1, 0),
page_size=request.page_size,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing ownership filter params

Add created_by_me and owned_by_me parameters to the list_tool.run_tool() call and extend the ListSavedQueriesRequest schema to support these flags, enabling ownership-based filtering.

Code Review Run #a1ef76


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant