Security gateway · Model Context Protocol
A multi-tenant security gateway for MCP servers.
Tool lists are text the model trusts, and a server can poison them or swap them after you approved them. Tool results are untrusted text that can carry instructions like "ignore all previous instructions". Most MCP servers are single tenant, so two customers behind one server can read each other's data.
mcp-tenant-gate fixes all three in one place, in front of servers that stay naive. One API key is one tenant.
- 20/20 attacks blocked
- 20/20 benign calls passed
- ~1 ms added, p50
- 45%of unseen injections withheld (rules alone: 23%)
- 158 tests
Scroll the figure sideways to see the upstream servers.
- can block
- can change and deliver
- lit by the last playground verdict
01 · Live
Playground
Every verdict here comes from the real gateway code, running in a Python serverless function. The upstream servers are in-process fakes: nothing is fetched and nothing is read from disk.
Paste any text as if a tool returned it. It travels the real result path for the selected tenant: size cap, cross-tenant filter, PII, injection scan.
Gateway verdict
Cross-tenant walkthrough
One naive notes server, two tenants. The upstream stores everyone's notes and searches all of them. The gateway's ownership ledger decides who sees what.
02 · Scripted
Attack suite
20 attacks against a deliberately malicious MCP server, plus 20 normal calls. I wrote these, so they show the checks work. They do not show the gate is hard to beat.
Loading the recorded run.
| # | Attack | Category | Result | Caught by | Logged | Detail |
|---|
The repo's README reports the same 20/20 with every upstream as a real MCP server over stdio. This site runs the upstreams in-process, because a serverless function cannot start subprocesses. The audit tamper attack is the log itself, so 19 of 20 are loggable.
Harder benign text
Ordinary sentences that share words with attacks, stored in a note and read back. Wrap means the text was delivered inside untrusted-data markers, not withheld. Honest caveat: these 8 were written after a first run showed 3 of them being withheld, and the rules were tightened. They are a regression set, not an unseen test.
| Text | Outcome |
|---|
03 · Recorded
Held-out eval
Recorded: deepset/prompt-injections test split, 60 injections and 56 benign rows, scored once. Rules were tuned and the classifier trained on the train split only.
| Frozen test split (Wilson 95%) | Rules only | Rules + classifier |
|---|
60 held-out injections
counts, not row order- withheld
- wrapped, delivered as data
- passed with no flag
The regex rules alone withhold about 1 in 4 unseen injections. With the small offline classifier, 45%, somewhere between a third and a half. More than half still get through unwithheld, and 14 of 60 are not even wrapped. That is why the gateway does not rely on wording: the controls that stopped all 20 attacks do not depend on it.
The playground scanner uses rules + classifier, the shipped config.
04 · Misses
What the filter still misses
The 33 held-out injections that were not withheld, grouped by hand by what the text asks for. The grouping is my judgement, so treat counts as approximate.
| Category | Misses | Wrapped / passed | What would actually help |
|---|
Isolation still holds when detection misses
A test turns the injection detector off entirely, stores all 60 held-out injections as acme's notes, plays a model that obeys them (reads another tenant's note id, spoofs owner, searches for the other tenant's secret), and checks that globex data never appears in any result. tests/test_detection_miss_isolation.py
Limit of this claim: it covers the demo notes server and two demo tenants. It shows an injection cannot cross tenants through the gateway. It does not stop an injection from changing what a model says to its own tenant.
05 · Honest
Limits
- Wording detection is weak. Rules plus the classifier withhold 45% of held-out injections. Paraphrase, role play and other languages get through. It is a cheap filter, not the defence.
- Defence in depth, not a sandbox. The gateway cannot see what an upstream does with its own credentials, network or disk. Upstreams still need least privilege.
- Not audited. Written in a few hours as a work sample. Do not put it in front of production data without a review.
- API keys only, state in memory. No OAuth, no key rotation. The ownership ledger is lost on restart, which fails closed.
- Only tools/list and tools/call are proxied. Resources, prompts, sampling and list-changed notifications are not.
What is live and what is recorded
- LIVE
- Every playground verdict and the Run the suite live button. Real gateway code in a Python serverless function, with in-process upstreams.
read_fileandfetch_urlare dictionaries of fake data, and they only run if the argument guard lets the call through. - RECORDED
- The held-out eval numbers, the error analysis, and the attack table until you press Run live.
The function is stateless. Your browser sends the ops it already ran plus a seed, and the server replays them, so note ids repeat exactly and every replayed op goes through every check again.