MCP Governance Example
This example puts CapFence between an agent and an MCP server so MCP tool calls are authorized before they reach the upstream server.
Gateway
from capfence.mcp.gateway import MCPGatewayServer
gateway = MCPGatewayServer(
upstream_command=[
"python",
"-m",
"mcp_server_filesystem",
"/tmp",
],
policy_path="policies/mcp_filesystem.yaml",
)
gateway.run()Policy
# policies/mcp_filesystem.yaml
deny:
- capability: filesystem.delete
- capability: filesystem.write
path_prefix: /etc
require_approval:
- capability: filesystem.write
path_prefix: /var
allow:
- capability: filesystem.read
- capability: filesystem.listDecision flow
Agent → CapFence MCP Gateway → MCP Server
│
├─ allow read/list tools
├─ require approval for sensitive writes
└─ deny destructive filesystem toolsOperational use
Use this pattern when a model can discover and call tools from an MCP server but you still need infrastructure-grade authorization at execution time.