aminghadersohi opened a new pull request, #40098:
URL: https://github.com/apache/superset/pull/40098
### SUMMARY
Add RBAC-aware tool visibility to the MCP service so that write tools are
hidden from users who lack write permissions, and permission-denied errors
surface cleanly to the caller.
**Phase 1 — clean permission-denied errors:**
`MCPPermissionDeniedError` did not subclass `PermissionError`, so
`GlobalErrorHandlerMiddleware._handle_error()` fell through to the generic
"Internal error" branch (500-style response). Fixed by:
- Adding `MCPPermissionDeniedError` to `_USER_ERROR_TYPES` so it is logged
at WARNING, not ERROR
- Adding an explicit `elif isinstance(error, MCPPermissionDeniedError)`
branch that converts the error to a structured `ToolError` with the denial
message
**Phase 2 — per-request `tools/list` filtering:**
- Add `is_tool_visible_to_current_user(tool)` to `auth.py` as the single
source of truth for tool visibility, covering both RBAC permissions and
data-model metadata privacy
- Add `RBACToolVisibilityMiddleware` that intercepts `tools/list` responses
and removes tools the requesting user lacks permission to execute. Fail-open:
if user resolution fails, all tools are returned (call-time RBAC still enforces)
- Refactor `_tool_allowed_for_current_user()` in `server.py` to delegate to
`is_tool_visible_to_current_user()` so tool-search and `tools/list` share
identical visibility logic
- Register `RBACToolVisibilityMiddleware` inside
`StructuredContentStripperMiddleware` so it filters full tool objects before
`outputSchema` stripping
- Update server instructions to note write tools require write permissions
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — MCP protocol change, no UI.
### TESTING INSTRUCTIONS
1. Unit tests cover all new logic:
```bash
pytest tests/unit_tests/mcp_service/test_auth_rbac.py -v
pytest tests/unit_tests/mcp_service/test_middleware.py -v
```
2. Connect an MCP client as a Viewer-role user and confirm write tools
(`generate_chart`, `generate_dashboard`, etc.) do not appear in `tools/list`.
3. Connect as an Admin and confirm write tools are present.
4. Call a write tool directly as a Viewer; confirm the response is a
structured `ToolError` with a clear denial message (not an "Internal error").
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags: `MCP_RBAC_ENABLED` (default `True`)
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] 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]