From your IdP to a tool call: how agent authorization works
Tiago Zien-Mendes
Published · 9 min read
When an MCP connection uses a shared service account and a server-level allowlist, security teams can struggle to determine who initiated a tool call and whether that person should have had access.
Speakeasy ties MCP access to an identified caller and checks permissions down to the tool. A person can sign in through their identity provider, while agents and automated workloads can use their own identities. Tool logs attribute activity to the caller, and authorization challenges help administrators investigate denied access.
How AI agents authenticate through your identity provider
Private MCP servers on Speakeasy reject anonymous traffic. When an agent connects without credentials, the server responds with a 401 and a WWW-Authenticate header pointing at OAuth protected-resource metadata, the standard MCP authorization handshake. That causes the agent's client (Claude, Cursor, a custom harness) to start an OAuth flow, and the person behind the agent can sign in through the company's identity provider. The agent auth reference places this production OAuth path beside EMA, XAA, and the proposed AAuth protocol.
Directory sync keeps identity provider metadata current in Speakeasy's MCP gateway:
- Users, groups, and attributes flow in from Okta or Entra.
- Role assignments track group membership, so someone joining a team gets the matching access automatically.
- When someone is deprovisioned, their access is removed.
Once that OAuth flow completes, Speakeasy can evaluate the signed-in user's roles. This is the human-led path used in the examples below.
Speakeasy also supports agent identities with their own permissions and a human owner. An agent credential is limited by the intersection of its credential maximum, the agent's current policy, and the owner's current policy.
For example, suppose a support agent's credential and its own policy both permit the billing server's read and refund tools, but its owner Alice can use only the read tools. The agent can read invoices but cannot issue a refund through that credential. If Alice later loses billing access, the agent loses that access on its next request. The human-led example below follows Alice's own session; an agent using its own identity has these additional bounds.
Automated workloads such as CI jobs can exchange a platform-issued identity token for a short-lived session and act as an assigned agent. Their permissions are bounded by the session and agent policies; the agent's owner must remain an eligible organization member.
The identity used to connect to Speakeasy is separate from the credential used upstream. A remote MCP server can call its upstream as the individual user, with a shared service account, or without a managed identity. A shared upstream credential does not by itself erase the caller identity held by Speakeasy.
Role-based access control for MCP server connections
With identity resolved, the first authorization gate fires when the session attaches to a server. The caller must hold the mcp:connect scope for that specific server.
Permissions in Speakeasy are grants: a scope paired with a selector that says which resources it reaches. Roles are named bundles of grants, which gives you role-based access control that stays in step with your directory.
The built-in admin role holds the standard administrative scopes, and the built-in member role holds a read-and-connect subset. Members can hold several roles, and their grants add together; a narrow custom role does not cancel a broader grant from the member role. Review the baseline role and use an applicable block where needed. A grant that lets a role connect to one server in one project looks like this:
{
"scope": "mcp:connect",
"selectors": [
{
"resource_kind": "mcp",
"resource_id": "<server-id>",
"project_id": "<project-id>"
}
]
}
Selectors support explicit wildcards ("resource_id": "*" reaches every server), so a role can be as broad or as narrow as the team it describes. A grant only constrains the keys it names. Pin project_id and the grant follows the project, or leave it off and the grant applies everywhere the scope does.
If no grant satisfies the check, the connection is denied. The check is attributed to the caller, whether that is a person or an agent.
Tool-level permissions that authorize each MCP tool call
After a connection is authorized, each tools/call passes through a second mcp:connect check for the server. This check includes the tool name and the tool's disposition.
Disposition is derived from the tool's recorded MCP annotations:
- Tools declaring
readOnlyHintevaluate asread_only. - Tools declaring
destructiveHintevaluate asdestructive. - The rest of the vocabulary is
idempotentandopen_world.
This lets you write policy for classes of behavior as well as named tools. For remote and tunneled servers, Speakeasy uses stored annotation metadata for the check. When the live server differs, an administrator can review the difference and sync the annotations. Built servers record tool definitions at deployment. Annotations are hints supplied by the tool provider, so review them before relying on them for access decisions.
Suppose Alice is a support engineer who needs to look up invoices but must not issue refunds. Her administrator has scoped the Member role so it does not grant broader billing access, and Alice has no other billing grants. Changing the Member role affects everyone assigned to it, so administrators should review its existing holders before narrowing it. The billing server's stored annotations mark get_invoice as read-only and create_refund as destructive.
The administrator assigns Alice a Support role with this grant:
{
"scope": "mcp:connect",
"selectors": [
{
"resource_kind": "mcp",
"resource_id": "<billing-server-id>",
"disposition": "read_only"
}
]
}
The grant allows Alice to connect and call get_invoice; it does not match create_refund. With no broader grant and no other control blocking the read, the invoice lookup is allowed and the refund is denied. These checks do not require a change to the upstream server. Use a tool key to name specific tools.
How the MCP gateway evaluates each allow-or-deny decision
For the human caller in this example, the grant check can be understood in four steps:
- Load the caller's grants. Everything the principal holds (through their synced role and any direct grants) is assembled for the organization.
- Expand scopes. Higher privileges satisfy lower ones.
mcp:writesatisfies anmcp:readcheck, and either satisfiesmcp:connect, so you never have to grant the same family three times. - Match selectors. For selector keys present in both the grant and the check, the values must match or the grant can use
*. A key absent from the check does not prevent an allow grant from matching. That is why a grant scoped to"disposition": "read_only"can satisfy a connection-level check that does not ask about disposition. - Apply denies. Deny rules evaluate as a separate pass with stricter matching, and a matching deny always beats a matching allow.
Scroll horizontally to see the full diagram on a narrow screen.
The diagram covers the grant check within the wider request path. The gateway also applies client admission, checks for an active killswitch, and evaluates blocking risk policies where configured. Client admission happens when the client signs in or refreshes; access, killswitch, and policy checks run on tool calls. Agent credentials have the additional policy bounds described above.
When multiple grants apply to the same resource, a matching deny takes precedence regardless of the order of the rules. Network-level access follows the same principle.
As an alternative, suppose Alice's Member role grants mcp:connect on every server and an administrator adds a deny rule for destructive tools on the billing server. Alice can connect and call permitted read tools. If her client calls create_refund, the matching deny takes precedence over the broader allow.
Investigate tool activity and denied access
Suppose the billing team reports a refund and asks whether Alice's client made the call. In Observability > Tool Logs, an administrator can filter by the incident's time range, the billing server, and Alice's email, then use the gram.tool.name attribute to find create_refund. Opening a matching trace shows its status and related log entries. Tool call telemetry also records the caller's directory attributes, groups, and roles at the moment of the call, so the record reflects what Alice held then, not how the roles are configured today. Tool input and output are available only if the organization enabled their recording, and a log does not guarantee a record of the exact grant that permitted an earlier call.
If Alice's refund attempt was denied, the administrator can also look for an authorization challenge identifying the caller and missing scope. The challenge helps investigate the denial; where appropriate, the grant flow can assign a custom role covering the requested action. Review the intended access before granting it, since the denial may be the correct outcome.
Where to find this
Open Organization settings > Team > Roles & Permissions > Authorization Challenges to review denied and resolved checks. Unresolved challenges also appear on the organization home page. Where directory sync manages a person's roles, follow your organization's identity-provider assignment process.
Get started with identity-based MCP access control
Connect your identity provider and configure directory sync from Organization settings > Team, then map directory groups or attributes to roles. Use Roles & Permissions or a server's Team Access tab to configure access, and review the agent identity documentation when automated agents need their own credentials. Check your logging settings and test both allowed and denied calls before rollout.
Need to prove who did what across your agents? Book time with our team and we'll walk through it with you.