Expand description
Role-based access control (RBAC) middleware for the proxy.
This module enforces per-role tool access policies on authenticated requests.
It reads JWT claims from RouterRequest extensions, maps claim values to
named roles via a configurable mapping, and applies per-role allow/deny lists
to both tools/call and tools/list requests.
§How role resolution works
- The auth layer (JWT or introspection) validates the token and inserts
TokenClaimsinto the request extensions. RbacConfigreads a configured claim (e.g."scope","role","groups") from those claims.- The claim value is matched against
role_mapping.mappingto resolve a role name (e.g."read-only"->"reader"). - The resolved role’s
allow_toolsanddeny_toolslists determine access.
If no TokenClaims are present in
the request extensions (e.g. unauthenticated or bearer-token-only requests),
the RBAC layer passes the request through without restriction.
§Allow/deny list semantics
Each role can define an allow list, a deny list, or both:
- Allow list only: only the listed tools are accessible. All others are denied.
- Deny list only: all tools are accessible except those listed.
- Both: a tool must appear in the allow list AND not appear in the deny list.
- Neither (empty lists): the role has unrestricted access (e.g. an admin role).
§Interaction with capability filtering
RBAC runs on top of the static capability filter configured per backend. The final set of visible tools is the intersection of what the backend exposes and what the role permits – RBAC can only further restrict, never widen, the tools a client can see or call.
§Configuration example
[auth]
type = "jwt"
issuer = "https://auth.example.com"
audience = "mcp-proxy"
jwks_uri = "https://auth.example.com/.well-known/jwks.json"
[[auth.roles]]
name = "admin"
# Empty allow/deny = unrestricted access
[[auth.roles]]
name = "reader"
allow_tools = ["files/read_file", "files/list_dir"]
[[auth.roles]]
name = "developer"
deny_tools = ["admin/restart", "admin/shutdown"]
[auth.role_mapping]
claim = "scope"
[auth.role_mapping.mapping]
admin = "admin"
read-only = "reader"
dev = "developer"§Enforcement
RbacService is a Tower middleware that wraps the proxy’s inner service.
On tools/call requests, it checks the tool name against the resolved role
before forwarding. On tools/list responses, it filters out tools the role
cannot access. Denied calls receive a JSON-RPC InvalidParams error with
a message identifying the role and tool.
Structs§
- Rbac
Config - Resolved RBAC rules.
- Rbac
Service - Middleware that enforces RBAC on tool calls and list responses.