Skip to content

feat(mcp): add get_dashboard_datasets tool#40961

Merged
aminghadersohi merged 7 commits into
masterfrom
mcp-get-dashboard-datasets
Jun 30, 2026
Merged

feat(mcp): add get_dashboard_datasets tool#40961
aminghadersohi merged 7 commits into
masterfrom
mcp-get-dashboard-datasets

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

SUMMARY

Adds a new read-only MCP tool, get_dashboard_datasets, that lists all datasets used by a dashboard's charts — the prerequisite context an AI agent needs before configuring native filters on a dashboard (e.g. picking filter target columns and datasets).

Design notes:

  • Accepts a dashboard identifier as numeric ID, UUID, or slug (same resolution as get_dashboard_info, via ModelGetInfoCore with supports_slug=True).
  • Groups the dashboard's charts by datasource (mirroring Dashboard.datasets_trimmed_for_slices) using the DAO layer, but returns the full (capped) column and metric lists, since native-filter configuration regularly needs columns that no chart references.
  • Each dataset includes: id, uuid, table_name, schema, database (id + name + backend), columns (column_name, type, is_dttm, verbose_name), metrics (metric_name, expression, verbose_name), and the number of dashboard charts using it.
  • Respects data access: datasets the current user cannot access (per security_manager.can_access_datasource) are excluded from the response and only counted via inaccessible_dataset_count.
  • Keeps responses LLM-friendly: per-dataset caps (100 columns / 50 metrics) with columns_truncated/metrics_truncated flags and total counts, and all user-controlled strings are sanitized/escaped with the existing LLM-context helpers.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (no UI changes — MCP service tool)

TESTING INSTRUCTIONS

  • Unit tests: pytest tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_datasets.py
  • Manually: start the MCP service and call get_dashboard_datasets with {"identifier": <dashboard id|uuid|slug>}; verify the datasets, columns, metrics, and database info match the dashboard's charts, and that datasets outside the user's access are excluded.

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

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.35135% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.48%. Comparing base (bf88c62) to head (b2eaf18).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/dashboard/schemas.py 56.57% 33 Missing ⚠️
...p_service/dashboard/tool/get_dashboard_datasets.py 38.23% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40961      +/-   ##
==========================================
- Coverage   64.50%   64.48%   -0.02%     
==========================================
  Files        2666     2667       +1     
  Lines      146864   146973     +109     
  Branches    33910    33918       +8     
