4 min read · Technical deep-dive for developers building on MCP
A pre-action gate is an enforcement rule that intercepts an AI agent's tool call before it executes. If the tool call matches a known-bad pattern, the gate blocks it and returns a rejection to the agent. The agent then adapts its approach without ever having run the dangerous action.
Gates run at the hook layer of the Model Context Protocol (MCP). They are external to the agent's reasoning chain, which means they cannot be overridden by prompt injection, context overflow, or chain-of-thought reasoning.
| Property | Prompt Rules | Pre-Action Gates |
|---|---|---|
| Where they live | Inside agent context | External hook layer |
| Can be overridden | Yes (context overflow, reasoning) | No (runs outside agent) |
| Enforcement | Advisory | Physical block |
| Persistence | Per-session (context-dependent) | Permanent (database-backed) |
| Adapts over time | No | Yes (Thompson Sampling) |
| Explains why | No | Yes (reason chain per block) |
Gates match against the tool name and its arguments. For a Bash tool call, the pattern might match git push --force targeting main. For a Write tool call, it might match writes to .env or production.config.
{
"tool": "Bash",
"pattern": "git push.*(--force|-f).*main",
"action": "BLOCK"
}
Every gate decision includes a reasoning chain: why this pattern exists, how many times it has fired, what the original failure was. This transparency lets you audit the system and tune it.
{
"gate": "no-force-push-main",
"decision": "BLOCK",
"reason": "Force-push to main blocked",
"evidence": "User reported loss of 14 commits (2026-03-15)",
"fire_count": 7,
"confidence": 0.94
}
Not all patterns deserve the same enforcement level. Thompson Sampling uses a beta distribution to model each gate's risk profile. High-risk patterns (many failures, few successes) get strict enforcement. Low-risk patterns (rarely triggered, occasionally overridden) stay relaxed.
Pre-action gates work with any agent that supports MCP hooks:
.claude/settings.json.cursor/mcp.jsonRun npx mcp-memory-gateway init to auto-detect your agent and configure the correct hook format.
Install, give your first thumbs-down, and watch the gate auto-generate.