Skip to content
Ylabator

MCP Server Security and Tool Permissions

A model-suggested tool call is not an authorized action. Verify the token, the scope and the target at every hop, and gate writes behind approval.

Topics
Secure AI Agents
Level
Founder / builder
Read
4 min
Published
2026-11-12
Reviewed
2026-11-12
Week 5

The problem

On May 26, 2025, Invariant Labs published an attack on the official GitHub MCP server, a project with about 14,000 stars at the time. An attacker opens an issue in a public repository. A user asks an agent to review that repository's issues. The issue text instructs the agent, and the agent, using the user's own token, reads data from the user's private repositories and publishes it in a pull request on the public one [1].

Invariant's point was that the server code had no bug. The authors called it an architectural issue that has to be fixed at the agent system level [1]. In the demonstration, the agent's token reached every repository the user could reach. The model treated text in an issue as an instruction. Every individual step was permitted.

The Model Context Protocol (MCP) makes it easy to give a model tools: read mail, search a drive, open a pull request, run a query. Each tool call carries a credential, and the model decides which call to make based on text, some of which an attacker wrote. A founder shipping an agent with tool access is shipping a program whose next action can be chosen by anyone who can put text in front of it.

The question is how to make the wrong action fail even when the model proposes it.

How it works

Treat the path from a model's proposal to a real-world effect as five hops. Each has its own check, and the diagram for this article follows the same order.

  1. Model proposes call. The output is proposed data only: a tool name and arguments. Nothing is executed yet.
  2. Token verification. The MCP server validates the access token's issuer, audience, scope and expiry. The MCP authorization specification requires servers to validate that tokens were issued specifically for them as the intended audience, per RFC 8707, and to return HTTP 401 for invalid or expired tokens [2].
  3. Vetted MCP server. Only servers your team reviewed and pinned are reachable. Tool parameters are structured and validated against a schema, not free text passed to a shell or a query.
  4. Application check. The server checks the request against what this user, in this session, granted: which repositories, which mailbox, which folder. Sensitive operations such as sending, sharing, merging and paying wait for human approval.
  5. Egress rules. Network policy limits where the server can send data. An allowlist enforced by infrastructure holds when the prompt is compromised.

Two rules from the specification close the most common gaps. Token passthrough is forbidden: an MCP server must not accept a token issued for another service, and must not forward the client's token to an upstream API. If it calls upstream, it uses a separate token issued for that API [2][3]. And possession of a state handle, such as a workflow ID, is not authentication. Servers should bind handles to the user ID derived from the verified token and reject them from anyone else [3].

Scope design matters as much as validation. The security guidance lists wildcard or omnibus scopes and publishing every scope up front as common mistakes, and recommends a minimal initial scope with step-up for privileged operations [3]. A token that can only read one repository cannot leak another, whatever the issue text says.

A tool call is checked at every hop

Fig. 05
  1. Model proposes callProposed data only
  2. Token verificationAudience, scope, expiry
  3. Vetted MCP serverStructured parameters
  4. Application checkApproval for sensitive ops
  5. Egress rulesAllowed destinations
Transport authorization and downstream application checks are complementary. A model-suggested tool call is never an authorized user action.
Technical detail

Reject expired tokens, wrong-audience tokens, manipulated tool descriptions and state handles belonging to another user. Keep credentials segregated per service.

By the numbers

GitHub stars on the official MCP server in Invariant's disclosure [1]
14k
of organizations with a breach of AI models or apps had no AI access controls [4]
97%
of breaches studied involved attackers using AI tools [4]
16%
of organizations reported breaches of AI models or applications [4]
13%
ConditionRequired behaviorResponse
Missing, invalid or expired tokenReject401 Unauthorized
Token issued for a different audienceReject, never forward401 Unauthorized
Valid token, scope too narrowReject with insufficient_scope and the needed scope403 Forbidden
Client token sent on to an upstream APIForbidden as token passthroughUse a separate upstream token
State handle presented by another userReject, possession is not authenticationDeny
Token in a URL query stringForbiddenHeader only
Token and request checks in the MCP authorization specification and security guidance, as documented in November 2026 [2][3]

The IBM figures show the same pattern at scale. Access control is the boundary that fails most often, and AI tooling is one more set of credentials to control [4].

The 16% figure is a reminder that attackers use the same tools. OWASP's Top 10 for Agentic Applications, published in December 2025, catalogs tool misuse and identity and privilege abuse as separate risks for exactly this reason [5].

Implementation

The function below runs at the MCP server before any tool executes. It uses the jose library for JWT validation. The repos claim is a custom claim the authorization server adds when the user grants access to specific repositories.

authorize.tstypescript
import { createRemoteJWKSet, errors, jwtVerify } from "jose";

const ISSUER = "https://auth.example.com";
const RESOURCE = "https://mcp.example.com/mcp"; // canonical server URI (RFC 8707)
const JWKS = createRemoteJWKSet(new URL(`${ISSUER}/.well-known/jwks.json`));

// Each tool needs one scope. Read and write are separate scopes.
const TOOL_SCOPES: Record<string, string> = {
  "issues.list": "repo:read",
  "pulls.create": "repo:write",
};
const NEEDS_APPROVAL = new Set(["pulls.create"]);

type Decision =
  | { status: 401 }
  | { status: 403; error: string; scope?: string }
  | { status: 200; sub: string; needsApproval: boolean };

export async function authorize(header: string | undefined, tool: string, repo: string): Promise<Decision> {
  if (!header?.startsWith("Bearer ")) return { status: 401 };
  try {
    // Checks signature, issuer, audience, exp and nbf.
    const { payload } = await jwtVerify(header.slice(7), JWKS, { issuer: ISSUER, audience: RESOURCE });
    const need = TOOL_SCOPES[tool];
    const granted = String(payload.scope ?? "").split(" ");
    if (!need || !granted.includes(need)) return { status: 403, error: "insufficient_scope", scope: need };
    // The target must be in the user's grant, whatever the model asked for.
    const repos = Array.isArray(payload.repos) ? (payload.repos as string[]) : [];
    if (!repos.includes(repo)) return { status: 403, error: "repo_not_granted" };
    return { status: 200, sub: String(payload.sub), needsApproval: NEEDS_APPROVAL.has(tool) };
  } catch (e) {
    if (e instanceof errors.JOSEError) return { status: 401 }; // expired, wrong audience, bad signature
    throw e;
  }
}

When needsApproval is true, the server records the proposed call, returns a pending status, and executes only after a person approves it in a separate interface. The approval screen shows the tool, the target and the exact arguments.

Around this function, three operational controls complete the boundary:

  • Segregated credentials. One OAuth client and one token per downstream service. A mail token cannot open the drive.
  • Pinned servers. Review an MCP server's code and tool descriptions before enabling it, pin the version, and re-review on update. A changed tool description is a changed instruction to the model.
  • Network egress. Run servers in a network segment that can reach only their own upstream APIs.

Test it

The negative tests below run against a staging MCP server with tokens minted by a test identity provider. None are real credentials. In this design the authorization layer runs before MCP message handling, so each check returns an HTTP status without an initialized session.

mcp_negative_tests.shbash
#!/usr/bin/env bash
# Expected status for each hostile request. Tokens come from the test IdP fixture.
set -euo pipefail
MCP="https://mcp.staging.example.com/mcp"
BODY='{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"pulls.create","arguments":{"repo":"acme/private-plans"}}}'

expect() {  # $1 label, $2 token, $3 expected HTTP status
  local code
  code=$(curl -s -o /dev/null -w '%{http_code}' -X POST "$MCP" \
    -H "Authorization: Bearer $2" \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json, text/event-stream' \
    -d "$BODY")
  if [[ "$code" == "$3" ]]; then
    echo "PASS $1 ($code)"
  else
    echo "FAIL $1: got $code, want $3"
    exit 1
  fi
}

expect "expired token"             "$TOKEN_EXPIRED"        401
expect "token for another service" "$TOKEN_OTHER_AUDIENCE" 401
expect "read scope calls a write"  "$TOKEN_READ_ONLY"      403
expect "repo outside the grant"    "$TOKEN_OTHER_REPO"     403

Expected result: four PASS lines. Then cover the cases a status code cannot show:

  • Plant a hostile issue in a test repository that tells the agent to copy a private file into a public pull request. Expected: the write waits for approval, and the approval screen shows the cross-repository target.
  • Change a tool description on a pinned server. Expected: the client refuses the changed server until it is re-reviewed.
  • Present another user's state handle. Expected: denied and logged.
  • Confirm that no server forwards the client's token upstream by inspecting upstream access logs for the MCP audience.

Decision

Never confuse a model-suggested tool call with an authorized user action.

  • Validate audience, scope and expiry on every request, and bind every target to the user's grant.
  • Split read and write scopes, start with read only, and require step-up plus human approval for sends, shares, merges and payments.
  • Pin and review every MCP server, and restrict its network egress.
  • Run the negative tests on every server update. The work is a few days per server, and much less than one incident.

Sources

  1. [1]GitHub MCP Exploited: Accessing private repositories via MCP (opens in a new tab)Invariant Labs, May 2025
  2. [2]Authorization, Model Context Protocol specification 2025-11-25 (opens in a new tab)Model Context Protocol, November 2025
  3. [3]Security Best Practices (opens in a new tab)Model Context Protocol, November 2026
  4. [4]IBM Report: 13% of organizations reported breaches of AI models or applications, 97% of which reported lacking proper AI access controls (opens in a new tab)IBM Newsroom, July 2025
  5. [5]OWASP Top 10 for Agentic Applications for 2026 (opens in a new tab)OWASP GenAI Security Project, December 2025

Technical guidance, not security certification or legal advice.

All Private AI articles