feat: add ToolAuthorizationMiddleware for granular tool access control #350
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Link to Devin run: https://app.devin.ai/sessions/11342fe981114dcbb8980e63517d132a
Requested by: Martin Vasko (@Matovidlo)
Change Type
Summary
Adds a new
ToolAuthorizationMiddlewarethat enables granular tool access control via HTTP headers. This allows administrators to restrict which tools specific clients (like Devin AI agent) can access.New HTTP Headers:
X-Allowed-Tools: Comma-separated list of allowed tool names (e.g.,get_configs,get_buckets,query_data)X-Read-Only-Mode: Set totrue/1/yesto restrict access to read-only tools onlyBehavior:
X-Allowed-Toolsheader is treated as no restriction (same as no header)Key files:
src/keboola_mcp_server/authorization.py- New middleware implementation withREAD_ONLY_TOOLSfrozensetsrc/keboola_mcp_server/server.py- Middleware registration in the pipelinetests/test_authorization.py- Comprehensive unit tests (27 test cases)Human Review Checklist
READ_ONLY_TOOLSlist matches all tools withreadOnlyHint=Trueannotationctxparameter in_get_allowed_toolsis unused (only usesget_http_request_or_none())Testing
Streamable-HTTPtransports)Optional testing
canary-orionMCP (SSEandStreamable-HTTP)canary-orioncanary-orionChecklist