Skip to content

feat(mcp): add semantic layer MCP tools (list_metrics, get_table, get_compatible_dimensions, get_compatible_metrics) - #41611

Merged
aminghadersohi merged 5 commits into
masterfrom
aminghadersohi/mcp-semantic-layer-tools
Jul 7, 2026
Merged

aminghadersohi merged 5 commits into
masterfrom
aminghadersohi/mcp-semantic-layer-tools

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

SUMMARY

Adds 4 new MCP tools that surface Superset's semantic layer to LLM clients, spanning both built-in SqlaTable datasets and external SemanticView implementations.

Primary workflow (as recommended in research spike):

  1. list_metrics → discover available metrics and their compatible dimensions inline
  2. get_table → query data using chosen metrics and dimensions

Tools added:

  • list_metrics — Unified metric discovery across built-in datasets and external semantic views. Returns MetricInfo objects with compatible_dimensions included per metric for progressive query building. Supports search by name/description, filtering by dataset_id or view_id, and pagination.

  • get_table — Query a data source (built-in or external) using metric and dimension names. Routes to ChartDataCommand (built-in SqlaTable) or the semantic view's query path (external) based on dataset_id vs view_id. Returns tabular results with column metadata and cache status.

  • get_compatible_dimensions — Returns dimensions valid to add to the current metric/dimension selection. For built-in datasets: all groupby-enabled columns. For external semantic views: delegates to SemanticView.get_compatible_dimensions().

  • get_compatible_metrics — Returns metrics valid to add given a dimension selection. For built-in datasets: all metrics (SQL GROUP BY has no metric-level constraints). For external: delegates to SemanticView.get_compatible_metrics().

Design decisions:

  • External semantic view calls degrade gracefully when the registry is empty (OSS default — logs a warning per view, continues)
  • All tools use dataset_id / view_id from list_metrics to avoid ambiguity when metric names collide across sources
  • Follows all existing patterns: @tool decorator with tags/class_permission_name/ToolAnnotations, Pydantic schemas, DAO-based lookups, event_logger, ctx logging, ASF license headers

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

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

TESTING INSTRUCTIONS

  1. Start the MCP server
  2. List metrics: list_metrics(request={"search": "revenue"})
  3. Pick a metric from the response, note its dataset_id (or view_id) and a compatible_dimensions entry
  4. Query: get_table(request={"dataset_id": <id>, "metrics": ["<metric>"], "dimensions": ["<dim>"], "row_limit": 10})
  5. For external semantic views (requires a registered SemanticView): use view_id in place of dataset_id
  6. Verify get_compatible_dimensions and get_compatible_metrics return valid subsets for a known view

ADDITIONAL INFORMATION

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

@codecov

codecov Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.92540% with 372 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.66%. Comparing base (1c3b070) to head (7e91cf2).
⚠️ Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
...erset/mcp_service/semantic_layer/tool/get_table.py 20.32% 145 Missing ⚠️
...et/mcp_service/semantic_layer/tool/list_metrics.py 19.04% 85 Missing ⚠️
...e/semantic_layer/tool/get_compatible_dimensions.py 18.96% 47 Missing ⚠️
...vice/semantic_layer/tool/get_compatible_metrics.py 18.96% 47 Missing ⚠️
superset/mcp_service/utils/response_utils.py 12.50% 21 Missing ⚠️
superset/mcp_service/utils/query_utils.py 10.52% 17 Missing ⚠️
superset/daos/semantic_layer.py 20.00% 8 Missing ⚠️
superset/mcp_service/dataset/tool/query_dataset.py 66.66% 1 Missing ⚠️
superset/mcp_service/semantic_layer/schemas.py 98.96% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41611      +/-   ##
==========================================
- Coverage   64.77%   64.66%   -0.12%     
==========================================
  Files        2689     2698       +9     
  Lines      148945   149752     +807     
  Branches    34369    34469     +100     
==========================================
+ Hits        96486    96834     +348     
- Misses      50693    51140     +447     
- Partials     1766     1778      +12     
Flag Coverage Δ
hive 39.16% <33.92%> (-0.04%) ⬇️
mysql 57.69% <33.92%> (-0.18%) ⬇️
postgres 57.75% <33.92%> (-0.19%) ⬇️
presto 40.68% <33.92%> (-0.06%) ⬇️
python 59.14% <33.92%> (-0.18%) ⬇️
sqlite 57.33% <33.92%> (-0.17%) ⬇️
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 requested a review from Copilot July 1, 2026 16:37
@aminghadersohi
aminghadersohi marked this pull request as ready for review July 1, 2026 16:37
@dosubot dosubot Bot added the api Related to the REST API label Jul 1, 2026

