TL;DR: FastMCP v2.2.7 adds OAuth-based authentication for MCP servers, and Pangea’s walkthrough shows how that shifts MCP access from implicit trust to scoped client authorization, including custom scopes, authorization code flow, and token handling. For IAM teams, the real change is that MCP tools now need identity governance, not just transport security.
At a glance
What this is: This is a technical guide showing how FastMCP v2.2.7 can authenticate MCP clients with OAuth and custom scopes, turning MCP server access into an identity-governed control plane.
Why it matters: It matters because MCP servers are now part of the NHI surface area, so IAM, IGA, and PAM teams need to treat tool access, client registration, and token lifecycle as governed identity events.
By the numbers:
- Only 18% of MCP server deployments implement any form of access scoping for tool permissions.
- 53% of MCP servers expose credentials through hard-coded values in configuration files.
- 70% of organisations grant AI systems more access than they would give a human employee performing the exact same job.
- Only 44% of organisations have implemented any policies to manage their AI agents, despite 92% agreeing that governing AI agents is critical to enterprise security.
👉 Read Pangea's guide to authenticating FastMCP servers with OAuth
Context
Model Context Protocol, or MCP, creates a standard way for AI clients to connect to tools and data sources. The security question is no longer just whether the server is reachable, but whether each client, tool scope, and callback flow is properly governed as a non-human identity interaction.
The article focuses on adding OAuth authentication to FastMCP servers through a custom provider pattern, with client registration, scopes, authorization code exchange, and token validation. That is a practical step toward treating MCP access as identity infrastructure rather than ad hoc integration plumbing.
For IAM and NHI teams, the relevant shift is that MCP tooling now exposes the same governance problems seen in service accounts and API integrations: uncontrolled scope, weak token handling, and unclear lifecycle ownership. The post is a how-to, but the security implication is broader than the code sample itself.
Key questions
Q: How should security teams govern MCP OAuth flows in enterprise environments?
A: Treat MCP OAuth as an identity control plane, not a convenience layer. Bind authorization state to the initiating session, display clear consent context, restrict redirect URIs, and review every proxy-style client registration. If the server cannot prove who initiated the request and where the callback should go, it should not issue a usable authorization code.
Q: What breaks when MCP clients share broad scopes?
A: Broad scopes collapse the boundary between authentication and authorization. Every authenticated client can inherit tool reach that was meant for a narrow workflow, which makes abuse and accidental overuse harder to detect. The result is privilege creep inside the MCP layer, with the same overexposure patterns seen in unmanaged service account estates.
Q: How do security teams know whether MCP authorization is actually working?
A: Look for evidence that consent is stored per client, tokens are validated at each hop, and invalid audience or redirect values are rejected consistently. If a server accepts session-only state, relayed tokens, or vague consent prompts, authorization is functioning as a convenience layer rather than a control.
Q: What is the difference between authenticating an MCP client and authorising its tool use?
A: Authentication proves the client is allowed to request access. Authorization determines which tools or resources that client can reach once the session is established. In MCP, the dangerous mistake is to treat successful login as sufficient. Identity teams need both a verified client and a tightly scoped permission model.
Technical breakdown
OAuth authorization code flow for MCP clients
FastMCP v2.2.7 can place an OAuth authorization code flow in front of MCP tool access. In this pattern, the client first authenticates with an external authorization server, receives a code, and then exchanges that code for a bearer token used against the MCP server. The MCP server becomes the relying party, while the authorization server becomes the identity source for client access. That means tool access is no longer a simple network call. It is now mediated by client registration, redirect URIs, scopes, and token validation, which are the same governance primitives IAM teams already use for federated application access.
Practical implication: register MCP clients explicitly and treat redirect URIs, scopes, and token issuance as controlled identity configuration.
Custom scopes define MCP tool permissions
The guide uses a custom scope such as mcp to represent permission to authenticate with the server. Scopes are not just labels. They are the mechanism by which the server distinguishes broad client authentication from actual authorization to use tools and resources. If scopes are too coarse, every authenticated client inherits unnecessary reach. If they are too broad or reused across projects, the server loses meaningful privilege boundaries. In NHI terms, the scope is the policy boundary that should separate authentication from task-specific authorization, especially when the client is a tool-using application or agent.
Practical implication: design MCP scopes around specific tool sets or use cases, not around a single catch-all permission.
Token mapping and callback handling create the real trust boundary
The callback handler exchanges the external OAuth code, stores the resulting access token, and maps it back to an MCP-issued token for local use. That introduces a trust boundary between the external identity provider and the MCP runtime. The code sample also shows why state handling, expiry checks, and revocation logic matter: if these controls are weak, the server may accept a token that is no longer valid, mapped incorrectly, or retained longer than intended. For identity teams, this is the NHI equivalent of session governance, but applied to machine-to-tool interaction.
Practical implication: enforce token expiry, revocation, and state validation as first-class controls in MCP implementations.
NHI Mgmt Group analysis
MCP authentication turns tool access into NHI governance, not just application security. Once a client must authenticate before it can reach tools and resources, the control problem shifts from connectivity to identity lifecycle, privilege scope, and token handling. That aligns MCP servers with the same governance questions already familiar in API keys and service accounts. The practical conclusion is that MCP deployments need NHI oversight from day one, not after tool sprawl appears.
Scope is the only meaningful boundary when the client is machine-driven. The article’s custom scope example shows that OAuth authentication alone does not create least privilege. The authority to call a tool still depends on how tightly scopes map to business function and runtime need. If scope design is vague, the server recreates the same overprivilege problem that identity teams already struggle with in other NHI estates.
Runtime token handling is the weakest point in many MCP implementations. The sample stores access tokens, state mappings, and authorization codes in memory, which is fine for a tutorial but not for production governance. That pattern exposes the broader issue: MCP security is not just a protocol question, it is a lifecycle question around issuance, storage, expiry, and revocation. Practitioners should treat token persistence as a control surface, not an implementation detail.
Named concept: MCP trust boundary drift. As MCP servers add authentication, the boundary between authenticated client and authorised tool access can drift if scopes, redirect handling, and token reuse are not tightly governed. This is a classic NHI failure mode because the identity path looks secure while the permission model quietly expands. The implication is that teams need to continuously validate where authentication ends and authorisation actually begins.
Tool-enabled AI systems make identity decisions more consequential than their code footprint suggests. A small authentication layer can govern a large downstream tool estate if the client is an AI agent or automated workflow. That is why MCP security sits at the intersection of NHI governance and emerging agentic control models. Practitioners should expect the identity surface to expand faster than the application surface.
From our research:
- Only 18% of MCP server deployments implement any form of access scoping for tool permissions, according to The State of MCP Server Security 2025.
- 53% of MCP servers expose credentials through hard-coded values in configuration files, according to The State of MCP Server Security 2025.
- For a broader identity lens, The 2026 Infrastructure Identity Survey found that only 44% of organisations have implemented any policies to manage their AI agents.
What this signals
MCP trust boundary drift: once authentication is added to MCP, the real risk becomes scope expansion and lifecycle slippage around tokens, not just unauthenticated access. Teams should expect the control plane to behave like any other NHI estate: client registrations multiply, permissions widen, and ownership becomes ambiguous unless someone owns the identity model end to end.
The broader market signal is that AI systems are getting access faster than governance is catching up. With 70% of organisations granting AI systems more access than a human employee in the same role, per The 2026 Infrastructure Identity Survey, MCP authentication will only reduce risk if it is paired with tight scope design and revocation discipline.
For practitioners
- Register MCP clients deliberately Create separate OAuth clients for distinct MCP use cases, and bind each one to the minimum redirect URI and scope set required for that workflow.
- Define scopes around tool boundaries Use scope values that map to concrete tool groups or business functions, then review whether any scope grants more access than the client actually needs.
- Move token state out of process memory Persist authorization codes, access tokens, and revocation state in durable storage with auditability instead of keeping them only in runtime dictionaries.
- Validate callback and state handling strictly Check that the state value, redirect URI, and code exchange all match the expected client context before issuing any local MCP token.
- Tie MCP token revocation to lifecycle events Revoke tokens when clients are rotated, disabled, or re-registered so old credentials do not continue to authorize tool access.
Key takeaways
- MCP servers are now identity endpoints, so authentication, scope, and token lifecycle need NHI governance.
- The biggest failure mode is overbroad permissioning, because OAuth alone does not enforce least privilege for tool access.
- Practitioners should treat client registration, callback integrity, and token revocation as production controls, not tutorial details.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 and OWASP Agentic AI Top 10 address the attack and risk surface, while NIST CSF 2.0, NIST SP 800-53 Rev 5 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 | OAuth scopes and token handling map directly to NHI authorisation and lifecycle risks. |
| OWASP Agentic AI Top 10 | MCP is a core tool-access pattern for agentic systems and can amplify privilege abuse. | |
| NIST CSF 2.0 | PR.AC-4 | The article centres on access permissions and authentication boundaries. |
| NIST SP 800-53 Rev 5 | IA-5 | Token lifecycle and authenticator management are central to the callback and revocation flow. |
| NIST Zero Trust (SP 800-207) | MCP tool access should be treated as continuously verified access across trust boundaries. |
Assess whether MCP-connected agents can exceed their intended tool scope or reuse credentials unsafely.
Key terms
- Model Context Protocol: Model Context Protocol is an open protocol that lets AI agents connect to tools and data sources. It expands what an agent can reach, so governance has to cover not only the model and its prompts, but also every system that can receive or return agent-driven data.
- OAuth Authorization Code Flow: An OAuth pattern that exchanges a temporary code for tokens instead of sending tokens directly through the browser redirect. The design reduces exposure during the authentication step and is widely used because it separates the front-channel interaction from token issuance.
- Mcp Trust Boundary: The security boundary created by a Model Context Protocol connection between an AI assistant and an external system. Each connection can supply data, trigger actions, or both, so it must be governed like a delegated access path rather than a simple integration.
- Scope Minimisation: Scope minimisation is the practice of granting only the permissions needed for a specific task or transaction. For MCP and other non-human identities, it must be evaluated at the workflow level because agents can chain tool use quickly and expand exposure if granted broad scopes. The control reduces blast radius when a client is compromised.
What's in the full article
Pangea's full post covers the implementation detail this analysis intentionally leaves at a higher level:
- Exact FastMCP provider class wiring and callback route code for local implementation
- Environment variable setup for client ID and client secret in a working example
- Step-by-step creation of custom OAuth scopes and client registration values
- Production guidance on replacing localhost callback URLs with deployed server addresses
👉 Pangea's full post shows the callback flow, provider code, and client setup in detail.
Deepen your knowledge
NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are building or maturing an identity security programme, it is worth exploring.
Published by the NHIMG editorial team on August 18, 2026.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org