rebenitez1802 opened a new pull request, #45357:
URL: https://github.com/apache/superset/pull/45357
### SUMMARY
MCP clients can read a dashboard's native filters through
`get_dashboard_info`, but not the values those filters offer. An assistant
asked to "filter to Bikes" or "show Europe, Middle East & Africa" has to guess
which filter and which stored value the user means, and comma-containing or
quoted values are easy to mangle. This adds opt-in, bounded discovery of the
dropdown choices a caller may select.
**Request (all additive; existing calls are unchanged and run no choice
queries)**
- `include_filter_values: true` opts in; `native_filters` must stay in
`select_columns`.
- `filter_value_requests`: up to 20 filter IDs, each with optional `limit`
(default 25, max 100), a literal case-insensitive `search`, or a strictly typed
`exact_value` (including explicit `null`).
- `filter_values_offset`: pages through filter definitions (20 per page)
when no explicit IDs are given.
- `proposed_filter_values`: a read-only preview of parent selections, so a
dependent filter's choices can be discovered for a parent change before
anything is applied.
**Response**
- Each returned native filter gains `available_values`: `status` (`complete`
/ `truncated` / `unavailable` / `unsupported`), exact scalar `values`,
`query_mode`, `reason` and `scope: "filter_selection"`.
- A companion `filter_value_discovery` object reports pagination, query
count and validated proposals.
- `complete` only claims completeness for the given mode, predicate and
effective parent selections. `truncated` never establishes absence, and
`unavailable` always carries a reason.
**Design**
- **Native filter query path.** Choices use the dashboard's native filter
query construction (`NATIVE_FILTER` form data, then
`ChartDataQueryContextSchema`, then `ChartDataCommand.validate()` before every
run or cache read). Dashboard and embedded-guest grants, guest dataset
allowlists, RLS, saved dropdown predicates and cascading parents therefore
apply exactly as in the dashboard UI. The target's own selection and unrelated
filters do not restrict its dropdown. Choices are selectable options, not
values present in filtered chart results.
- **Snapshot state.** `permalink_key` or `filter_state` is hydrated the way
the dashboard does it. Under `X-Superset-Dashboard-Scope`, a `dataMask`
snapshot is required. Missing, invalid or expired state is reported per filter
and never falls back to saved defaults.
- **Exact values.** Private query flags keep exact scalars (no whitespace or
sentinel coercion) and use a dialect-escaped literal contains predicate. The
flags are stripped from stored-chart, cache warm-up and public-schema paths, so
ordinary chart behavior is unchanged.
- **Bounds.** At most 20 dataset queries per call (including failures and
proposal validation), no new scheduling after 10 s, a 20 KiB choice envelope,
and the configured whole-response limit. The size guard removes whole option
values only and marks the list `truncated/response_limit`; it never clips a
value. Discovery calls bypass the outer MCP tool-response cache. Authorized
query caching still applies after validation.
- **Docs.** A new "Native filter choice discovery" section in
`docs/developer_docs/extensions/mcp.md` documents the contract.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend / MCP API only)
### TESTING INSTRUCTIONS
```bash
pytest
tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_filter_values.py
\
tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_guest_discovery.py \
tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py \
tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py \
tests/unit_tests/mcp_service/test_dashboard_scope.py \
tests/unit_tests/mcp_service/test_mcp_caching.py \
tests/unit_tests/mcp_service/test_middleware.py \
tests/unit_tests/mcp_service/utils/test_response_size_utils.py \
tests/unit_tests/models/helpers_test.py \
tests/unit_tests/common/test_query_object_factory.py \
tests/unit_tests/common/test_query_context_factory.py \
tests/unit_tests/commands/chart/warm_up_cache_test.py
```
Manual check against an MCP client, on a dashboard with a Region select
filter and a dependent Country filter:
```json
{"request": {"identifier": 1, "include_filter_values": true,
"filter_value_requests": [{"filter_id": "NATIVE_FILTER-country", "search":
"Fr"}],
"proposed_filter_values": [{"filter_id": "NATIVE_FILTER-region", "values":
["EMEA"]}],
"select_columns": ["id", "native_filters"]}}
```
Confirm that the countries returned belong to EMEA, that the live dashboard
selection is unchanged, and that the same call without `include_filter_values`
returns the usual metadata with no `available_values`.
### 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
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]