Guide 27 of 61 · Protecting secrets and data
Contain prompt injection in MCP tool output
Strip hidden text from MCP tool results, hold back poisoned tool descriptions, pin tool definitions, and limit what a hijacked agent can do next.
Built, not yet claimed preview: this guide describes a package that has not passed its release gate.
Have the MCP gateway strip what renders as nothing from tool results, hold back tool descriptions written to steer the model, pin each tool's definition so a changed one is caught, and write flow rules that stop a hijacked agent from sending a secret it read. AgentGarm does not claim to catch every injection: visible text in a result reaches the agent, so the rules on what it may do next are the part that holds.
1. Know what is checked, and where
Runtime checks on tool output happen in the MCP gateway, so they cover only servers that run through it: set that up first. The gateway treats two kinds of text differently. Metadata (tool and prompt descriptions, input schemas and server instructions) is what a server uses to steer the model, so a suspicious entry is held back. Data (tool results, resource contents and prompt messages) is what the agent asked for, so it is never held back or reworded: it only loses characters that render as nothing.
A web page or file the agent reads with its own tools does not pass through the gateway and is not read for injection. The files agents load at start (CLAUDE.md, rules, MCP configurations) are a separate scan, in the guide on poisoned configs.
See also
Catch poisoned agent configs before launchScan the instruction, settings, hook, plugin and MCP files your agents read for hidden text and auto-approval switches, and gate CI on the result.
2. Let the gateway clean tool results
In every result and error the gateway relays, each text, description and title string loses terminal escape sequences, control characters and hidden characters: Unicode Tags, runs of variation selectors, zero-width characters and bidi overrides, the ways an instruction is hidden from a person but read by the model. Legitimate uses are kept, such as the joiner in an emoji sequence, Persian and Arabic joiners, and right-to-left marks. Nothing else changes, and a rewrite is logged rather than recorded as an event. An instruction written in plain, visible words in a result reaches the agent as written.
3. See poisoned tool descriptions held back
Every tools/list and prompts/list reply, and the server's instructions, pass the filter before the agent sees them. A tool or prompt is dropped from the list when its text hides characters, tells the agent what to do (injection.imperative, including line-jumping phrases such as “before using any other tool”), names a credential file such as ~/.ssh (mcp.secret_path), asks for the user's password or token (mcp.credential_solicitation), gives orders about another tool (injection.cross_tool), claims to replace a built-in (injection.tool_shadowing), or has a name mixing Latin with Cyrillic or Greek letters (text.mixed_script).
Each held-back tool is recorded with its detector ids and a hash of its definition, never its text. The dashboard's MCP screen lists them under its Tools tab, per task. The detectors are heuristics: a poisoned description in other words passes, and a server whose tool legitimately names a key file is held back, with no per-server exception yet.
agentgarm ui --open4. Pin tool definitions
agentgarmd keeps a hash of each tool's definition the first time the gateway offers it, per user, server version and tool, so a server that changes a tool after you trusted it is caught. Under security_boundaries.mcp, pin_tool_definitions sets what a changed definition does: alert (the default) records it and allows the tool, block quarantines it, and off keeps no pins. quarantine: strict goes further: every tool seen for the first time is quarantined until approved, a changed one always is, and a description naming a configuration location such as ~/.aws is held back too.
A quarantined tool is dropped from the list, and a call to it is refused before the server sees it. In audit mode pins are kept and changes recorded, but every tool is allowed. If the pin store or agentgarmd cannot be reached when a list arrives, the list is refused (fail closed, enforced by agentgarm-session). Lint the policy and restart agentgarmd to load it.
pin_tool_definitions: alert
quarantine: strictagentgarm policy lint ~/.config/agentgarm/agents.d/claude-code.yaml5. Approve a new or changed tool
On a root install with a presence key, the quarantined tools of one list become a single approval request: “Allow new or changed tool definitions of MCP server” with the server's id and the tool names. Approve it in agentgarm presence watch within its 30 seconds, and the agent sees the tools at its next tools/list. The record holds the two hashes, not the text, so read the server's release notes before you approve. A no-root install has no presence boundary: a quarantined tool stays quarantined until the policy changes.
agentgarm presence watchSee also
Approve risky actions with Touch IDEnrol a Touch ID key on your Mac and approve each command your policy asks about with your fingerprint, for that one call only.
6. Limit what a hijacked agent can do
Since visible text gets through, write rules for what an agent does after reading it. flow_rules look at the classes of what the task tree did earlier, MCP calls and hooked commands together: with the rule below, a secret read followed by anything that reaches the network (an MCP tool classed network_egress, a curl, a git push or Claude Code's WebFetch) is denied. Flow rules need the task's history, which only an agent started with agentgarm run has; a session governed by hooks alone keeps none, so they do not fire there. The gateway also scans results for secrets under dlp.on_secret, and an ask rule puts a person in front of a risky call.
flow_rules:
- id: no-exfil
deny: { after: secrets_read, tools: [network_egress] }See also
Keep secrets and card numbers out of promptsSee which credentials your agent sends its model provider, have the proxy replace them with cache-safe placeholders, and deny tool calls that carry one.
7. Know what it does not catch
The gateway rates MCP C on every platform and install until its configuration custody is proven by a live run. Outside the strict profile, a description poisoned from the first time it is seen is pinned as trusted. Resource descriptions, the text of a server's own requests, notifications, structuredContent and _meta are not cleaned, and a result over 4 MiB streams through unrewritten. None of this detects every hijack: it removes hidden instructions and narrows what a steered agent can reach.
agentgarm statusSee also
Check that protection is onSee whether AgentGarm's services are up, what assurance level each agent session has and why, and what to do about a bypass alert.