Copilot AI 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.

Pull request overview

Adds a new “semantic layer” MCP surface area to Superset’s MCP server, enabling LLM clients to discover metrics/dimensions and execute tabular queries against either built-in SqlaTable datasets or SemanticView-backed sources.

Changes:

  • Introduces 4 new MCP tools: list_metrics, get_table, get_compatible_dimensions, get_compatible_metrics.
  • Adds Pydantic schemas for semantic-layer tool request/response payloads.
  • Wires the new tools into the MCP app and updates default MCP instructions.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
superset/mcp_service/semantic_layer/tool/list_metrics.py New tool to enumerate metrics across datasets and semantic views, with inline compatible dimensions and pagination.
superset/mcp_service/semantic_layer/tool/get_table.py New tool to query a dataset/semantic view using metric + dimension names and return tabular results.
superset/mcp_service/semantic_layer/tool/get_compatible_dimensions.py New tool to list addable dimensions for a current selection (builtin + external).
superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py New tool to list addable metrics for a current selection (builtin + external).
superset/mcp_service/semantic_layer/tool/init.py Exposes semantic-layer tools for MCP registration/import.
superset/mcp_service/semantic_layer/schemas.py Adds semantic-layer Pydantic schemas (requests, responses, shared error model).
superset/mcp_service/semantic_layer/init.py Initializes semantic_layer package.
superset/mcp_service/app.py Registers/imports the semantic-layer tools and documents usage in default instructions.
.pre-commit-config.yaml Adds a full pre-commit configuration file (scope appears unrelated to the PR description).

@github-actions github-actions Bot removed the api Related to the REST API label Jul 1, 2026
@netlify

netlify Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit d2a5b56
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a4c782b3c0cde00081da235
😎 Deploy Preview https://deploy-preview-41611--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@aminghadersohi
aminghadersohi force-pushed the aminghadersohi/mcp-semantic-layer-tools branch from fa0e3b7 to d80343c Compare July 1, 2026 17:22
@aminghadersohi
aminghadersohi marked this pull request as draft July 1, 2026 17:47
@aminghadersohi
aminghadersohi marked this pull request as ready for review July 1, 2026 19:25
@dosubot dosubot Bot added the api Related to the REST API label Jul 1, 2026

@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 #18462e

Actionable Suggestions - 3
  • superset/mcp_service/semantic_layer/tool/get_table.py - 1
    • Function complexity exceeds thresholds · Line 93-93
  • superset/daos/semantic_layer.py - 1
  • superset/mcp_service/utils/query_utils.py - 1
    • Missing unit tests for validate_names · Line 23-40
Additional Suggestions - 8
  • superset/mcp_service/utils/response_utils.py - 1
    • Missing unit tests · Line 169-212
      The new `format_data_columns` utility lacks unit tests. Per project guidelines, new MCP utilities require dedicated test coverage in `tests/unit_tests/mcp_service/utils/test_response_utils.py` covering success paths, type inference edge cases, and boundary conditions.
  • superset/mcp_service/app.py - 1
    • Documentation inconsistency across tools · Line 313-317
      The `get_compatible_metrics` example only shows `view_id` (external views), but this tool also supports `dataset_id` for built-in datasets. The companion tool `get_compatible_dimensions` includes "dataset_id: # or view_id: " in its example. For consistency, add both options so users understand built-in datasets are also supported.
  • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_metrics.py - 2
    • Incomplete test assertions · Line 136-138
      The builtin path test only validates `name` field (line 116) but doesn't verify that other fields like `expression`, `verbose_name`, `d3format`, and `warning_text` are correctly populated from the dataset metrics. This allows bugs in those fields to go undetected. Add assertions checking `expression` is "COUNT(*)" for the first metric and "SUM(revenue)" for the second.
    • Test helper incomplete for external fields · Line 87-87
      The `_make_view` helper (line 87) creates metrics without `verbose_name`, `d3format`, or `warning_text` fields set. This means tests cannot verify the external path correctly enriches these fields from the view's metric metadata.
  • tests/unit_tests/mcp_service/semantic_layer/tool/test_list_metrics.py - 1
    • Hardcoded constant instead of import · Line 149-149
      Uses hardcoded string `"DataModelMetadataRestricted"` instead of importing `DATA_MODEL_METADATA_ERROR_TYPE`. Other similar tests in the repo (e.g., `test_list_charts.py` line 35, 343) use the imported constant. This creates maintenance risk if the constant value ever changes.
  • superset/mcp_service/semantic_layer/tool/get_table.py - 1
    • Redundant str() call on str field · Line 245-245
      At line 245, `str(ex.error.message)` wraps a string attribute in an extra `str()` call — this is redundant. The message field on SupersetError is already typed as str.
  • superset/mcp_service/semantic_layer/tool/list_metrics.py - 2
    • Redundant inline import inside if branch · Line 80-82
      Duplicate inline import of `subqueryload` and `SqlaTable` inside the `if request.dataset_id is not None` block (lines 80-82). Both symbols are already imported at function scope (lines 74-76), making the nested imports redundant and misleading — they suggest conditional availability when it is unconditional.
    • Redundant inline import inside else branch · Line 93-95
      Duplicate inline import of `subqueryload` and `SqlaTable` inside the else block (lines 93-95). Both symbols are already imported at function scope (lines 74-76), making the nested imports redundant. Same issue as lines 80-82 but in the else branch.
Filtered by Review Rules

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

  • superset/mcp_service/semantic_layer/tool/get_table.py - 3
  • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py - 6
  • superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py - 1
  • superset/mcp_service/semantic_layer/tool/list_metrics.py - 1
Review Details
  • Files reviewed - 18 · Commit Range: 8f2a01e..ec88c32
    • superset/daos/semantic_layer.py
    • superset/mcp_service/app.py
    • superset/mcp_service/dataset/tool/query_dataset.py
    • superset/mcp_service/semantic_layer/__init__.py
    • superset/mcp_service/semantic_layer/schemas.py
    • superset/mcp_service/semantic_layer/tool/__init__.py
    • superset/mcp_service/semantic_layer/tool/get_compatible_dimensions.py
    • superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py
    • superset/mcp_service/semantic_layer/tool/get_table.py
    • superset/mcp_service/semantic_layer/tool/list_metrics.py
    • superset/mcp_service/utils/query_utils.py
    • superset/mcp_service/utils/response_utils.py
    • tests/unit_tests/mcp_service/semantic_layer/__init__.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/__init__.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_dimensions.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_metrics.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_list_metrics.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/daos/semantic_layer.py Resolved
Comment thread superset/daos/semantic_layer.py Resolved
@github-actions github-actions Bot removed the api Related to the REST API label Jul 6, 2026
Comment thread superset/daos/semantic_layer.py Resolved
@bito-code-review

bito-code-review Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #326b42

Actionable Suggestions - 0
Filtered by Review Rules

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

  • superset/mcp_service/semantic_layer/tool/list_metrics.py - 1
Review Details
  • Files reviewed - 15 · Commit Range: ec88c32..f4bcbf3
    • superset/daos/semantic_layer.py
    • superset/mcp_service/semantic_layer/tool/get_table.py
    • tests/unit_tests/mcp_service/utils/test_query_utils.py
    • tests/unit_tests/semantic_layers/dao_test.py
    • superset/mcp_service/dataset/tool/query_dataset.py
    • superset/mcp_service/semantic_layer/tool/get_compatible_dimensions.py
    • superset/mcp_service/semantic_layer/tool/list_metrics.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_dimensions.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_metrics.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_list_metrics.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py
    • superset/mcp_service/utils/response_utils.py
    • tests/unit_tests/mcp_service/utils/test_response_utils.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Adds a semantic-layer surface to the MCP service for LLM-driven metric
discovery and querying across both built-in SqlaTable datasets and
external SemanticView-backed sources:

- list_metrics: unified metric discovery with inline compatible
  dimensions and pagination, sorted deterministically.
- get_table: query a dataset/semantic view by metric + dimension name,
  with time_column/time_range validation.
- get_compatible_dimensions / get_compatible_metrics: progressive
  query-builder support, resolving per-metric compatibility for
  external views.

Includes shared utilities (query_utils.validate_names,
response_utils.format_data_columns), DAO permission filtering
(SemanticViewDAO.find_accessible), and unit test coverage for all
four tools plus the shared utilities and DAO methods.
Rebase fallout: master added tests importing _validate_names directly
from query_dataset.py, but this branch had already extracted that
function into the shared superset.mcp_service.utils.query_utils
module as validate_names(). Point the tests at the shared function
instead of re-adding the now-removed local copy.
@aminghadersohi
aminghadersohi force-pushed the aminghadersohi/mcp-semantic-layer-tools branch from f4bcbf3 to d2a5b56 Compare July 7, 2026 03:53
Comment thread superset/daos/semantic_layer.py Resolved

@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 #18034f

Actionable Suggestions - 3
  • superset/daos/semantic_layer.py - 1
  • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_dimensions.py - 1
  • superset/mcp_service/semantic_layer/tool/list_metrics.py - 1
Additional Suggestions - 2
  • superset/mcp_service/app.py - 1
    • Inconsistent documentation parameter · Line 316-316
      The `get_compatible_metrics` example on line 316 only shows `view_id` as the parameter, while the similar `get_compatible_dimensions` example on line 311 correctly shows `dataset_id` with a comment about `view_id` as an alternative. Both functions accept either `dataset_id` or `view_id` as documented in the schemas, so the documentation should be consistent. Users may mistakenly believe `view_id` is required when `dataset_id` works for built-in datasets.
  • superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py - 1
    • Inconsistent MetricInfo fields in external path · Line 191-209
      The external semantic view path (lines 191-209) builds `MetricInfo` without the `verbose_name` field that the builtin path (lines 139-152) provides. This makes the `source=external` response structurally incomplete compared to `source=builtin`.
Filtered by Review Rules

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

  • superset/mcp_service/semantic_layer/tool/get_compatible_dimensions.py - 1
    • CWE-703: AttributeError on exception access · Line 184-184
  • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_metrics.py - 7
    • Missing return type annotation on fixture · Line 46-46
    • Missing return type annotation on helper · Line 62-62
    • Missing return type annotation on helper · Line 73-73
    • Missing return type annotation on helper · Line 82-82
    • Missing return type annotation on helper · Line 92-92
    • Unused import statement · Line 24-24
    • Inconsistent error type constant · Line 30-32
Review Details
  • Files reviewed - 23 · Commit Range: a26a383..d2a5b56
    • superset/daos/semantic_layer.py
    • superset/mcp_service/app.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/dataset/tool/query_dataset.py
    • superset/mcp_service/semantic_layer/__init__.py
    • superset/mcp_service/semantic_layer/schemas.py
    • superset/mcp_service/semantic_layer/tool/__init__.py
    • superset/mcp_service/semantic_layer/tool/get_compatible_dimensions.py
    • superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py
    • superset/mcp_service/semantic_layer/tool/get_table.py
    • superset/mcp_service/semantic_layer/tool/list_metrics.py
    • superset/mcp_service/utils/query_utils.py
    • superset/mcp_service/utils/response_utils.py
    • tests/unit_tests/mcp_service/chart/test_chart_config_coercion.py
    • tests/unit_tests/mcp_service/semantic_layer/__init__.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/__init__.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_dimensions.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_metrics.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_list_metrics.py
    • tests/unit_tests/mcp_service/utils/test_query_utils.py
    • tests/unit_tests/mcp_service/utils/test_response_utils.py
    • tests/unit_tests/semantic_layers/dao_test.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

- Fix DataColumn.statistics description to not claim numeric-only,
  since format_data_columns now sets statistics.sampled_rows for any
  sampled column type.
- Add verbose_name to external metrics in list_metrics, matching the
  builtin path.
- Add missing NotFound test for get_compatible_dimensions' external
  view lookup path (only the builtin path was covered).
- Add explicit type annotations to remaining local variables flagged
  by automated review (DAO lookups, dataset/view lists, lookup dicts,
  mock helpers in tests) per this project's type-hint conventions.

Left two suggestions unapplied: annotating the `cls` parameter on
`SemanticLayerError.create`/`SemanticViewDAO.find_accessible` classmethods
would be inconsistent with every other `.create()` classmethod in
mcp_service/*/schemas.py, none of which annotate `cls`.
# Local import breaks the chart.schemas ↔ response_utils circular dependency.
from superset.mcp_service.chart.schemas import DataColumn # noqa: PLC0415

stats_rows = data[:STATS_ROW_CAP]

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.

Suggestion: Add an explicit type annotation for this intermediate rows collection to satisfy the type-hint requirement for relevant variables. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The variable is introduced without an explicit type annotation even though its type can be clearly annotated as a list of row dictionaries, which matches the custom rule requiring type hints on relevant variables in new or modified Python code.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/mcp_service/utils/response_utils.py
**Line:** 185:185
**Comment:**
	*Custom Rule: Add an explicit type annotation for this intermediate rows collection to satisfy the type-hint requirement for relevant variables.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[dict[str, Any]] annotation to stats_rows.

from superset.mcp_service.chart.schemas import DataColumn # noqa: PLC0415

stats_rows = data[:STATS_ROW_CAP]
is_sampled = len(data) > STATS_ROW_CAP

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.

Suggestion: Add a boolean type annotation for this sampling flag variable. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a new boolean local variable that can be explicitly annotated as bool, but it is left untyped in the modified code, so it fits the type-hint rule for relevant variables.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/mcp_service/utils/response_utils.py
**Line:** 186:186
**Comment:**
	*Custom Rule: Add a boolean type annotation for this sampling flag variable.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit bool annotation to is_sampled.

sample_values = [
row.get(col_name) for row in data[:3] if row.get(col_name) is not None
]
data_type = "string"

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.

Suggestion: Add an explicit type annotation for this inferred column type variable. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The variable is a new local scalar whose type can be explicitly annotated as str, but the modified code leaves it inferred, which violates the custom type-hint requirement.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/mcp_service/utils/response_utils.py
**Line:** 192:192
**Comment:**
	*Custom Rule: Add an explicit type annotation for this inferred column type variable.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit str annotation to data_type.

Comment on lines +138 to +152
compatible = [
MetricInfo(
name=m.metric_name,
verbose_name=m.verbose_name or None,
description=m.description or None,
expression=m.expression or None,
d3format=m.d3format or None,
warning_text=m.warning_text or None,
source="builtin",
dataset_id=dataset.id,
dataset_name=dataset.table_name,
)
for m in dataset.metrics
if m.metric_name not in selected_metrics
]

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.

Suggestion: Add an explicit type annotation for this list variable to satisfy the requirement for annotating relevant variables. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The list variable compatible is newly introduced without an explicit type annotation in a Python file, which matches the custom rule requiring type hints on relevant variables that can be annotated.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py
**Line:** 138:152
**Comment:**
	*Custom Rule: Add an explicit type annotation for this list variable to satisfy the requirement for annotating relevant variables.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[MetricInfo] annotation to compatible.

Comment on lines +101 to +104
query = db.session.query(SqlaTable).options(
subqueryload(SqlaTable.columns),
subqueryload(SqlaTable.metrics),
)

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.

Suggestion: Add an explicit type annotation for this SQLAlchemy query variable to satisfy the type-hint requirement for relevant local variables. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a new local variable in modified Python code that could be explicitly typed, so it fits the rule requiring type hints for relevant annotatable variables.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/mcp_service/semantic_layer/tool/list_metrics.py
**Line:** 101:104
**Comment:**
	*Custom Rule: Add an explicit type annotation for this SQLAlchemy query variable to satisfy the type-hint requirement for relevant local variables.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit Query annotation to query.

await ctx.debug("Collected %d built-in metrics" % len(all_metrics))

if request.dataset_id is None:
external = await _collect_external_metrics(request, ctx)

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.

Suggestion: Add a type annotation to this local variable so the collected external metrics list is explicitly typed. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The local variable external is assigned a list result and is not explicitly annotated, so it is a valid type-hint omission under the rule.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/mcp_service/semantic_layer/tool/list_metrics.py
**Line:** 294:294
**Comment:**
	*Custom Rule: Add a type annotation to this local variable so the collected external metrics list is explicitly typed.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[MetricInfo] annotation to external.


def test_infers_boolean_type(self) -> None:
"""Should infer boolean data_type from sample values."""
data = [{"is_active": True}, {"is_active": False}]

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.

Suggestion: Add an explicit type annotation for this local dataset variable to comply with required Python type hints. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This new local variable is untyped even though its value is a list of dictionaries and can clearly be annotated. That matches the rule requiring type hints for new Python variables that can be annotated.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/mcp_service/utils/test_response_utils.py
**Line:** 50:50
**Comment:**
	*Custom Rule: Add an explicit type annotation for this local dataset variable to comply with required Python type hints.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[dict[str, Any]] annotation to the test's data variable.


def test_infers_string_type_by_default(self) -> None:
"""Should default to string data_type when values aren't numeric/boolean."""
data = [{"region": "west"}, {"region": "east"}]

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.

Suggestion: Add an explicit type annotation for this local dataset variable to satisfy the enforced type-hint rule. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a newly added untyped local variable in Python code, and its structure is obvious enough to annotate. The rule explicitly requires type hints for such variables.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/mcp_service/utils/test_response_utils.py
**Line:** 57:57
**Comment:**
	*Custom Rule: Add an explicit type annotation for this local dataset variable to satisfy the enforced type-hint rule.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[dict[str, Any]] annotation to the test's data variable.


def test_string_type_when_no_sample_values(self) -> None:
"""Should default to string data_type when all sampled values are null."""
data = [{"region": None}]

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.

Suggestion: Add a concrete type annotation to this local variable rather than leaving it untyped. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This local dataset variable is untyped in newly added Python code and can be annotated as a list of dicts. That is a direct violation of the type-hint rule.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/mcp_service/utils/test_response_utils.py
**Line:** 64:64
**Comment:**
	*Custom Rule: Add a concrete type annotation to this local variable rather than leaving it untyped.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[dict[str, Any]] annotation to the test's data variable.


def test_sample_values_capped_at_three(self) -> None:
"""Should only take the first 3 non-null values as samples."""
data = [{"region": f"r{i}"} for i in range(10)]

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.

Suggestion: Add an explicit type hint for this list-comprehension-backed local dataset variable. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This new local variable is untyped even though the list-comprehension result is easy to annotate. The code therefore violates the Python type-hint requirement.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/mcp_service/utils/test_response_utils.py
**Line:** 71:71
**Comment:**
	*Custom Rule: Add an explicit type hint for this list-comprehension-backed local dataset variable.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[dict[str, Any]] annotation to the test's data variable.

sample for performance, but were previously returned as if they were
exact full-dataset totals with no indication of sampling.
"""
data = [{"id": i} for i in range(STATS_ROW_CAP + 10)]

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.

Suggestion: Add an explicit type annotation for this local variable to comply with mandatory Python typing in new code. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This newly introduced local variable is untyped and has a clear list-of-dicts shape that can be annotated, so it falls under the required Python type-hint rule.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/mcp_service/utils/test_response_utils.py
**Line:** 97:97
**Comment:**
	*Custom Rule: Add an explicit type annotation for this local variable to comply with mandatory Python typing in new code.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e91cf2: added an explicit list[dict[str, Any]] annotation to the test's data variable.

…tic layer tools

- get_table now lists valid metric names (or a discovery hint) when an
  unknown metric is requested, matching query_dataset behavior via the
  shared validate_names utility.
- validate_names gains a full_list_hint parameter so semantic layer
  tools can point at list_metrics instead of get_dataset_info.
- get_compatible_dimensions / get_compatible_metrics now reject unknown
  names in selected_metrics / selected_dimensions with a ValidationError
  instead of silently ignoring them on the builtin dataset path.
Adds missing local-variable type hints in response_utils.py,
list_metrics.py, get_compatible_metrics.py, and the response_utils
test file, per the dev-standard type-hint rule.
@aminghadersohi
aminghadersohi merged commit fbc2495 into master Jul 7, 2026
59 checks passed
@aminghadersohi
aminghadersohi deleted the aminghadersohi/mcp-semantic-layer-tools branch July 7, 2026 16:51
@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

rusackas added a commit that referenced this pull request Sep 28, 2026
Documents the four semantic-layer MCP tools from #41611 (list_metrics,
get_table, get_compatible_dimensions, get_compatible_metrics): a
"Query the Semantic Layer" workflow section with example prompts and a
recommended-workflow callout in the end-user AI docs, a "Semantic
Layer" tool reference table, and the FAB permission row these tools
require in the admin MCP server guide.

Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants