A security gateway for MCP tool calls, built from a paper that shipped no code, and tested with real LLM agents in the agent's seat.
MCP lets an LLM agent call tools on real systems. It reads files, queries databases and sends email. The SMCP paper (Hou, Wang et al., Feb 2026) proposes five security layers for it: a trusted registry, mutual authentication, a security context on every call, a policy engine and a signed audit log. It describes them with JSON examples. It ships no code and runs no experiments, so there was no way to know what the design actually stops.
I built all five layers as a gateway that sits in front of any unmodified MCP server, over stdio or Streamable HTTP. Then I attacked it, first with the paper's own list of 26 MCP risks, then with real LLM agents.
Registry
A YAML registry of agents, servers and tools. Each tool's name, description and input schema is pinned by SHA-256, so a lookalike or rug-pulled tool is hidden from the agent.
Handshake
Agent and gateway trade Ed25519-signed hellos and derive a session key with X25519. Every call then carries an HMAC and a strictly increasing sequence number, so a forged or replayed call is refused.
Security context
Built from delegation tokens the gateway checks itself. It ignores any chain the agent asserts, and scopes can only narrow along the chain.
Policy
Built-in checks plus YAML rules, where deny wins. Obligations redact secrets and fields and cap rows before a result reaches the agent.
Extensions
Argument guards, Ed25519-signed user approval, session flow labels and tool-description scanning. Each one is off unless configured, and each one faces variants written to beat it.
Audit
A hash-chained JSONL log with every entry signed, plus a signed checkpoint of its head, so a cut or edited log is caught.
Every SMCP field travels in MCP's existing _meta field. The gateway adds no JSON-RPC methods, and the server behind it never sees an SMCP field. Two checks use code I didn't write: the gateway runs in front of the official @modelcontextprotocol/server-filesystem with its 14 real tools, and the official MCP Inspector CLI drives it over Streamable HTTP.
The paper's design answers one question well: who is calling, on whose behalf, and may they call this tool. Forged identities, replayed sessions, typosquatted and rug-pulled tools and cross-tenant calls all get blocked.
A trusted caller doing something harmful gets through. The policy engine reads riskLevel from the calling agent, so a rule like "sensitive tools only at medium risk or below" denies an honest agent that declares high and permits a fooled agent that declares low. With real models, the paper's design stopped 1 of the 4 attacks that worked, and only because a redaction rule hid the key the model read.
The extensions take the risk level as the higher of what the agent declares and what the gateway assesses from the session, and they send high-stakes calls to the user for a signed approval.
--rescore rebuilds each table without an API call.A security review of my own extensions found gaps, and I fixed them before v0.2.
$ also matched just before a final newline. Patterns now follow ECMA-262, and the bench has a trailing-newline variant for command injection.| Result | What it measures | Source |
|---|---|---|
| 39 to 0 | Attack runs, out of 105, where an open-weight LLM agent reached the attacker's goal, with no gateway vs. with the extensions | docs/LLM_RESULTS.md, gpt-oss-120b, gpt-oss-20b and Qwen 3.8 27B on Groq, 405 runs in all. 12 of the stops rely on a simulated user who declines. |
| 33 of 105 | Attack runs that still reached the goal through the paper's own design | Same run. It stopped only tool poisoning, through its redaction rule. |
| 10 to 18 | Of the paper's 26 MCP risks, blocked by the paper's design vs. with the extensions | Scripted bench on a simulated server. With the extensions, 5 are partial, 1 is missed and 2 are not tested. |
| 30 of 30 | Normal tasks finished in every profile, with 15 approval prompts under the extensions | docs/LLM_RESULTS.md |
| 0 of 45 | Runs where the textbook "ignore your previous instructions" comment fooled a model. The same ask as a business note fooled both gpt-oss models in every run with no gateway. | docs/LLM_RESULTS.md, indirect-comment and indirect-prose |
| 1.4 ms | Median cost per call through the gateway with every extension on, against 0.04 ms for a plain MCP call | smcp-gateway bench, Apple M1, Python 3.12 |
| 136 | Tests, one of which pins every bench outcome, run in CI on Python 3.10 to 3.12 and against the official filesystem server | pytest collection, Oct 14 2026 |
39 to 0
Attack runs, out of 105, where an open-weight LLM agent reached the attacker's goal, with no gateway vs. with the extensions
docs/LLM_RESULTS.md, gpt-oss-120b, gpt-oss-20b and Qwen 3.8 27B on Groq, 405 runs in all. 12 of the stops rely on a simulated user who declines.
33 of 105
Attack runs that still reached the goal through the paper's own design
Same run. It stopped only tool poisoning, through its redaction rule.
10 to 18
Of the paper's 26 MCP risks, blocked by the paper's design vs. with the extensions
Scripted bench on a simulated server. With the extensions, 5 are partial, 1 is missed and 2 are not tested.
30 of 30
Normal tasks finished in every profile, with 15 approval prompts under the extensions
docs/LLM_RESULTS.md
0 of 45
Runs where the textbook "ignore your previous instructions" comment fooled a model. The same ask as a business note fooled both gpt-oss models in every run with no gateway.
docs/LLM_RESULTS.md, indirect-comment and indirect-prose
1.4 ms
Median cost per call through the gateway with every extension on, against 0.04 ms for a plain MCP call
smcp-gateway bench, Apple M1, Python 3.12
136
Tests, one of which pins every bench outcome, run in CI on Python 3.10 to 3.12 and against the official filesystem server
pytest collection, Oct 14 2026
I wrote both the attacks and the defenses, so this isn't an independent red team. The bench server is simulated, the approving user is simulated and careful, and the models are open-weight models on one provider on one day. With four or five trials per cell, a difference of one or two runs is noise.
Credential theft stays missed. With the agent's key, the attacker is the agent until someone revokes it. Argument guards are lexical, so a symlink inside an allowed root escapes them. The scanner looks for known markers, and text reworded to avoid them passes. The reworded variants fooled no model, so the real-model run doesn't test that gap. Streamable HTTP has no TLS, so bind it to loopback or put a TLS proxy in front.
Next project
minja-repro
An independent reimplementation of MINJA, a memory-poisoning attack on LLM agents that needs nothing but ordinary queries, plus the confidence intervals the paper left out.