You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "mikebridge (via GitHub)" <gi...@apache.org> on 2026/10/09 20:19:54 UTC

[PR] fix(mcp): reject unknown semantic compatibility selections [superset]

mikebridge opened a new pull request, #45153:
URL: https://github.com/apache/superset/pull/45153

   ### SUMMARY
   
   The MCP tools `get_compatible_metrics` and `get_compatible_dimensions` silently dropped selected names they did not recognize when the source was an external semantic view. `SemanticView.get_compatible_*` translates names to semantic-layer objects and skips any name it can't find. A typo, a display label or a provider ID therefore produced a successful answer for a smaller selection than the caller asked for, with no sign that anything was ignored. The SQL-dataset path of the same tools already rejected unknown names, and so does `get_table` for filters.
   
   On the external-view path, both tools now validate `selected_metrics` and `selected_dimensions` against the view's metric and dimension names. The check runs after the access check and before the provider's compatibility call. Unknown names return a `ValidationError` that names each one, using the existing shared validator. For example:
   
   `Unknown metric: 'bogus_metric'; Unknown dimension: 'bogus_dimension'`
   
   Close-match suggestions come only from the view's member names. Provider metric or dimension definitions never appear in the error. The validator is a small shared helper in `mcp_service/utils/query_utils.py`, used by both tools.
   
   Behavior:
   
   | Selection on an external semantic view | Before | After |
   | --- | --- | --- |
   | All names known | Compatible members returned | Unchanged |
   | Empty selection | Compatible members returned | Unchanged |
   | Contains an unknown metric or dimension name | Success, computed as if the unknown name were absent | `ValidationError` naming the unknown fields; no provider compatibility call |
   
   The source-selection checks (`dataset_id` versus `view_id`) were merged into one branch, keeping both existing error messages, and tests now pin those messages. The MCP server docs describe the validation.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Not applicable: MCP tool response change, with no UI. The table above describes the behavior before and after.
   
   ### TESTING INSTRUCTIONS
   
   ```bash
   pytest tests/unit_tests/mcp_service/semantic_layer/tool/test_compatibility_selection_validation.py \
          tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_metrics.py \
          tests/unit_tests/mcp_service/semantic_layer/tool/test_get_compatible_dimensions.py
   ```
   
   The new test calls both tools through the MCP client against a real `SemanticView`. The view is backed by core `Metric`/`Dimension` objects whose IDs differ from their names (`orders.bookings` / `bookings`), so it exercises the model's real name translation.
   
   - **Invalid cases:** an unknown metric, an unknown dimension, or both. Each returns the fixed `ValidationError`, never calls the provider's compatibility method, and leaks no provider definitions.
   - **Valid and empty cases:** the provider still receives the same object sets.
   - **Before the fix:** the six invalid cases return success, and the four valid or empty cases pass on both.
   
   Local validation:
   - The MCP semantic-layer tool tests pass. The one exception is an existing timezone-dependent `get_table` test that this change does not touch.
   - Changed-file pre-commit passed, including mypy, ruff and pylint.
   - No live semantic provider was used.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] 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
   
   @aminghadersohi
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): reject unknown semantic compatibility selections [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #45153:
URL: https://github.com/apache/superset/pull/45153#issuecomment-6145597375

   ## CodeAnt PR Risk: Low Risk
   
   - The PR appears safe to merge; it narrowly validates selected names for external semantic views.
   - Tests cover both compatibility tools, unknown metric and dimension names, and valid or empty selections.
   
   **Assessed commit:** `66741154bbb5`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): reject unknown semantic compatibility selections [superset]

Posted by "gabotorresruiz (via GitHub)" <gi...@apache.org>.
gabotorresruiz commented on code in PR #45153:
URL: https://github.com/apache/superset/pull/45153#discussion_r4264839398


##########
superset/mcp_service/utils/query_utils.py:
##########
@@ -15,12 +15,24 @@
 # specific language governing permissions and limitations
 # under the License.
 
-"""Backwards-compatible re-export of the shared name validator.
+"""Shared name validation for MCP tools.
 
