MCP security when an agent can call every tool on the server
MCP security for production agents. What the GitHub MCP exploit shows about tool grants, and how to check a call's arguments before it leaves the agent.
MCP security for production agents. What the GitHub MCP exploit shows about tool grants, and how to check a call's arguments before it leaves the agent.
MCP security usually starts at the server, with who may connect and which token they hold. An agent that can reach a server can normally call every tool on it, with whatever arguments the model writes. The agent's tool list usually includes tools it never needs, such as one that deletes files, and a token copied off the agent's host opens the whole server. In the published attack on GitHub's MCP server, every call the agent made was allowed, and private data ended up in a public repository.
Amiril, which we build, puts a gateway between agents and their tool servers that grants each agent only the tools it needs and keeps the server's key away from it. A rule in the agent reads each call, and what the run did before it, before the call goes out.
In May 2025 Invariant Labs published an attack on GitHub's official MCP server. A user had Claude Desktop connected to the server with their own GitHub account, which owned one public repository and some private ones. An attacker opened an issue on the public repository with instructions written into it. Later the user asked the agent to look at the open issues. The agent read the planted one, pulled data from the private repositories into its context and wrote it into a new pull request on the public repository, where anyone could read it. Invariant's demo leaked the names of private projects, a plan to move to South America and the user's salary.
Claude Desktop asks before each tool call by default. Invariant points out that many people switch that to "Always Allow" and stop watching, and an agent in production has nobody to ask anyway.
Invariant was clear that the server's code had no bug. Every call in the attack was one the agent was allowed to make. It could read the private repositories because the user's token could, and opening pull requests on the public one was part of the job. As of December 2026 the server has a lockdown mode that hides public-repository content from authors without push access, and its README says lockdown "is not an authorization boundary: it does not change what the underlying GitHub credential can read or write." Lockdown is still worth having for MCP security. Under it, issue_read returns an error for an issue like the attacker's, written by someone without push access.
The spec's authorization section is optional, covers the HTTP transports and builds on OAuth 2.1. It decides whether a client may use a server at all, and it has no model for which tools a given client may call. The tools page puts that on the server, which "MUST validate all tool inputs" and "implement proper access controls". Annotations such as readOnlyHint and destructiveHint describe a tool, but clients must treat them as untrusted unless they trust the server. The security best practices list wildcard and omnibus scopes as a common mistake.
So most of what the spec says about MCP server security concerns the server's own front door. When the server belongs to a vendor, you get the vendor's scopes, and those are usually coarse. Input checks and access control there ask whether the token may write to the repository named in the call, and the pull request in the GitHub attack passed both.
Amiril runs an MCP gateway that sits between your agents and the servers their tools live on. You register each tool server once, with its address and how Amiril signs in to it. That can be an API key, OAuth client credentials, or a person's OAuth login, which Amiril renews. Amiril reads the server's tool list and files each tool as Read, Write or Destructive from its readOnlyHint and destructiveHint. A tool that sends neither counts as Write. The spec says to treat those hints as untrusted unless you trust the server, so you look over the list and fix any that are wrong before the tools are added.
On an agent's Access tab every tool starts denied. You grant tools one switch at a time, or tick a whole server at Read, Read and write, or Full, and the grant takes effect within a few seconds. A level ticks only the tools the server has when you save it, so a tool the server adds next year arrives denied whatever its hints say, and the access log records that it appeared. An agent belongs to one environment, so the production agent and its development twin each have their own grants.
The agent connects as an ordinary MCP client with a gateway token. Its tool list holds the tools it was granted and nothing else, under names such as github__create_pull_request, the server's slug and the tool joined by two underscores. A call to any other tool never reaches the server, and the agent gets this back:
This agent doesn't have access to github__delete_file. An admin can grant it in Amiril.
The token belongs to one agent in one environment, and you can revoke it on its own. The server's own key or OAuth token stays with the gateway, encrypted with AES-256-GCM, and the gateway adds it to the request after the check. If the agent's host leaks its environment variables, the token reaches that agent's granted tools and nothing else. GitHub's own server can be narrowed too. It has a read-only mode and named toolsets. That works until two agents need different tools from it, as the post on MCP access control explains.
Per-tool permissions take away what an issue-triage agent never needed, such as deleting files. Opening pull requests was the agent's job, and a good one calls github__create_pull_request under the same grant.
The two calls that mattered were a read from a private repository and, later in the same run, a pull request against the public one. An Amiril rule can say exactly that:
@id("no-cross-repo-pr")
@sentence("This run read another repository before opening a pull request on {repo}")
block (
agent == "issue_triage",
tool == "github__create_pull_request"
)
when {
github__get_file_contents{ args.owner != call.args.owner || args.repo != call.args.repo }
};The agent wraps its gateway tools with the Amiril SDK, which checks each call inside the agent before it goes to the gateway. By default a rule reads earlier calls in the same run. Inside the braces, call.args is the pull request being checked. args is each earlier read. {repo} fills in the pull request's repository. So the rule blocks a pull request to the public repository (pacman in Invariant's demo) once the run has read a file from any other repository, and lets it through when the agent stayed put. A version for a real agent would list each of its read tools, code search included. When the rule fires, the tool never runs, and the model gets this in place of a result:
The call to github__create_pull_request was not performed. Rule no-cross-repo-pr blocked it: This run read another repository before opening a pull request on pacman. Do not retry this call with different arguments or achieve the same outcome another way; tell the user it was not performed.
The same rule language handles the plainer argument checks, like an amount limit, a list of allowed currencies, one payment per invoice or a cap on refunds summed across a session.
A published rule starts in Shadow, where it checks every call, records what it would have done and lets the call through. Test on past calls replays any version of a rule over the last 24 hours, 7 days or 30 days of real calls and lists each one it would have fired on. That is where you'd find the triage agent's legitimate habit of copying a config file from a template repository. Once the list looks right, switch the rule to Enforce. Published rules reach running agents within about a minute with no redeploy, and the SDK keeps enforcing its last rules while Amiril is unreachable.
When General Analysis showed a prompt injection pulling private rows out of a Supabase database through its MCP server, Supabase answered with a post on defence in depth. It repeats the advice from its MCP security guide, which ends with "Monitor and log all MCP queries."
The agent's Calls tab in Amiril lists every call through the gateway, newest first, with whether the gateway allowed it and how the tool server answered. The access log records who granted or revoked each tool and when, and each tool that appeared on a server, changed or left it, so a tool that changes after you granted it shows up there. The SDK reports its own decisions as well, and each rule's page counts what it blocked, flagged and allowed.
The gateway sees every call, so it knows which grants have gone quiet. A tool granted more than 30 days ago and not called in the last 30 becomes an access suggestion, which you answer with Revoke or Dismiss. If the agent calls the tool again first, the suggestion closes on its own. The investigator that writes up each issue can suggest a revoke as well, when the issue's runs show the agent shouldn't have that tool at all.
Rules run in the SDK, so they check an agent's function tools as well as its MCP ones, and the post on AI agent security writes them for a reporting agent with run_sql and send_email. The setup guide puts an agent behind the gateway, from registering it to pasting its token into the agent's MCP client settings.