Over about six weeks I shipped three authorization fixes across my own MCP infrastructure. Two were CWE-285, improper authorization: a permission check that existed and did not run. The third was not a vulnerability at all, and I am including it anyway, because when I lined the commits up they had the same shape.
In each case I had written a permission check. In each case the check was real, tested, and correct. And in each case there was a second path to the same capability that never touched it.
The threat model, since everything below depends on it: I run coding agents (Claude Code, Codex) as daily drivers on my own machine and on Kubernetes, with access to MCP servers that can write to my task system, send email, spawn other agents, and drive a browser. The adversary I care about is not a stranger on the network. It is my own agent, steered by a prompt injection in something it read, using tools it was legitimately handed. I have written before about getting OAuth onto those servers, and that all still holds. It is also not this problem. Authentication answers who is calling. Every bug below happened downstream of a correctly authenticated caller.
The argument I want to make is that MCP authorization is not one boundary. It is several planes that each have to be gated separately, and the protocol gives you no help noticing you have covered one and missed another.
Plane one: execution was gated, transport was not#
My agent-framework package has a permission model with READ, WRITE, SEND, DELETE, and ADMIN levels. Each tool declares the levels it requires at registration; check_tool_permission(tool_name, caller_permissions) returns whether the caller satisfies them and, if not, which are missing. It worked. Agents calling tools in-process went through it every time.
Then I checked what happened when the same tools were exposed over stdio MCP.
MCPServerBase.call_tool looked up the handler by name and awaited it. The name lookup was the entire check. Any stdio client that finished the MCP handshake could invoke delete_memory, send_email, or run_claude_code regardless of the permissions in its context, because the permission model was enforced by the Agent class and the MCP server was a second door into the same handlers.
PR #3642 added an optional context_factory to MCPServerBase: a callable the server author supplies at construction, which returns the ExecutionContext for the caller currently being served. Dispatch now runs the check before the handler:
try:
context = self._context_factory()
except Exception as exc:
raise ContextFactoryError(
f"context_factory raised while enforcing permissions for {name!r}"
) from exc
allowed, missing = check_tool_permission(name, set(context.permissions))
if not allowed:
missing_names = ", ".join(sorted(p.name for p in missing))
raise ToolPermissionError(
f"Permission denied: {context.caller.name} lacks required "
f"permission(s) for tool {name!r}: {missing_names}"
)
The fix is optional and defaults to off. Making it mandatory would have broken every server in the fleet that had not yet been given a factory, so this was the right migration decision and it is the wrong steady state, for reasons I will own up to at the end.
The mistake underneath was believing "the permission system" was a property of the code, when it was a property of one call path through the code.
Plane two: execution was gated, discovery was not#
Once call_tool enforced permissions I considered tool authorization solved, for about two weeks. list_tools was still returning everything.
A read-only caller would get correctly denied at dispatch on delete_task, and would still see delete_task in the catalog, with its description and full JSON input schema. Same for every admin tool on the server.
The obvious response is that this is information disclosure about tools the caller cannot invoke anyway. I think that undersells it. An MCP tool listing is a machine-readable map of a backend: the names of its privileged operations, their argument shapes, the enum of statuses it recognizes, the fields on its internal models. If you are working out what a service does before attacking it, tools/list is a better artifact than most internal documentation, and it was being served to anyone who completed a handshake.
The fix in #4196 routes discovery through the same predicate as dispatch:
context = self._context_factory()
caller_permissions = set(context.permissions)
return [
Tool(
name=tool_info["name"],
description=tool_info["description"],
inputSchema=tool_info["input_schema"],
)
for tool_info in self.tools.values()
if check_tool_permission(tool_info["name"], caller_permissions)[0]
]
One if. The interesting part is not the code. I had written check_tool_permission months earlier and used it correctly at dispatch, and still did not think of discovery as a place where authorization applies, because discovery does not feel like an action. It feels like metadata, so it gets built as a serialization concern, in a different function, by someone not thinking about permissions at that moment.
Plane three: every server gated it, and one copy drifted#
The third is less dramatic and probably more common in real fleets.
I run several small MCP resource servers (reddit, x, bluesky, an agents gateway). Each needs to attach a required-scope check to its tool functions at import time, before the settings object that names the scope has been constructed, so each had a small adapter that defers reading the scope until the tool is actually called. Each server had its own copy of that adapter. Three of the four were identical apart from one word in a docstring.
The fourth had drifted. bluesky-mcp reimplemented scope enforcement from scratch instead of copying the adapter, and on a scope failure raised a bare PermissionError. Its siblings returned a structured insufficient_scope response. The framework's generic tool handler caught the bare exception and flattened it into an opaque create_post API error.
That is not a bypass, and it is worth being precise rather than dressing it up: the call was still denied. What broke was the agent's ability to tell "you lack a scope, go request it" from "Bluesky is down, retry later." An agent that cannot distinguish an authorization failure from an upstream failure will retry the authorization failure. PR #6300 deleted all four copies for one shared helper in the framework and made bluesky return what its siblings return.
The pattern, and how far it generalizes#
Three bugs, one shape: a capability reachable through more than one plane, gated on the plane I happened to be thinking about. Execution is one plane. Discovery is a second. Transport is a third, since the same handler reached in-process and over stdio is two doors. Implementation is a fourth, once the same policy is written out separately in each of several servers.
I want to be careful about how much of this I blame on MCP, because two of the four are generic. A second entry point into shared handlers is an old bug. N drifted copies of a policy adapter is an older one. Neither needed a new protocol to happen.
The list-versus-call split is the one with a protocol flavor, and even it has an ancestor: a REST index endpoint that returns rows its detail endpoint would refuse. What MCP adds is scale and framing. Every server publishes a complete, structured, self-describing catalog of its privileged operations as a first-class protocol operation, and the spec presents advertisement and invocation as different kinds of thing. Nothing says they must agree. So the honest version of the claim is not that MCP invented this failure, it is that MCP hands you an unusually rich disclosure surface and no conformance pressure to gate it.
I also do not think more careful review fixes any of it. I reviewed all three.
One choke point instead of four#
So I moved enforcement out of the servers and into a broker.
Every agent session now points at the broker instead of at upstream servers. The broker terminates MCP rather than forwarding it opaquely: it parses initialize, tools/list, and tools/call as protocol operations and answers them itself, which is what lets it filter a tool list and refuse a call. An opaque reverse proxy (which is what I had before) can only pass bytes through, so it can authenticate a connection and nothing finer.
The broker holds the upstream OAuth credentials, and the agent does not have them; that is what keeps the agent on the broker rather than dialing nexus directly. A session is minted by an admin command, bound to a profile at mint time, and identified by an opaque mcp_sess_<...> bearer token stored only as a SHA-256 digest. Profiles are evaluated against canonical <server_id>.<tool> names. The evaluation core from #4546 has no database in it:
def evaluate_tool_rules(
tool_name: str,
*,
allow: Iterable[str],
deny: Iterable[str],
fail_open: bool = False,
) -> bool:
if matches_any(tool_name, deny):
return False
if fail_open:
return True
return matches_any(tool_name, allow)
Deny is checked first and short-circuits, so deny beats allow. With fail_open unset, the absence of a matching allow is a deny, which means a new tool appearing on an upstream server stays invisible until a rule names it. That is the property I care about most. When an upstream adds a tool, the failure mode is that my agents cannot see it.
matches_any uses fnmatch.fnmatchcase rather than plain fnmatch, which normalizes case per host OS and would make an authorization decision platform-dependent.
Above the globs is a coarser gate. A profile names a set of servers, and membership is checked before any pattern matching, so a tool whose server_id is not in the profile's list is denied before its allow rules are consulted. A name that does not parse into <server>.<tool> at all is denied rather than raising. This is what bounds the one deliberately fail-open profile, personal-trusted, whose allow list is * but whose server list is three entries long.
One wrinkle worth naming because it confused me while writing this: on a fail-open profile the allow list is never read at all, since fail_open returns before it. So personal-trusted's allow_tools: ['*'] is documentation, not mechanism. The seed loader still rejects a bare * allow unless fail_open: true is set on the same profile, which sounds circular and is not: the check exists so that nobody can write the * that looks like allow-all without also writing the flag that actually is.
The list is advertisement; the call is enforcement#
Here is where the discovery bug gets its real resolution, and it is not the one I expected.
The broker filters tools/list per session, which handles the disclosure problem from plane two. But filtering the list turns out to buy almost nothing as enforcement, for an empirical reason. When a session's policy changes, MCP says to emit notifications/tools/list_changed. I checked whether the two clients I actually use react to it. Codex does not: its SDK's on_tool_list_changed handler is a no-op, and a live test against an instrumented server confirmed no tools/list follows the notification. For Claude Code I have documentation claiming support and open issues reporting it does not refetch, but I could not run the live test from inside an already-running session, so that half is unconfirmed rather than measured.
Even on n=1 confirmed, the design consequence is the same: I cannot rely on a client noticing that its list went stale. A client can invoke a tool by a name it was never shown, or one it was shown ten minutes ago before a grant expired. So tools/call re-reads policy on every call and re-authorizes from scratch, and a tool that was visible at list time and is not allowed now is rejected now.
That reconciles the tension I set up earlier. Filtering tools/list is worth doing, and what it buys is exactly the thing I argued for in plane two, which is not leaking a map of the backend to under-permissioned callers. It is a disclosure control. It is not a gate, and it cannot be made into one from the server side, because the client is free to ignore every signal you send it. The gate is at the call.
The boundary that isn't code#
The broker lets an agent ask for more. capabilities.list_requestable returns a catalog of admin-authored capability bundles; permission_request.create files a request against one. Grants are TTL-bounded (two hours for browser automation, thirty minutes for task writes, fifteen for anything touching stored credentials). The agent can request. The agent cannot approve.
Enforcing that second half is where it stops being a matter of writing a check.
An enterprise gateway enforces request-versus-approve by identity: the agent's service account cannot call the approve endpoint. That does not work here, because the agent runs as me. Same uid, same shell, same home directory. I considered a separate agent user and rejected it, so there is no uid boundary to hide behind, and an identity check is a question with no useful answer.
What is left is human presence. The broker runs as a dedicated mcp-proxy system user with its policy DB and token store under /var/lib/mcp-proxy at 0700, so the agent uid cannot rewrite its own grants. Admin commands go over a Unix socket at /run/mcp-proxy/admin.sock, group mcp-admin, with no admin token anywhere: authorization is the socket's ownership and mode, specifically so that no secret has to live in an environment variable or a command line the agent can read. Approval requires a TOTP code from a seed at /var/lib/mcp-proxy/totp.seed, owned by mcp-proxy at 0600 inside a 0700 directory.
Two details there are load-bearing.
The gate is enforced in _insert_grant, at the moment a grant row is created, rather than in each approval surface. There are three surfaces (the CLI, a local web form, and MCP elicitation) and a fourth will exist eventually. Putting the check at the single point they all funnel through means the fourth one cannot forget it.
And the elicitation surface is the reason a code is required rather than a click. An elicitation response arrives back through the agent's own client process. action: "accept" on that channel is not evidence that a human decided anything; it is evidence that something in the agent's process said the word accept. The six digits are the part the agent cannot produce.
I wrote a probe that attacks this from the strongest position an agent actually holds here rather than a weakened one: my uid, in mcp-admin so the socket is reachable and every admin verb is available, repo checkout writable so it can edit and run broker source in its own tree (which buys it nothing, since the running service loads from a separate deploy checkout at /opt/mcp-proxy/infra that the agent uid cannot write), holding a live session token. It cannot approve. Every path that mints a grant refuses without a code, brute force freezes the approve path after five failures in five minutes, and codes are single-use with the last-used step recorded, so one scraped from a terminal or a log is worthless. The probe exits 2 rather than 0 when the broker is not running, because a stopped broker must never look like a passing gate.
I am aware of how that reads. The security property of my agent sandbox is a six-digit code on my phone. But I would rather state the boundary accurately than describe a uid separation I do not have.
What I still have wrong#
The bypass I have not closed. Grant creation is gated. Session minting is not. An agent in the mcp-admin group can reach the admin socket and mint itself a session bound to personal-trusted, which is most of what the capability system exists to make it ask for. The TOTP gate protects the request-versus-approve boundary and does nothing about the profile-assignment boundary sitting right next to it. I found this while writing this post, which is its own small argument for writing things up.
The optional check. context_factory still defaults to off, so a server that never sets one dispatches exactly as permissively as it did before #3642. I have not written the CI check that would fail a build for a server exposing privileged tools without one, and that check is the only thing that would actually retire plane one.
A policy contradiction I have not resolved. personal-trusted denies browser_agent.login_frontline. There is also a requestable capability, frontline-login, whose entire grant is that one tool. Profile denies beat grants by design, so that a mis-authored capability can never resurface a tool a profile blocked. Which means a personal-trusted session can file that request, get it approved, burn a TOTP code, and still be denied at the call. I do not yet know whether the deny or the capability is the mistake. The rule is working exactly as designed; the policy I hand-wrote for it is not.
Concentration. I replaced four places where authorization could be wrong with one place where it can be wrong, and the seed file it reads is still hand-authored, as the previous paragraph demonstrates. Deny-by-default is what makes that trade acceptable to me. When the broker is confused, it says no.
I do not have production numbers on the broker yet, which is a gap given that the first half of this post is entirely evidence and this half is entirely design. What I can say is what the design is for: not to make the check correct, since the check was correct all three times, but to reduce the number of places I have to notice that it is missing.