==========================================
+ Hits        94728    94779      +51     
- Misses      50421    50477      +56     
- Partials     1715     1717       +2     
Flag Coverage Δ
hive 39.16% <51.35%> (+0.01%) ⬆️
mysql 57.77% <51.35%> (-0.02%) ⬇️
postgres 57.84% <51.35%> (-0.02%) ⬇️
presto 40.72% <51.35%> (+0.01%) ⬆️
python 59.25% <51.35%> (-0.02%) ⬇️
sqlite 57.47% <51.35%> (-0.01%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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 June 12, 2026 19:05
@dosubot dosubot Bot added the dashboard Namespace | Anything related to the Dashboard label Jun 12, 2026
@aminghadersohi
aminghadersohi requested a review from eschutho June 12, 2026 19:09

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

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.

Code Review Agent Run #a262d1

Actionable Suggestions - 1
  • superset/mcp_service/dashboard/schemas.py - 1
Additional Suggestions - 1
  • superset/mcp_service/app.py - 1
    • Missing companion tool hint · Line 131-131
      The tool description mentions 'native filters' but doesn't indicate its companion relationship to `get_dashboard_info` for filter configuration, unlike `get_dashboard_layout` which explicitly states '(companion to get_dashboard_info...)'. For consistency, consider adding similar context to clarify the tool's role in the dashboard configuration workflow.
Review Details
  • Files reviewed - 5 · Commit Range: 21fa014..21fa014
    • superset/mcp_service/app.py
    • superset/mcp_service/dashboard/schemas.py
    • superset/mcp_service/dashboard/tool/__init__.py
    • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_datasets.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/dashboard/schemas.py
@aminghadersohi
aminghadersohi force-pushed the mcp-get-dashboard-datasets branch from 21fa014 to 226fba7 Compare June 26, 2026 14:41
Comment thread superset/mcp_service/dashboard/schemas.py
Comment thread superset/mcp_service/dashboard/schemas.py
Comment thread tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_datasets.py Outdated
Comment thread superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
Comment thread superset/mcp_service/dashboard/tool/get_dashboard_datasets.py Outdated
aminghadersohi added a commit that referenced this pull request Jun 26, 2026
…+ avoid N+1

Address CodeAnt review on #40961:
- Add @requires_data_model_metadata_access decorator and body gate so
  dashboard-only viewers without dataset metadata permission cannot read
  dataset columns/metrics/database via this tool (mirrors get_dataset_info).
- Eager-load each slice's dataset columns, metrics, and database to avoid
  N+1 queries when serializing dashboards with many datasets.
Comment thread superset/mcp_service/dashboard/schemas.py
Comment thread superset/mcp_service/dashboard/schemas.py
@bito-code-review

bito-code-review Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8ef41f

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py - 1
    • Inconsistent error timestamp format · Line 96-96
      Line 96 calls `DashboardError.create()` which uses naive `datetime.now()` per `schemas.py:136`, while line 152 constructs `DashboardError` directly with `datetime.now(timezone.utc)`. These produce inconsistent timestamp formats in the same function. Use the direct constructor with `datetime.now(timezone.utc)` for consistency.
      Code suggestion
      --- superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
      +++ superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
       @@ -93,9 +93,10 @@ async def get_dashboard_datasets(
            # calls so dashboard-only viewers can't read dataset/database metadata.
            if not user_can_view_data_model_metadata():
                await ctx.warning("Dashboard datasets lookup blocked by privacy controls")
      -        return DashboardError.create(
      -            error="You don't have permission to access dataset details for your role.",
      -            error_type=DATA_MODEL_METADATA_ERROR_TYPE,
      +        return DashboardError(
      +            error="You don't have permission to access dataset details for your role.",
      +            error_type=DATA_MODEL_METADATA_ERROR_TYPE,
      +            timestamp=datetime.now(timezone.utc),
                )
Review Details
  • Files reviewed - 5 · Commit Range: 226fba7..b5f2d71
    • superset/mcp_service/app.py
    • superset/mcp_service/dashboard/schemas.py
    • superset/mcp_service/dashboard/tool/__init__.py
    • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_datasets.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 added a commit that referenced this pull request Jun 29, 2026
…+ avoid N+1

Address CodeAnt review on #40961:
- Add @requires_data_model_metadata_access decorator and body gate so
  dashboard-only viewers without dataset metadata permission cannot read
  dataset columns/metrics/database via this tool (mirrors get_dataset_info).
- Eager-load each slice's dataset columns, metrics, and database to avoid
  N+1 queries when serializing dashboards with many datasets.
@aminghadersohi
aminghadersohi force-pushed the mcp-get-dashboard-datasets branch from b5f2d71 to 6b43384 Compare June 29, 2026 16:39
Comment thread superset/mcp_service/dashboard/schemas.py Outdated
Comment thread superset/mcp_service/dashboard/schemas.py Outdated
Comment thread superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
Comment thread superset/mcp_service/dashboard/schemas.py
aminghadersohi added a commit that referenced this pull request Jun 29, 2026
…+ avoid N+1

Address CodeAnt review on #40961:
- Add @requires_data_model_metadata_access decorator and body gate so
  dashboard-only viewers without dataset metadata permission cannot read
  dataset columns/metrics/database via this tool (mirrors get_dataset_info).
- Eager-load each slice's dataset columns, metrics, and database to avoid
  N+1 queries when serializing dashboards with many datasets.
@aminghadersohi
aminghadersohi force-pushed the mcp-get-dashboard-datasets branch from 6b43384 to 4f3d048 Compare June 29, 2026 17:52
@aminghadersohi

Copy link
Copy Markdown
Contributor Author

Already fixed in 4f3d048DashboardError.create() now uses datetime.now(timezone.utc), so both code paths use timezone-aware UTC timestamps consistently.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

chart_count groups on datasource_id only (mirrors datasets_trimmed_for_slices), theoretically over-countable across datasource types. Otherwise LGTM

@bito-code-review

bito-code-review Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #fa57cd

Actionable Suggestions - 0
Review Details
  • Files reviewed - 5 · Commit Range: dea3e82..4f3d048
    • superset/mcp_service/app.py
    • superset/mcp_service/dashboard/schemas.py
    • superset/mcp_service/dashboard/tool/__init__.py
    • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_datasets.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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 added a commit that referenced this pull request Jun 30, 2026
…+ avoid N+1

Address CodeAnt review on #40961:
- Add @requires_data_model_metadata_access decorator and body gate so
  dashboard-only viewers without dataset metadata permission cannot read
  dataset columns/metrics/database via this tool (mirrors get_dataset_info).
- Eager-load each slice's dataset columns, metrics, and database to avoid
  N+1 queries when serializing dashboards with many datasets.
@aminghadersohi
aminghadersohi force-pushed the mcp-get-dashboard-datasets branch from 4f3d048 to dad30f8 Compare June 30, 2026 19:30
Comment thread superset/mcp_service/dashboard/schemas.py
aminghadersohi and others added 4 commits June 30, 2026 21:10
…+ avoid N+1

Address CodeAnt review on #40961:
- Add @requires_data_model_metadata_access decorator and body gate so
  dashboard-only viewers without dataset metadata permission cannot read
  dataset columns/metrics/database via this tool (mirrors get_dataset_info).
- Eager-load each slice's dataset columns, metrics, and database to avoid
  N+1 queries when serializing dashboards with many datasets.
DashboardError.create() was producing naive timestamps via datetime.now(),
inconsistent with the direct constructor path which uses datetime.now(timezone.utc).
…counter

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tInfo

Add alias="schema" and ConfigDict(populate_by_name=True) to
DashboardDatasetSummary.schema_name, mirroring the identical pattern in
DatasetInfo (dataset/schemas.py:137,184). Without the alias, model_json_schema()
advertises "schema_name" while the model_serializer outputs "schema", creating
an API contract mismatch for strict JSON-schema clients and typed SDKs. With the
alias, both the advertised schema and runtime payload agree on "schema".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aminghadersohi
aminghadersohi force-pushed the mcp-get-dashboard-datasets branch from 2bd6bf5 to 648ebbb Compare June 30, 2026 21:25
aminghadersohi and others added 2 commits June 30, 2026 21:26
Group slices by the full datasource key (id, type) instead of id alone,
preventing chart_count over-counting across datasource types that share
the same numeric id.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aminghadersohi
aminghadersohi merged commit fd9c84b into master Jun 30, 2026
59 checks passed
@aminghadersohi
aminghadersohi deleted the mcp-get-dashboard-datasets branch June 30, 2026 22:27
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

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

Labels

dashboard Namespace | Anything related to the Dashboard size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants