Wrap your MCP client session. Every tool call gets evaluated before it reaches the server.
- AncilisMiddleware wrapping an MCP client session
- Tool discovery and automatic registry (OBSERVED/APPROVED states)
- Allowed tools passing through with evidence recorded
- Unauthorized tools blocked in enforce mode
- Same scenario in audit mode — failures logged, nothing blocked
- The
get_summary_line()output your agent framework can surface
pip install "ancilis[mcp]"This example uses a mock MCP session — no real MCP server needed.
cd examples/mcp-middleware
python run.pyagent:
name: mcp-demo-agent
security:
mode: enforce
tools:
allowed:
- get-status
- get-transactions
blocked:
- delete-database=== Enforce Mode ===
Config: get-status and get-transactions allowed, delete-database blocked
Discovered 4 tools from MCP server
Tool registry:
get-status: approved
get-transactions: approved
send-email: observed
delete-database: observed
1. Calling 'get-status' (allowed)...
Result: All systems operational.
Decision: ALLOW
2. Calling 'get-transactions' (allowed)...
Result: Transaction #1: $42.00 at Merchant A
Decision: ALLOW
3. Calling 'send-email' (not in allowed list, enforce mode)...
BLOCKED: Ancilis [blocked]: Tool 'send-email' blocked — scope enforcement, tool provenance check.
To approve: ancilis approve-tool send-email
To review: ancilis status
4. Calling 'delete-database' (explicitly blocked)...
BLOCKED: Ancilis [blocked]: Tool 'delete-database' blocked — scope enforcement, tool provenance check.
To approve: ancilis approve-tool delete-database
To review: ancilis status
Ancilis: 4 tool calls evaluated. 2 issues. Run `ancilis status` for details.
=== Audit Mode ===
Same tools, same calls — but mode is audit (log everything, block nothing)
Calling 'send-email' (not in allowed list, audit mode)...
Result: Email sent to [email protected]
Decision: ALLOW
Mode: audit
Failures logged: ['PR-02', 'PR-03']
Calling 'delete-database' (explicitly blocked, audit mode)...
Result: Database dropped.
Decision: ALLOW
Failures logged: ['PR-02', 'PR-03']
Ancilis: 2 tool calls evaluated. 2 issues. Run `ancilis status` for details.
Done. Same policy, two modes. Enforce blocks. Audit logs.
- Middleware auto-discovers tools from the MCP server via
list_tools() - Tools in
security.tools.allowedare registered as APPROVED - Other tools are registered as OBSERVED (discovered but not yet approved)
- In enforce mode: unapproved tools are blocked before reaching the server
- In audit mode: same evaluation happens, failures are logged, but the call goes through
- Every evaluation produces a hash-chained evidence record
- The
get_summary_line()gives your agent framework a one-liner to surface
The only difference is one config field: security.mode.
- audit (default): Evaluate everything, log everything, block nothing. Use this when onboarding.
- enforce: Evaluate everything, log everything, block violations. Use this in production.
Both modes produce identical evidence records. The mode field in each record shows which was active.