-The implementation now lives in ``superset.common.tabular_query`` so the REST
+The name-validator implementation lives in ``superset.common.tabular_query`` so the REST
 endpoint and the MCP tools cannot drift apart.
 """
 
 from superset.common.tabular_query import validate_names
 
-__all__ = ["validate_names"]
+__all__: list[str] = ["validate_names", "validate_selection_names"]
+
+
+def validate_selection_names(
+    selected_metrics: list[str],
+    selected_dimensions: list[str],
+    valid_metrics: set[str],
+    valid_dimensions: set[str],
+) -> list[str]:
+    """Report unknown selected members using the shared validation messages."""
+    return validate_names(selected_metrics, valid_metrics, "metric") + validate_names(
+        selected_dimensions, valid_dimensions, "dimension"
+    )

Review Comment:
   Not a blocker, more a parity question: should the external path hand back the same recovery hint the SQL path already does? The SQL branch of this same tool passes `list_valid_on_miss=True` and `full_list_hint="call list_metrics for the full list"` (`get_compatible_metrics.py:161`), and `validate_query_names` does the same for `get_table` on both sources, so an unknown metric with no close match reads `Unknown metric: 'zzzzzzzz'. Valid metrics: bookings, revenue` there but just `Unknown metric: 'zzzzzzzz'` here. Since the caller is an agent, that list is usually what lets it retry without another round trip. Leaving the dimension half bare keeps it matching the SQL path, which is also bare.
   
   ```suggestion
   def validate_selection_names(
       selected_metrics: list[str],
       selected_dimensions: list[str],
       valid_metrics: set[str],
       valid_dimensions: set[str],
   ) -> list[str]:
       """Report unknown selected members using the shared validation messages."""
       return validate_names(
           selected_metrics,
           valid_metrics,
           "metric",
           list_valid_on_miss=True,
           full_list_hint="call list_metrics for the full list",
       ) + validate_names(selected_dimensions, valid_dimensions, "dimension")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): reject unknown semantic compatibility selections [superset]

Posted by "gabotorresruiz (via GitHub)" <gi...@apache.org>.
gabotorresruiz merged PR #45153:
URL: https://github.com/apache/superset/pull/45153


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): reject unknown semantic compatibility selections [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #45153:
URL: https://github.com/apache/superset/pull/45153#issuecomment-6088617070

   ### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">🔨</span> Latest commit | 937e9c521455f02549be50e9d2503a2388721c28 |
   |<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6ac94c6a1fcbcb000759b8a3 |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-45153--superset-docs-preview.netlify.app](https://deploy-preview-45153--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQ1MTUzLS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.4KmLGTJPffJNdRbJ5ZWHJca3AdtZrKIoxkKKKKYhWHs)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcpLCoAgEADQu8w6QSstu0HHGEcjwR8mQUR3z91bvBdKzbE02AAGMBUTnd0XMTFKqTmLVNjlIqbmid0YvMXmc-rZuhLys9veFZKeSaE4yJDhnC9SmxUn-H4) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-45153--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): reject unknown semantic compatibility selections [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #45153:
URL: https://github.com/apache/superset/pull/45153#issuecomment-6088898319

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/45153?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `30.76923%` with `9 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 65.57%. Comparing base ([`a8fc576`](https://app.codecov.io/gh/apache/superset/commit/a8fc576cfe36011788c1c78eaca3c31f77d9d43e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`937e9c5`](https://app.codecov.io/gh/apache/superset/commit/937e9c521455f02549be50e9d2503a2388721c28?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/45153?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...e/semantic\_layer/tool/get\_compatible\_dimensions.py](https://app.codecov.io/gh/apache/superset/pull/45153?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fsemantic_layer%2Ftool%2Fget_compatible_dimensions.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2Uvc2VtYW50aWNfbGF5ZXIvdG9vbC9nZXRfY29tcGF0aWJsZV9kaW1lbnNpb25zLnB5) | 20.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/45153?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...vice/semantic\_layer/tool/get\_compatible\_metrics.py](https://app.codecov.io/gh/apache/superset/pull/45153?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fsemantic_layer%2Ftool%2Fget_compatible_metrics.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2Uvc2VtYW50aWNfbGF5ZXIvdG9vbC9nZXRfY29tcGF0aWJsZV9tZXRyaWNzLnB5) | 20.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/45153?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/utils/query\_utils.py](https://app.codecov.io/gh/apache/superset/pull/45153?src=pr&el=tree&filepath=superset%2Fmcp_service%2Futils%2Fquery_utils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvdXRpbHMvcXVlcnlfdXRpbHMucHk=) | 66.66% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/45153?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #45153       +/-   ##
   ===========================================
   - Coverage   82.83%   65.57%   -17.27%     
   ===========================================
     Files        3017     3017               
     Lines      192698   192713       +15     
     Branches    44914    44914               
   ===========================================
   - Hits       159624   126365    -33259     
   - Misses      30040    63552    +33512     
   + Partials     3034     2796      -238     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `35.35% <30.76%> (+<0.01%)` | :arrow_up: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.81% <30.76%> (+<0.01%)` | :arrow_up: |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `37.19% <30.76%> (+<0.01%)` | :arrow_up: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `54.04% <30.76%> (-32.43%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.55% <30.76%> (+<0.01%)` | :arrow_up: |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/45153/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/45153?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org