Repository navigation
feat(mcp): add semantic layer MCP tools (list_metrics, get_table, get_compatible_dimensions, get_compatible_metrics) - #41611
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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). |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
fa0e3b7 to
d80343c
Compare
There was a problem hiding this comment.
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
- Missing unit tests for new DAO method · Line 204-225
-
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-212The 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-317The `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-138The 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-87The `_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-149Uses 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-245At 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-82Duplicate 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-95Duplicate 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
- Wrong assignment creates tuple · Line 371-374
- Type mismatch: str vs CacheStatus · Line 358-358
- Type mismatch: str vs CacheStatus · Line 393-394
-
tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py - 6
- Incomplete happy-path assertions · Line 118-159
- Missing error message assertion · Line 162-170
- Missing error message assertion · Line 173-183
- Missing error message assertion · Line 186-199
- Missing error message assertion · Line 202-216
- Missing error message assertion · Line 245-263
-
superset/mcp_service/semantic_layer/tool/get_compatible_metrics.py - 1
- Missing metric metadata in external path · Line 187-205
-
superset/mcp_service/semantic_layer/tool/list_metrics.py - 1
- Missing metric fields for external source · Line 182-191
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
Code Review Agent Run #326b42Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
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.
f4bcbf3 to
d2a5b56
Compare
There was a problem hiding this comment.
Code Review Agent Run #18034f
Actionable Suggestions - 3
-
superset/daos/semantic_layer.py - 1
- Inline imports should be module-level · Line 204-236
-
tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_dimensions.py - 1
- Missing NotFound test for view path · Line 222-232
-
superset/mcp_service/semantic_layer/tool/list_metrics.py - 1
- Missing verbose_name for external metrics · Line 210-220
Additional Suggestions - 2
-
superset/mcp_service/app.py - 1
-
Inconsistent documentation parameter · Line 316-316The `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-209The 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
- 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] |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
Fixed in 7e91cf2: added an explicit str annotation to data_type.
| 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 | ||
| ] |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
Fixed in 7e91cf2: added an explicit list[MetricInfo] annotation to compatible.
| query = db.session.query(SqlaTable).options( | ||
| subqueryload(SqlaTable.columns), | ||
| subqueryload(SqlaTable.metrics), | ||
| ) |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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}] |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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"}] |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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}] |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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)
(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 fixThere was a problem hiding this comment.
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.
|
Bito Automatic Review Skipped – PR Already Merged |
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]>
SUMMARY
Adds 4 new MCP tools that surface Superset's semantic layer to LLM clients, spanning both built-in
SqlaTabledatasets and externalSemanticViewimplementations.Primary workflow (as recommended in research spike):
list_metrics→ discover available metrics and their compatible dimensions inlineget_table→ query data using chosen metrics and dimensionsTools added:
list_metrics— Unified metric discovery across built-in datasets and external semantic views. ReturnsMetricInfoobjects withcompatible_dimensionsincluded per metric for progressive query building. Supports search by name/description, filtering bydataset_idorview_id, and pagination.get_table— Query a data source (built-in or external) using metric and dimension names. Routes toChartDataCommand(built-inSqlaTable) or the semantic view's query path (external) based ondataset_idvsview_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 toSemanticView.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 toSemanticView.get_compatible_metrics().Design decisions:
dataset_id/view_idfromlist_metricsto avoid ambiguity when metric names collide across sources@tooldecorator withtags/class_permission_name/ToolAnnotations, Pydantic schemas, DAO-based lookups,event_logger,ctxlogging, ASF license headersBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — MCP tool additions (no UI changes)
TESTING INSTRUCTIONS
list_metrics(request={"search": "revenue"})dataset_id(orview_id) and acompatible_dimensionsentryget_table(request={"dataset_id": <id>, "metrics": ["<metric>"], "dimensions": ["<dim>"], "row_limit": 10})view_idin place ofdataset_idget_compatible_dimensionsandget_compatible_metricsreturn valid subsets for a known viewADDITIONAL INFORMATION