Skip to content

feat(mcp): add database connection listing and info tools#39111

Merged
aminghadersohi merged 7 commits intomasterfrom
mcp-database-tools
Apr 6, 2026
Merged

feat(mcp): add database connection listing and info tools#39111
aminghadersohi merged 7 commits intomasterfrom
mcp-database-tools

Conversation

@mistercrunch
Copy link
Copy Markdown
Member

SUMMARY

Add MCP tools for listing and getting database connection details, filling a gap where databases were the only core Superset resource without MCP tool coverage.

New tools:

  • list_databases — List database connections with filtering, search, and pagination (tag: core)
  • get_database_info — Get detailed database connection metadata by ID (tag: discovery)

Schema discovery integration:

  • Registers "database" as a model type in get_schema, so LLM clients can discover available columns, filters, and sort options

Follows existing patterns exactly — modeled after the dataset tool domain (ModelListCore, ModelGetInfoCore, Pydantic schemas, MetadataCacheControl, event logging).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend-only MCP tool additions, no UI changes.

TESTING INSTRUCTIONS

  1. Start Superset with MCP enabled
  2. Connect an MCP client and call list_databases — should return paginated database connections
  3. Call get_database_info with a known database ID — should return full connection metadata
  4. Call get_schema(model_type="database") — should return column/filter/sort metadata
  5. Run unit tests: pytest tests/unit_tests/mcp_service/database/

ADDITIONAL INFORMATION

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

Add MCP tools for listing and getting database connection details,
filling a gap where databases were the only core Superset resource
without MCP tool coverage.

New tools:
- list_databases: List database connections with filtering/pagination
- get_database_info: Get detailed database connection metadata by ID

Also registers "database" as a model type in get_schema for
column/filter discovery.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 59.81308% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.53%. Comparing base (d796543) to head (431d14e).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/database/schemas.py 71.54% 35 Missing ⚠️
...perset/mcp_service/database/tool/list_databases.py 33.33% 20 Missing ⚠️
...set/mcp_service/database/tool/get_database_info.py 41.66% 14 Missing ⚠️
superset/mcp_service/mcp_core.py 9.09% 10 Missing ⚠️
superset/mcp_service/common/schema_discovery.py 71.42% 4 Missing ⚠️
superset/mcp_service/system/tool/get_schema.py 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #39111      +/-   ##
==========================================
+ Coverage   64.52%   64.53%   +0.01%     
==========================================
  Files        2536     2540       +4     
  Lines      131208   131413     +205     
  Branches    30457    30467      +10     
==========================================
+ Hits        84661    84811     +150     
- Misses      45084    45139      +55     
  Partials     1463     1463              
Flag Coverage Δ
hive 40.15% <59.81%> (+0.11%) ⬆️
mysql 60.91% <59.81%> (+0.04%) ⬆️
postgres 61.00% <59.81%> (+0.04%) ⬆️
presto 40.17% <59.81%> (+0.11%) ⬆️
python 62.58% <59.81%> (+0.03%) ⬆️
sqlite 60.62% <59.81%> (+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.

mistercrunch and others added 2 commits April 4, 2026 19:01
Move the repeated Literal["chart", "dataset", "dashboard", "database"]
type alias to a shared ModelType in constants.py, replacing 4 inline
occurrences across schema_discovery.py, mcp_core.py, and get_schema.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove `backend` from DatabaseFilter (it's a @Property, not a SQL
  column, so DAO filtering would fail at query time)
- Add UUID support to GetDatabaseInfoRequest (identifier: int | str)
  and expose uuid field on DatabaseInfo — Database inherits UUIDMixin
  via ImportExportMixin
- Exclude sensitive columns (sqlalchemy_uri, password, encrypted_extra,
  server_cert) from schema discovery via new exclude_columns parameter
  on get_columns_from_model()
- Update get_database_info docstring with UUID examples

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mistercrunch mistercrunch marked this pull request as ready for review April 4, 2026 19:21
@dosubot dosubot Bot added api Related to the REST API data:connect Namespace | Anything related to db connections / integrations labels Apr 4, 2026
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 #ef0696

Actionable Suggestions - 2
  • superset/mcp_service/database/schemas.py - 2
Additional Suggestions - 2
  • tests/unit_tests/mcp_service/database/tool/test_database_tools.py - 1
    • Missing Type Hints · Line 34-34
      Add explicit type hints to parameters and return type for create_mock_database to comply with type safety requirements for new Python code.
      Code suggestion
       @@ -34,11 +34,11 @@
      -def create_mock_database(
      -    database_id=1,
      -    database_name="examples",
      -    backend="postgresql",
      -    expose_in_sqllab=True,
      -    allow_ctas=False,
      -    allow_cvas=False,
      -    allow_dml=False,
      -    allow_file_upload=False,
      -    allow_run_async=False,
      -):
      +def create_mock_database(
      +    database_id: int = 1,
      +    database_name: str = "examples",
      +    backend: str = "postgresql",
      +    expose_in_sqllab: bool = True,
      +    allow_ctas: bool = False,
      +    allow_cvas: bool = False,
      +    allow_dml: bool = False,
      +    allow_file_upload: bool = False,
      +    allow_run_async: bool = False,
      +) -> MagicMock:
  • superset/mcp_service/mcp_core.py - 1
    • Update model_type docstring · Line 525-525
      The type annotation for model_type has been changed from Literal["chart", "dataset", "dashboard"] to ModelType, which includes "database" as well. The docstring at line 540 should be updated accordingly to maintain consistency.
Review Details
  • Files reviewed - 13 · Commit Range: bbc6abf..81c4b12
    • superset/mcp_service/app.py
    • superset/mcp_service/common/schema_discovery.py
    • superset/mcp_service/constants.py
    • superset/mcp_service/database/__init__.py
    • superset/mcp_service/database/schemas.py
    • superset/mcp_service/database/tool/__init__.py
    • superset/mcp_service/database/tool/get_database_info.py
    • superset/mcp_service/database/tool/list_databases.py
    • superset/mcp_service/mcp_core.py
    • superset/mcp_service/system/tool/get_schema.py
    • tests/unit_tests/mcp_service/database/__init__.py
    • tests/unit_tests/mcp_service/database/tool/__init__.py
    • tests/unit_tests/mcp_service/database/tool/test_database_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 thread superset/mcp_service/database/schemas.py Outdated
Comment thread superset/mcp_service/database/schemas.py Outdated
… defaults for database tools

- Add created_by_fk and changed_by_fk to DatabaseFilter columns so users
  can filter databases by creator (matching chart/dashboard patterns)
- Add field_validator for filters and select_columns to handle JSON string
  parsing from MCP clients (double-serialization bug workaround)
- Remove duplicate DEFAULT_DATABASE_COLUMNS from list_databases.py, import
  from schema_discovery.py instead
- Update app.py instructions to document database created_by_fk workflow
- Fix datetime.now() without timezone in DatabaseError.create() and
  _humanize_timestamp() — use timezone-aware datetimes consistently
- Add type hints to create_mock_database() test helper
- Update mcp_core.py ModelGetSchemaCore docstring to include "database"
  in the model_type description
@github-actions github-actions Bot removed the api Related to the REST API label Apr 4, 2026
Comment thread superset/mcp_service/app.py Outdated
Comment thread superset/mcp_service/database/tool/list_databases.py
Comment thread superset/mcp_service/database/tool/get_database_info.py
Comment thread superset/mcp_service/database/schemas.py
Comment thread tests/unit_tests/mcp_service/database/tool/test_database_tools.py Outdated
Comment thread superset/mcp_service/system/tool/get_schema.py
Comment thread superset/mcp_service/common/schema_discovery.py
- Fix misleading "permissions" in app.py and get_database_info docstring
  — replaced with "capabilities" to match actual response fields
- Add changed_on to DATABASE_DEFAULT_COLUMNS so humanized timestamps
  can be computed reliably (matching chart/dataset pattern)
- Fix not-found test to use result.data["error_type"] instead of
  result.content (matching existing dataset/dashboard test patterns)
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Apr 5, 2026

Code Review Agent Run #301849

Actionable Suggestions - 0
Review Details
  • Files reviewed - 7 · Commit Range: 81c4b12..5e3309b
    • superset/mcp_service/app.py
    • superset/mcp_service/database/schemas.py
    • superset/mcp_service/database/tool/list_databases.py
    • superset/mcp_service/mcp_core.py
    • tests/unit_tests/mcp_service/database/tool/test_database_tools.py
    • superset/mcp_service/common/schema_discovery.py
    • superset/mcp_service/database/tool/get_database_info.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

…ve filter columns

- Add _get_backend() helper that safely handles backend @Property access
  on row proxies from DAO list queries (property requires URI decryption
  which fails on column-only query results)
- Add exclude_filter_columns parameter to ModelGetSchemaCore to strip
  sensitive columns (sqlalchemy_uri, password, encrypted_extra, server_cert)
  from filter discovery responses
- Wire DATABASE_EXCLUDE_COLUMNS into database schema discovery
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Apr 5, 2026

Code Review Agent Run #94a163

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 5e3309b..431d14e
    • superset/mcp_service/database/schemas.py
    • superset/mcp_service/mcp_core.py
    • superset/mcp_service/system/tool/get_schema.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

@aminghadersohi aminghadersohi merged commit a62be68 into master Apr 6, 2026
65 checks passed
@aminghadersohi aminghadersohi deleted the mcp-database-tools branch April 6, 2026 15:34
michael-s-molina pushed a commit that referenced this pull request Apr 13, 2026
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Amin Ghadersohi <amin.ghadersohi@gmail.com>
(cherry picked from commit a62be68)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:connect Namespace | Anything related to db connections / integrations size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants