Skip to content

fix(mcp): improve not-found errors to suggest corresponding list_* tools#39919

Open
aminghadersohi wants to merge 1 commit intoapache:masterfrom
aminghadersohi:fix/mcp-execute-sql-suggest-list-databases
Open

fix(mcp): improve not-found errors to suggest corresponding list_* tools#39919
aminghadersohi wants to merge 1 commit intoapache:masterfrom
aminghadersohi:fix/mcp-execute-sql-suggest-list-databases

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

When MCP tools return "not found" errors for invalid resource IDs (database, chart, dataset, dashboard), the LLM has no signal to recover. This change adds actionable recovery guidance to all "not found" error messages in MCP tools.

Before:

Database with ID -1 not found

After:

Database with ID -1 not found. Use list_databases to get valid database IDs.

Affected tools:

  • execute_sql — database not found → suggest list_databases
  • open_sql_lab_with_context — database not found → suggest list_databases
  • query_dataset — dataset not found → suggest list_datasets
  • get_chart_data — chart not found → suggest list_charts
  • get_chart_preview — chart not found → suggest list_charts
  • update_chart — chart not found → suggest list_charts
  • add_chart_to_existing_dashboard — dashboard/chart not found → suggest list_dashboards/list_charts
  • generate_dashboard — charts not found → suggest list_charts

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — error message text change only.

TESTING INSTRUCTIONS

  1. Call execute_sql with an invalid database_id (e.g., -1)
  2. Verify the error message now includes Use list_databases to get valid database IDs.
  3. Repeat for other tools with invalid IDs

Unit tests updated in tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

…tools

When MCP tools return "not found" errors for database, chart, dataset, or
dashboard IDs, include recovery guidance pointing to the appropriate list
tool (list_databases, list_charts, list_datasets, list_dashboards).

Affected tools: execute_sql, open_sql_lab_with_context, query_dataset,
get_chart_data, get_chart_preview, update_chart,
add_chart_to_existing_dashboard, generate_dashboard
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.88%. Comparing base (5b5dd01) to head (c78658d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #39919   +/-   ##
=======================================
  Coverage   63.88%   63.88%           
=======================================
  Files        2583     2583           
  Lines      136604   136604           
  Branches    31502    31502           
=======================================
  Hits        87276    87276           
  Misses      47812    47812           
  Partials     1516     1516           
Flag Coverage Δ
hive 39.38% <ø> (ø)
mysql 59.06% <ø> (ø)
postgres 59.13% <ø> (ø)
presto 41.08% <ø> (ø)
python 60.57% <ø> (ø)
sqlite 58.77% <ø> (ø)
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 marked this pull request as ready for review May 7, 2026 03:40
@dosubot dosubot Bot added the change:backend Requires changing the backend label May 7, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 7, 2026

Code Review Agent Run #e03ef2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 9 · Commit Range: c78658d..c78658d
    • superset/mcp_service/chart/tool/get_chart_data.py
    • superset/mcp_service/chart/tool/get_chart_preview.py
    • superset/mcp_service/chart/tool/update_chart.py
    • superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py
    • superset/mcp_service/dashboard/tool/generate_dashboard.py
    • superset/mcp_service/dataset/tool/query_dataset.py
    • superset/mcp_service/sql_lab/tool/execute_sql.py
    • superset/mcp_service/sql_lab/tool/open_sql_lab_with_context.py
    • tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.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

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

Labels

change:backend Requires changing the backend size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant