MoorAI runs inside coding agents on developers’ laptops. The same engine runs in front of AI apps and APIs: as a hook inside an Agent SDK service, as a decision API your code calls before a tool runs, as a proxy between an agent and its model API, as a gateway in front of remote MCP servers, and as the server Claude Enterprise’s Inference hooks call. This guide covers where each check sits, what it does, who decides what happens when it can’t decide, how to keep it out of the agent’s reach, and what has been tested with real clients.
Where the check happens
Each component runs next to the workload it protects. All of them are in the MoorAI agent, which is open source under MIT. This guide describes agent v1.17.1, released on 14 October 2026, and console v0.87.1.
| Where the AI acts | MoorAI component | What it checks |
|---|---|---|
| A service built on the Agent SDK | @moorai/agent-sdk | Every tool call, inside your service’s own process, plus its prompts and tool results. |
| Any agent framework, before a tool runs | moorai-serve sidecar | The tool call your code asks about, text to scan, and chunks about to be embedded. A localhost HTTP decision API on 127.0.0.1:8790. |
| The model API | moorai-model-proxy | What the agent sends to the model and the tool calls that come back, on 127.0.0.1:8791, for the Anthropic Messages, OpenAI Chat Completions, Gemini generateContent and Ollama native APIs. |
| Remote MCP servers | moorai-mcp-gateway | Every MCP message between the agent and the server, including each tool call and each streamed event. |
| Claude Enterprise, with Inference hooks on | moorai-inference-hook | Each governed prompt from claude.ai, Claude Code and Cowork, and each tool call frame when Validate tool calls is on, before Anthropic goes ahead. On 127.0.0.1:8792, behind your own TLS reverse proxy. |
| Every other connection | moorai-egress-proxy | The connections routed through it, against your declared egress rules. For HTTPS, host and port only: it doesn’t decrypt TLS. |
| Coding agents | Hooks | Tool calls and prompts in Claude Code, Codex, Copilot CLI, Cursor and Gemini CLI. |
Which one you need
- Your service runs on the Claude Agent SDK: the in-process hook.
- Another framework, or your own agent loop: the sidecar.
- You need to see or control what goes to the model API: the model proxy, in report-only mode first.
- Your agent uses MCP servers that run somewhere else: the MCP gateway.
- Your organization is on Claude Enterprise and an Owner has turned on Inference hooks: the Inference hooks server.
- You need the workload’s other connections held to declared egress rules: the egress proxy, with a network policy that makes it the only way out.
- Your developers use coding agents: the hooks, installed with the quick start.
They combine. A service can call the sidecar for its own tools, reach its MCP servers through the gateway and its model through the proxy. One W3C trace joins them, described below.
The Agent SDK hook: in process
For a service built on the Claude Agent SDK, @moorai/agent-sdk returns the hooks record for query(). PreToolUse returns the decision and reason MoorAI’s shell hook would give: a parity test over 214 payloads under two policy states found no mismatch. The check runs in your code path before each tool call, at a p50 of 1.99 ms on a 2 KB input, and the model doesn’t decide whether it is consulted.
import { moorAIHooks } from "@moorai/agent-sdk";
query({ prompt, options: { hooks: moorAIHooks({ serviceId: "invoice-agent" }) } })
Prompts and tool results are scanned and reported by default. prompts: "enforce" blocks a denied prompt, and toolResults: "advise" tells the model a flagged result is untrusted data. For an app that runs its own RAG ingestion, scanBeforeEmbed and guardEmbed scan each chunk before it is embedded.
The sidecar: a decision API for any framework
moorai-serve is a localhost HTTP decision API on 127.0.0.1:8790 for agent loops that are not Claude Code or the Agent SDK: the OpenAI Agents SDK, LangGraph, CrewAI or your own loop. Before your code runs a tool, it sends the call to POST /v1/tool-call and gets back the decision MoorAI’s hook would make for that call. Your code does what the answer says. POST /v1/scan scans text, including a tool’s raw result as inbound content, and POST /v1/index-scan gives one verdict per chunk about to be embedded. Verdicts never contain the submitted text, though a tool-call verdict’s message can name a file or a host from the call.
It binds loopback only, unless --allow-remote is given with a token of 16 or more characters. It refuses a non-loopback Host (421), a body that is not JSON (415) and a body over 1 MiB (413). The p50 for /v1/scan on 2 KB is 6.4 to 11 ms. A stdlib-only Python client with LangGraph and CrewAI examples is in the repository. /v1/tool-call reads paths on the sidecar’s own filesystem, so run it where the agent’s files are: in the agent’s pod or compose network, where the agent reaches it on loopback and no port is opened to the outside. The quick start’s Run it as a sidecar section has the command, the endpoints and the compose and Kubernetes examples.
What both in-process forms share
The SDK and the sidecar run the same engine and policy as the hook, with server mode’s rules: an “ask” has no one to answer it and is denied, the actor is the workload rather than a person, declared workload profiles are evaluated, and reports are content-free. Some controls need the whole session and are not evaluated in process: the circuit breaker, session risk, deletion volume, intent alignment, learned drift, MCP reputation, model escalation, honeytokens, the mask rewrite and the check of the agent’s own environment for a proxy or CA override. Each result lists them in notEvaluated. Neither form records the allow trail.
The model proxy: between the agent and its model API
moorai-model-proxy listens on 127.0.0.1:8791 with four default routes: /anthropic, /openai, /gemini and, on a loopback bind only, /ollama (Ollama’s API is unauthenticated, so a remote bind drops that route). The agent points its model SDK’s base URL at the proxy, and the proxy forwards each call to the provider. It scans what the agent sends: the prompt and system text, and the tool results and documents fed back, where indirect injection shows up. It decides every tool call in the model’s response before the agent framework receives it, with the decision the sidecar would make, whether or not your code asks the sidecar. The client’s own API key goes upstream untouched and is never logged, stored or reported.
Four parsed APIs
- Anthropic Messages, JSON and streamed.
- OpenAI Chat Completions, JSON and streamed. A local OpenAI-compatible server (Ollama, LM Studio, llama.cpp or vLLM) is a route to its loopback
/v1endpoint, read by the same parser. - Gemini
generateContentandstreamGenerateContent, chosen by path, so the Gemini API and Vertex AI publisher-model endpoints are both covered. EachfunctionCallpart is judged like any other tool call. - Ollama’s native
/api/chatand/api/generate, JSON and the NDJSON stream Ollama sends by default. A streamed turn is held from its first tool-call line to its finaldoneline.
Everything else is forwarded unparsed and unchecked: the OpenAI Responses API, embeddings, Amazon Bedrock, Gemini’s Interactions and Live APIs, and Vertex AI partner models. Assistant turns, images, base64 PDFs, tool definitions and server-side tool blocks are not scanned. The proxy covers only traffic that goes through it: it doesn’t intercept TLS, so an SDK pinned to the provider’s HTTPS URL bypasses it.
Report-only, then enforce
- Report-only by default. Requests and responses pass through byte-identical, streaming included, and MoorAI reports what it finds after the response is delivered. The added p50 latency is about 0 ms.
- Enforce mode. The proxy refuses a request that policy denies, before the provider sees it, in the provider’s own error shape. It refuses content it can’t fully evaluate. A response with a denied tool call is refused whole; in a stream, the tool call’s events are held until it is complete, then released byte-identical or replaced by the provider’s error event. As an opt-in (
--denied-tool-call replace), the proxy delivers that turn with every tool call withheld and a refusal in their place, so the agent gets a complete turn that ends in text and nothing from it runs. - One limit of streamed enforcement. In Anthropic streams a tool call is held one block at a time, so an allowed call that comes before a denied one in the same turn has already been released when the turn is refused.
Business actions and function names
Plain function calls are classed by the words of their name: money (issue_refund, transfer_funds), bulk data (export_customer_data_any), identity (reset_password, grant_admin_role), destructive (drop_table, purge_records) or delegation (accept_handoff). Lookups such as get_refund_status are not. Every class alerts by default, and a signed policy sets each one to allow, alert, ask or block. A rule in functionToolActions that names the function itself, exactly or by prefix, wins over its class. Alerts carry the class and the function name, never an argument. Classes come from names, so purge_cache counts as destructive and create_agent as delegation: under the default that costs an alert, under block a call.
Your own system prompt
The application’s own system prompt (Anthropic system, OpenAI system and developer, Gemini systemInstruction, Ollama system messages) is judged like any request content, because a client controls its own system role: personal data or a secret moved there is blocked or asked about per policy. As an opt-in, set only in the verified signed policy or the root-owned admin binding, operatorContext with privacy: "report" makes personal-data findings there report-only. Secrets and every finding that isn’t about data, such as prompt injection, a reverse shell or system-prompt extraction, are still decided as in a user turn. Ollama’s /api/generate prompt counts as the user’s, because the proxy can’t split one string by author.
Decoy keys
With decoyKeys set to place them in a verified signed policy, MoorAI writes three never-issued AI keys, in provider key shapes, into new files that key harvesters sweep and no tool loads. The model proxy checks every request header value, the query string and the body for them, and refuses a match with 403 in report and enforce mode alike. The Critical alert carries the decoy’s id and where it was found. A decoy that is re-encoded before use (base64, split, reversed) isn’t matched.
Placeholder credentials, opt-in
The agent holds a placeholder instead of the API key. The proxy, running as another user or in its own container, swaps the real key in only on the route the placeholder is bound to, refuses any other use of the placeholder, and masks a key the upstream echoes back. A raw key in a credential header or in the ?key= query string is alerted once per route, and refused with --require-placeholders. The MCP gateway has the same mechanism. It doesn’t protect a key the agent can read itself or use on another path, and the agent can still use the placeholder through the proxy, so policy decides what goes through.
One trace, and a record of each model call
Every agent session is one W3C trace. The model proxy learns the session from Claude Code’s X-Claude-Code-Session-Id header and sends traceparent and tracestate on to the provider; a valid incoming traceparent always wins. Its alerts carry traceId, spanId and parentSpanId, so the console’s trace view and an OTLP backend can join an agent action, the model call it made and the MCP call that followed. Only hex ids and an agent name leave, and the proxy adds about 2 to 4 µs per request. Session ids the proxy sees are caller-asserted: a process that can reach it can put its requests in another session’s trace, though it can’t change that session’s hook records.
With the allow trail on (actionTrail: "allowed" in the signed policy), the proxy also queues one content-free record per forwarded model request, with its provider, model and trace fields. Console v0.87.1 does not store these records: its allow trail accepts tool-call records only. In the console a model is named by the proxy’s alerts, and the runtime AIBOM shows model calls that raised no finding as not measured.
What has been run
Response-side enforcement is tested against a fake provider, and Gemini against a fake upstream only. Ollama’s native API was measured live against Ollama 0.15.6 (mistral-nemo) in enforce mode: the allowed call was released and the denied one refused, JSON and streaming. The proxy hasn’t been run with the providers’ own SDKs or against a real hosted provider, which is why report-only is the place to start.
The MCP gateway: in front of remote MCP servers
moorai-mcp-gateway is an HTTP MCP guard. The agent connects to the gateway, and the gateway connects to the remote server. It applies the stdio MCP proxy’s tool-call and tool-result checks, and every message passes through these as well:
- Staged validation. Each message is checked in order: JSON, JSON-RPC, structure, method, protocol version, schema. A malformed message is refused with
SCHEMA_INVALID. - One value per key. JSON with a repeated key, or with envelope or params keys that differ only in case, is refused. The value MoorAI checks is the value the server runs.
- Every streamed event. In an SSE response, every event is scanned.
- A size cap. A response, or one SSE event, over 4 MiB is refused with
RESPONSE_TOO_LARGE. - Workload profiles. A declared workload profile is enforced on every
tools/call. - Vector-store writes. A recognised vector-store write tool has its arguments scanned before the call is forwarded.
- Per-tool usage. The gateway posts daily call counts per tool to the console, names and counts only, which the console’s MCP map shows.
- Trace context. It sends
traceparentandtracestateupstream. It knows no session, so its spans start their own trace unless the client sends atraceparent. - An optional cool-down. A per-client cool-down (
CLIENT_COOLDOWN) is available and off by default.
A tool call that policy denies is refused at the gateway and doesn’t reach the server; it comes back to the client as an MCP tool result marked as an error. The headers of both MCP spec eras pass through. The gateway adds about 4.7 to 5 ms at p50 against an in-process fake upstream. It doesn’t judge egress rules. For the wider question of trusting MCP servers you don’t run, see MCP security.
The Inference hooks server: for Claude Enterprise
Inference hooks are a Claude Enterprise beta. Once an Owner turns them on, Anthropic sends each governed prompt from claude.ai, Claude Code and Cowork to the organization’s server, and, with Validate tool calls on, each tool call frame as well. Anthropic holds the request until the server answers allow or deny. moorai-inference-hook is that server.
- Verification. Requests are signed per Standard Webhooks. The signature is checked in constant time against every configured secret, so the previous and the current secret both work during a rotation. A timestamp more than five minutes off is rejected, and so is a request id already accepted. The secret comes from a file or the environment, never from a command-line value.
- Judging. The verdict comes from the same runtime as the sidecar: the verified console policy, the root-owned system config, and the headless rule that turns an “ask” into a deny. User text, tool results and attachment text are each judged at their own stage. A tool call frame is judged by its content only (the shell command, the URL, or else the argument JSON), because the tool runs on the user’s machine. A deny reason names threat ids and categories, never the content.
- When it can’t judge. An item past the scan cap, the evaluation timeout or an engine error is decided by
--fail:open, the default, answers allow, which matches Anthropic’s own default failure handling;closedanswers deny.--shadowalways answers allow and reports what it would have denied. - Alerts. Alerts are content-free. Each carries the reference id returned to Anthropic, which joins to the denied record in Anthropic’s Activity Feed. The transcript, email addresses and actor ids are never sent.
- Exposure. The server binds
127.0.0.1. Anthropic calls only anhttps://URL on port 443 with a publicly trusted certificate, so TLS is terminated by a reverse proxy on the same host.
A Read of a credential file, MCP file arguments and local secret egress are not judged here, because those files are not on this server. Field names may change during the beta.
When a check can’t decide
A check can fail to reach a decision: its engine throws, it runs past its time budget, or the content is past a scan cap. The administrator decides what happens then, per surface, in the signed console policy or the root-owned admin binding. The user can’t.
{ "failMode": { "default": "open", "modelProxy": "open", "mcpGateway": "closed", "inferenceHook": "closed" } }
| Surface | Own default | Set to closed |
|---|---|---|
| Model proxy | Enforce mode refuses, report mode forwards | Content it can’t judge is refused. In report mode, only request items past a cap, which are known before forwarding. |
| MCP stdio guard and HTTP gateway | Open: forwarded unchanged | A tools/call it can’t evaluate gets an error result and the server never receives it; a tool result whose scan failed is replaced by an error result. |
| Inference hooks server | The operator’s --fail flag, open unless set | The server answers deny. |
The admin binding wins, then the signed policy, then the surface’s own default. No environment variable, settings file or user-scope file is read, so nothing the agent can write turns a closed surface open. Each fail-closed refusal raises one content-free FAIL_CLOSED alert naming the cause and where the setting came from. Logging, inventory and telemetry always fail open.
Keep them out of the agent’s reach
A guardrail the agent can edit isn’t a guardrail. The container image ghcr.io/gitayg/moorai-server holds the server commands (moorai-serve by default, and moorai-mcp-gateway, moorai-model-proxy and moorai-egress-proxy), for amd64 and arm64, and runs as a non-root user (uid 1000). Run them in their own container and the agent process can’t edit their policy or files. Alerts from the sidecar, the gateway, the model proxy and the Agent SDK carry the workload’s container id and, when set through the Kubernetes downward API, its pod, namespace and node, so a SIEM can join MoorAI verdicts with host and container sensor events.
Routing is the other half. When your network policy forces the workload’s model and MCP traffic through the proxy and the gateway, the agent can’t route around them. The restriction is your own network policy. MoorAI’s Kubernetes and compose examples show one: the model proxy, the MCP gateway and moorai-egress-proxy run in their own pod, and the agent’s network reaches only that pod and cluster DNS. The egress proxy enforces your declared egress rules on every other connection the agent opens. It doesn’t decrypt TLS, so for HTTPS it judges host and port only.
For coding agents on servers and in CI, MoorAI’s hooks sit in Claude Code’s system-wide managed settings, which a repository can’t switch off. On a laptop the hook runs as the developer, so disabling it is detected, not prevented: an enrolled device sends a daily coverage heartbeat, and the console raises “agent active, no MoorAI hook traffic”. The full breakdown of what is prevented, what is detected and what is out of scope is in tamper resistance and the FAQ.
What leaves your environment
Prompts, code, files and secrets are checked where the agent runs. They aren’t sent anywhere to be checked. The console receives content-free signals about what fired, not the content that fired it, and trace fields are hex ids. Trust lists what leaves and what stays.
Evidence of what entered the context
Where the Claude Code hook runs, including claude -p in CI and an Agent SDK service that loads the shell hook from its settings, MoorAI keeps a per-session Merkle tree of what entered the agent’s context (context.tree): one content-free leaf per prompt, file read, web result, MCP result, command output and sub-agent hand-off. Every record carries the tree’s root, and an injection alert names the leaf whose content triggered it, so moorai-context-proof --verify finds which session took in a given file. With contextTree: "console" the leaves also go to the console, which re-verifies each record’s root and offers a patient-zero lookup by SHA-256. The in-process SDK, the sidecar, the proxies, the gateway and the Inference hooks server keep no tree. The tree is tamper-evident, not tamper-proof: it lives where the agent can write.
What was tested
On 2026-10-06, on macOS, four real MCP clients ran through MoorAI’s stdio MCP proxy and its HTTP gateway, in front of a test MCP server:
- Handshake and tool list. Claude Code 2.1.284, cursor-agent,
@modelcontextprotocol/sdk1.32.1 and MCP Inspector 2.9.0 each completed the handshake and listed the server’s tools through both. - Real tool calls, no model. The SDK and the Inspector each made a benign tool call and a denied one. The benign call was forwarded. The denied call was refused and never reached the server.
- Live model runs. Three
claude -pruns: a benign call over stdio and one over HTTP were forwarded and recorded, and a call with a policy-denied argument over stdio came back to the model as MoorAI’s refusal and never reached the server.
Beyond those runs:
- A real remote MCP server. The gateway ran in front of an AppCrane MCP endpoint over Streamable HTTP: initialize, a tool list of 62 tools and a read-only tool call passed through intact, and a malformed message and an over-cap response were refused.
- Gateway usage, end to end. Against a real local console, six calls arrived with exact per-tool counts and no argument text.
- A real local model server. The model proxy’s Ollama native parsing, live against Ollama 0.15.6, as above.
- Server mode. One live
claude -prun (Claude Code 2.1.284) with server mode from the environment: the hooks fired, a.envread was denied as a headless ask, and the console received content-free reports under the workload identity. - Kubernetes. The sidecar manifest runs on a local kind cluster (Kubernetes v1.37.0): both Deployments reach Ready on their exec probes, and the demo agent’s alerts carry pod, namespace and node.
Not tested
Claude Desktop, VS Code and the Cursor desktop app. Windows and Linux for the real-client runs. OAuth discovery through the gateway. A real client and a real remote MCP server in the same run. A live, model-driven denied call through the gateway. A completed session on the 2026-07-28 MCP revision with a real client. The model proxy with the providers’ own SDKs or a real hosted provider; Gemini has run against a fake upstream only. The Inference hooks server against Anthropic’s live service: it has been tested only against signed sample frames built from Anthropic’s published schema. An Agent SDK service or a GitHub Actions run watched end to end, and the Python sidecar examples, which have not been executed. CRI-O, a managed cloud cluster, and the amd64 image run on a host.
Questions to ask of any guardrail
Whichever product sits in front of your AI app, these questions separate a check from a log line:
- Where does the check run? In your environment, or in the vendor’s cloud with a copy of your prompts and code?
- Is a denied call stopped before it reaches the server, or recorded after it ran?
- Which model APIs does it parse, and which does it forward unchecked?
- What happens when it can’t decide? Ask who chooses between failing open and failing closed, per surface, and whether the agent can change it.
- Can the agent switch it off? Ask what is prevented, what is only detected, and on which kind of machine.
- Can the agent route around it? If the answer depends on your network policy, that should be said.
- Which real clients was it tested with, and which were not tested?
MoorAI is open-source (MIT) runtime guardrails for AI agents, apps and APIs. Every rule is mapped to the OWASP LLM, Agentic and MCP Top 10s, MITRE ATLAS and MITRE ATT&CK v20 in the threat rule-base. See also: Run it as a sidecar, MCP security, and The layer above the model.