mcp-tool-annotation-guard
MCP Tool Annotation Guard: least-privilege MCP tool access policy for MuleSoft Omni Gateway (PDK)
A custom policy for MuleSoft Omni Gateway that makes MCP servers least-privilege by default. It reads the safety annotations each MCP tool declares (readOnlyHint, destructiveHint), classes every tool as read, write or destructive, and lets each caller use only the tools their access level allows: Unannotated tools count as destructive, new tools are handled automatically, a tool's class can't be silently lowered (rug-pull protection), and an audit mode lets you roll out safely. Callers get higher levels from identity the gateway has already verified: JWT roles or scopes, or the client ID.
Summary extracted from the README.
MCP Tool Annotation Guard
A custom policy for MuleSoft Omni Gateway that makes MCP servers least-privilege by default. It reads the safety annotations each MCP tool declares (readOnlyHint, destructiveHint), classes every tool as read, write or destructive, and lets each caller use only the tools their access level allows:
tools/listresponses are filtered, so callers only see tools they may use.tools/callrequests are held and checked; refused calls are answered by the gateway and never reach the MCP server.
Unannotated tools count as destructive, new tools are handled automatically, a tool's class can't be silently lowered (rug-pull protection), and an audit mode lets you roll out safely. Callers get higher levels from identity the gateway has already verified: JWT roles or scopes, or the client ID.
Quick start
With an empty configuration, every caller is read-only: tools that change or delete data are hidden, and calls to them are refused. To give some callers more, add the policy after your authentication policy and set three fields. For example, with roles in a JWT verified by JWT Validation:
callerAttributes: "#[authentication.properties.claims.roles]" # where roles come from
grants: # which role gets which level
- { attribute: mcp.editor, level: write }
- { attribute: mcp.admin, level: destructive }
blockedTools: [delete_repository] # never, for anyone
Leave every other field as it is: the API Manager form starts at the safe defaults. Start with mode: audit to see what would be refused before enforcing. The Configuration doc has a Start here section and explains how the settings combine; the examples cover which setup fits you.
Platform
Built with the Policy Development Kit (PDK) in Rust, compiled to wasm32-wasip1. Requires Omni Gateway 1.11.4 or later.
Documentation
| Document | Contents |
|---|---|
| docs/overview.md | What the policy does, key features, limitations |
| docs/configuration.md | Every property, identity providers, refusals, logs |
| docs/examples.md | Configurations A–H with the tools each caller sees |
| docs/security.md | What it protects against and what not, trust model, fail-closed behaviour, logging, hardening checklist |
| docs/deployment.md | Deployment prerequisites, recommended policy order, tested chain |
| docs/faq.md | Common questions, related policies and specs |
| CHANGELOG.md | Release notes |
| SECURITY.md | How to report a vulnerability |
The docs/ files are the source of the policy's P4A catalog tabs.
Repository layout
guard-core/ Pure Rust logic (no PDK dependencies) and its unit tests
src/ PDK policy glue (lib.rs) and pdk-unit tests (test.rs)
definition/ Policy schema (gcl.yaml)
tests/ Integration tests against a local Omni Gateway (pdk-test)
mock-mcp-server/ Zero-dependency Node MCP server used by the tests
playground/ Local gateway configuration for `make run`
docs/ P4A documentation tabs
Development
Prerequisites: Anypoint CLI v4 with the PDK plugin, Rust 1.88+ with the wasm32-wasip1 target, Docker, and make. See the PDK prerequisites.
make setup # once: install PDK build dependencies
(cd guard-core && cargo test) # logic unit tests
make build # compile the Wasm policy
make test # pdk-unit tests + integration tests (Docker)
node mock-mcp-server/server.mjs # mock MCP server on :8080 (switches: top of server.mjs)
make run # policy in a local gateway (playground/config/api.yaml)
make clean # remove build output
make test and make run generate a local, disconnected registration.yaml on first use; it is git-ignored. If Docker can't be found, set DOCKER_HOST to your Docker socket (on Docker Desktop for macOS: unix://$HOME/.docker/run/docker.sock).
The integration tests run on Omni Gateway 1.13.0. To run them on another version, for example the minimum 1.11.4, set PDK_TEST_FLEX_IMAGE_VERSION=1.11.4.
Some integration tests are opt-in because they need extra setup or measure timing; run them with cargo test --test <name> -- --ignored --nocapture:
| Test | Checks |
|---|---|
latency |
Added latency on tools/call |
cache_placement |
Placement with the P4A MCP Response Cache (needs MCP_RESPONSE_CACHE_DIR, see the file header) |
log_forwarding |
Guard events reach the gateway's log forwarding outputs |
sse_server_request_first |
An SSE list whose server first sends a request to the client stalls (needs Node; see the file header) |
interrupted_lists |
A list the gateway cuts off (upstream reset, timeout) or the client hangs up on makes the guard stop trusting the catalog, and a later page trusts only its own tools again (needs Docker Desktop; see the file header) |
passthrough |
Requests forwarded without a body check carry nothing unchecked: no WebSocket upgrade, no HTTP/2 body (needs Docker Desktop and curl; see the file header) |
js_server_ids |
In front of a JavaScript server, which rounds integer IDs beyond ±9007199254740991, requests with such IDs are refused and lists stay filtered (needs Node and Docker Desktop; see the file header) |
Publishing
make publish publishes a development version (asset ID ending -dev, timestamped version) to Exchange in your configured organization; make release publishes the release version. Both first check that the built metadata declares the minimum runtime, 1.11.4; make check-min-runtime runs that check on its own after a build. See Uploading Custom Policies to Exchange.