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

   ### SUMMARY
   Adds a new MCP tool, `manage_native_filters`, to the Superset MCP service. 
Native filters are what make dashboards interactive; the MCP server could 
previously read them (via `get_dashboard_info`) but not write them.
   
   The tool exposes four operations on a dashboard's native filters, translated 
into the `deleted` / `modified` / `reordered` payload consumed by the existing 
`UpdateDashboardNativeFiltersCommand` (the same command behind the `PUT 
/api/v1/dashboard/{pk}/filters` endpoint):
   
   - **add** — create new filters from strict Pydantic specs (no raw JSON 
configs). v1 supports `filter_select` (dropdown: dataset + column target, 
`multiSelect`, `defaultToFirstItem`, `enableEmptyFilter`, `sortAscending`, 
`searchAllOptions`) and `filter_time` (time range with optional default). Other 
filter types (numerical range, time column, time grain) are documented as not 
yet supported.
   - **update** — partial updates addressed by filter ID. Because the backend 
command substitutes whole config entries (it does not merge deltas), the tool 
reads the dashboard's current `native_filter_configuration` and merges changes 
into FULL filter configs. Type-incompatible fields (e.g. `default_time_range` 
on a `filter_select`) are rejected.
   - **remove** — delete filters by ID (unknown IDs produce a descriptive error 
listing valid IDs).
   - **reorder** — complete ordered ID list. The DAO silently drops any 
surviving filter missing from the reordered list, so the tool validates the 
list covers every remaining filter; newly added filters are appended 
automatically.
   
   Design notes:
   - Filter IDs are server-generated as `NATIVE_FILTER-<random>`, matching the 
frontend's `generateFilterId` convention, and returned in the response 
(`added_filter_ids`).
   - New filter configs follow the frontend `Filter` type shape: `{id, type: 
"NATIVE_FILTER", filterType, name, description, scope, targets, controlValues, 
defaultDataMask, cascadeParentIds}`.
   - Optional `scope_chart_ids` per filter is translated into the frontend's 
exclusion-list scope (`{rootPath: ["ROOT_ID"], excluded: [...]}`); IDs not on 
the dashboard are rejected. When omitted, the filter applies to all charts.
   - Dataset and column targets are validated via `DatasetDAO` with an error 
that lists available columns so LLM callers can self-correct.
   - Decorated with `tags=["mutate"]`, `class_permission_name="Dashboard"`, 
`method_permission_name="write"`, and `ToolAnnotations(readOnlyHint=False, 
destructiveHint=True)` since `remove` deletes filters. 
`DashboardForbiddenError` / `TagForbiddenError` surface as structured 
`permission_denied` responses.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A — MCP service only, no UI changes.
   
   ### TESTING INSTRUCTIONS
   1. `pytest 
tests/unit_tests/mcp_service/dashboard/tool/test_manage_native_filters.py`
   2. Or manually: start the MCP service, then call `manage_native_filters` 
with e.g. `{"dashboard_id": 1, "add": [{"filter_type": "filter_select", "name": 
"Region", "dataset_id": 5, "column": "region"}]}` and verify the filter appears 
on the dashboard's filter bar; exercise `update`, `remove`, and `reorder` 
similarly.
   
   ### 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


-- 
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]

Reply via email to