MCP Server Auth vs MCP Client Auth: Two Different Problems
Sagara Gunathunga·23 min read
All posts
- MCP Authorization: The Complete Developer Guide
- MCP and OAuth 2.1: What Actually Changed and Why It Matters
- Connecting an AI Agent to an OAuth-Protected MCP Server
- Connecting a LangGraph Agent to an OAuth-Protected MCP Server
- MCP Server Auth vs MCP Client Auth: Two Different Problems
- Why Your MCP Token Expires Mid-Run
- The Architect's Guide to React Authentication: Choosing a Flow, a Store and a Boundary
- React Authentication Best Practices: The 2026 Checklist
- Best Authentication Libraries for React in 2026
- Open Source and Self-Hosted Auth for React in 2026
- JWT-Based Authentication in React: Storage, Validation and the localStorage Question
- Passwordless Login in React: Passkeys, Magic Links and OTP
- OAuth 2.0 and OIDC in React: The Authorization Code Flow with PKCE, Explained
- React Authentication: The Complete Guide
On this page
- The roles behind the specification
- What MCP server authorization means
- What MCP client authorization means
- Server view, client view
- Token passthrough and the confused deputy problem
- Server and client responsibilities
- When your team builds both sides
- Local servers over stdio
- Agent identity is a separate layer
- What developers should implement
- Where to go from here
A couple of years ago, there was no such thing as MCP. Now, chances are, you're building an MCP server, integrating with one as a client, or doing both on the same project within the same few weeks (often without anyone on the team stopping to ask which one they're actually doing). It's become common for developers to start that work with the line between the server role and the client role still blurry, especially where authorization, identity, and overall security are concerned, since the protocol reads as one specification and doesn't go out of its way to tell you that you're actually building two different things.
Not having that distinction clear from the start tends to show up later rather than immediately. A server built without a firm sense of where its own boundary sits will trust a token because it came from the right identity provider, it won't check that the token was actually issued for this server. A client built the same way will reuse a registration or a stored credential against a new server because the first one it talked to happened to work that way. A server that calls another service on the user's behalf will forward the token it was handed instead of getting its own, because nobody drew a hard line between authenticating a caller and acting as a caller. None of that fails in a demo, it only fails the day a caller or a callee shows up that the code wasn't written to expect, and by then it's running in front of a real user.
The goal of this post is to draw that line properly: what the server owns, what the client owns, the one mistake that comes from blurring the two, and a reference you can come back to once you're actually implementing either side.
Here's a fast way to tell which one you have. If you're publishing tools for someone else's agent to call, you're working on the server side. If your agent is calling a tool on a server somebody else built and protected, you're working on the client side. If you just read that and you're still not sure, read it again with your own project's name in place of "tools" and "agent."
The server and the client are answering two different questions, and it helps to say them out loud once before going any further.
- The server asks: who is calling me, which authority are they presenting, and may they perform this particular operation?
- The client asks: how do I identify this server and its authorization server, obtain the right authority, and use that authority safely while helping the user complete a task?
Those aren't rhetorical. An MCP server can end up guarding tools that read private email, search internal documents, access customer records, create invoices, modify source code, deploy infrastructure, approve financial transactions, or delete production resources. Whatever it protects, the server's job is narrow and inward-facing: publish where to get a token, check the one it's handed, decide whether this specific operation is allowed, and never mint a token itself. The client's job is wider and outward-facing: it may be connecting to a server it has never seen before, built by a team it has never talked to, protected by an authorization server it has to discover on the fly.
The two pieces share a specification, revision 2026-07-28 of the Model Context Protocol's authorization framework, and share almost nothing else. The work of publishing metadata and validating an inbound token has no code in common with the work of parsing a discovery document, registering a client, running a browser redirect, and keeping a token alive across an agent run that outlives the person who started it. They fail differently, they get tested differently, and a config object shared between them is usually where a server ends up trusting a token it should have rejected.
Confusing the two responsibilities tends to produce one of two problems, and it's worth naming both before the detail, since most of what follows is really just an elaboration of these:
- an MCP server accepts a token that passes every cryptographic check and still authorizes an operation it never should have, because the token was valid without being valid for this;
- an MCP client assumes every server it will ever talk to share the same issuer, registration path, scope vocabulary, or token lifetime as the first one it was built against.
This piece separates the two problems properly and gives you a practical reference for what to build on each side, one real mistake that comes from blurring them, and a look at what happens the moment either side has to deal with more than one of the other.
The roles behind the specification
The specification assigns four roles, and your code plays exactly one (it's worth separating the protocol role from the product wearing it, since one product can implement more than one role at once, but each role it plays still carries a distinct, separable responsibility). Here is the breakdown:
| Role | Who plays it | What it does |
|---|---|---|
| Resource server | Your MCP server | Accepts access tokens, validates them, serves tools |
| Client | The MCP client or agent | Obtains tokens and presents them |
| Authorization server | An identity provider | Authenticates the user and issues tokens |
| Resource owner | The user | Grants consent |
The MCP server is a resource server, never an authorization server. It doesn't issue tokens, run a login page, or store passwords, and every server that starts doing one of those things has quietly taken on a second job the specification never asked it to do. It can be co-located with an authorization server in the same product or deployment, but that just means one product is playing two roles, not that the roles have merged.
The MCP client is the only role obtaining tokens on someone's behalf, which means it's the only role that has to run an OAuth flow at all. It often lives inside a larger MCP host, an AI assistant, an IDE, a desktop app, a CLI, or an agent runtime, and the host may manage several MCP clients at once, each holding its own connection to a different server.
If you're building both sides of one connection, this split still applies. Write the server's code as if an arbitrary conformant client might connect, and the client's code as if an arbitrary conformant server might answer. The moment you let one side assume something about the other because you happen to control both today, you've built something that breaks the day either side changes without the other.
What MCP server authorization means
As an MCP server developer, you're the gatekeeper for your business capabilities and digital assets accessed by an agent, the emails, customer records, invoices, infrastructure, or payments this piece opened with. That responsibility comes down to a few concrete things: publish where to get a token, check the token you're handed, and never mint one yourself. What follows happens in order, and the status-code decision only makes sense because of what the validation step finds.
First, publish protected resource metadata, at a well-known URI matching your server's path, naming at least one authorization server. This is how a client that has never met your server before finds out where to send a user, and it has to exist before any request even arrives, everything else in this section only matters once a client has already found its way here.
app.get("/.well-known/oauth-protected-resource", (_req, res) => {
res.json({
resource: "https://mcp.example.com/mcp",
authorization_servers: ["https://login.example.com"],
scopes_supported: ["documents:read"]
});
});
Once a request actually arrives, validate the token properly, not just its signature. A token can be correctly signed, unexpired, and issued by a trusted authorization server, and still be the wrong token, one issued for a different MCP server entirely. Check the issuer, the signature or introspection result, expiry and activation time, audience or resource, scopes, subject, tenant or organization context, and any proof-of-possession information your token model uses.
app.use("/mcp", async (req, res, next) => {
const token = readBearerToken(req);
if (!token) return sendAuthorizationChallenge(res);
const authInfo = await tokenVerifier.verify(token, {
issuer: "https://login.example.com",
audience: "https://mcp.example.com/mcp"
});
res.locals.authInfo = authInfo;
next();
});
The audience check specifically is the one control that stops a token issued for a different MCP server from being accepted by yours merely because both trust the same authorization server, and it fails silently when it's missing, which is exactly why it deserves its own line item instead of being folded into "validate the token" generally.
What that check finds is what decides the status code, not just any challenge. A bare 401 forces the client back onto guesswork, and a 401 is also the wrong response once a token has already been accepted. Return 401 when the request has no acceptable credentials at all: the token is missing, malformed, expired, issued by an untrusted issuer, or intended for a different resource. Return 403 once the token is valid but the caller still lacks the authority for this specific operation, ideally with an insufficient_scope challenge naming what would resolve it. The distinction matters because a client behaves differently in response to each one, a 401 means fix or obtain authentication, a 403 with insufficient_scope means ask for more authority, and collapsing both into one status code makes correct client behavior close to impossible.
Even once the token clears all of that, enforce authorization inside the tool, not at the token boundary. A token can prove a user is allowed to read project data without proving they may delete the project, or grant access to one organization but not another, or let a support engineer view a customer account without letting them change its billing. A scope like documents:read is a stable capability gate, not a decision about whether this caller may read every document in every tenant. That decision has to live inside the tool handler or a policy layer close to the actual business operation, because nothing upstream of it has the context to make it.
If any of this leads your server to call something else, never pass the token through. If your server calls an upstream API on the user's behalf, get your own token for that call. Forwarding the token you received is the confused-deputy shortcut, and it's covered in full in Token passthrough and the confused deputy problem, because it's the mistake that actually motivates this entire piece. The standard way to get that separate token is OAuth 2.0 Token Exchange (RFC 8693), whose act claim records which party is acting on the user's behalf. It sits outside MCP's own specification entirely: MCP establishes the prohibition on passthrough but doesn't hand you one universal replacement, so check what your authorization server supports before you design this part.
Here's what this class of mistake looks like when it goes wrong in real software, not hypothetically. PrefectHQ's FastMCP, a Python framework built on the official MCP SDK, shipped an OAuth Proxy that ignored the client's resource parameter entirely and issued every token scoped to the proxy's own base URL rather than the specific MCP server that was actually requested, so a token captured by one server could be replayed against others (GHSA-5h2m-4q8j-pqpj, fixed in 2.14.2). A separate advisory against the same framework described a confused-deputy path where an attacker could ride a victim's existing consent for a static, shared identity-provider client straight into an authorization code meant for the MCP server, then redeem it themselves (GHSA-c2jp-c369-7pvx, fixed in 2.13.0). Neither of these is a reason to avoid the framework specifically. Both are a reason to read your framework's auth code rather than assume popularity implies correctness, since a server-side mistake like this one doesn't announce itself with a failing test, it announces itself as a security review finding months later.
What MCP client authorization means
As an MCP client developer, you're the one carrying your user's authority out into a world of servers you don't control, proving who you are, obtaining the right permissions, and using them safely on the user's behalf. That responsibility plays out in a fixed order, since each part depends on the one before it.
First, discover, in two hops, before you can do anything else. The client may start with nothing but a server URL. The usual sequence: call the server, receive a 401, retrieve its protected resource metadata, identify the authorization server or servers it names, retrieve that authorization server's own metadata, select the right one. Along the way it may need to check supported PKCE methods, grant types, registration mechanisms, and scopes (OAuth Authorization Server Metadata, OpenID Connect Discovery, and so on), since the two conventions disagree about where that document lives. A client that only works when a token has been manually configured ahead of time isn't implementing discovery, it's implementing a special case, and a client that skips validating the discovered issuer against the one it actually asked for has opened exactly the hole a hostile metadata document is built to exploit.
Once you know where to go, register, without assuming a prior relationship. Try a pre-registered client ID first, fall through to a Client ID Metadata Document, fall through again to Dynamic Client Registration only if nothing else is available, since that mechanism is deprecated as of the current revision, not gone, but no longer where a new client should start. The full priority order, and the two spec revisions that produced it, Client ID Metadata Documents recommended since 2025-11-25, Dynamic Client Registration deprecated in 2026-07-28 with at least a twelve-month window before it can be removed, is covered in depth in MCP Authorization: The Complete Developer Guide.
With an identity in hand, build one authorization request, and load it with everything that request needs to carry. That's three things at once, not three separate steps: PKCE, the resource parameter, and the minimum scope the task actually needs. PKCE is mandatory, not optional, and the client is the one that has to check code_challenge_methods_supported and refuse to continue if it's absent, since nothing about OAuth 2.1 defines a separate mechanism for that check, desktop apps, browser apps, IDE extensions, and CLI tools are public clients by default, and none of them can keep an embedded secret confidential, which is exactly what PKCE exists to make unnecessary. The resource parameter names the canonical URI of the specific server this token is for, sent regardless of whether the authorization server asks for it, which is what keeps one compromised server from becoming a working credential everywhere else the client goes. And the scope you request should be the minimum the current task needs, not everything the server advertises, with the user told which server is asking, what capability it needs, what data or action it affects, and how long the authority might remain valid, since connection consent is not the same thing as approval for every consequential action the agent might later decide to take. In other words, you can build the authorization URL something like this.
const authorizationUrl = new URL("https://login.example.com/authorize");
authorizationUrl.searchParams.set("response_type", "code");
authorizationUrl.searchParams.set("client_id", clientId);
authorizationUrl.searchParams.set("redirect_uri", redirectUri);
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
authorizationUrl.searchParams.set("code_challenge_method", "S256");
authorizationUrl.searchParams.set("resource", "https://mcp.example.com/mcp");
authorizationUrl.searchParams.set("scope", "documents:read");
This creates a two-sided control: the client requests narrowly, and the server independently refuses anything targeted elsewhere, so neither side is relying on the other to have gotten this right.
Once the user has authorized and the browser redirects back with a code, exchange it for tokens. Send the code to the authorization server's token endpoint together with the original PKCE verifier and the same resource parameter you sent in the request above, an authorization server that skipped verifying either one wouldn't be doing its half of the job. What comes back is a short-lived access token and, possibly, a refresh token, a client should never assume one will be issued.
Once you're actually holding tokens, keep them alive without either side finding out the hard way. Refresh before expiry, not after, and handle a 403 step-up by requesting the union of the challenge and whatever scope you already held, never a replacement. Isolate tokens and registration state by user and by issuer, and give the client a bounded response to a repeated insufficient-scope challenge rather than letting it loop or nag the user for authority that was already denied.
Server view, client view
Server and client are living through the same interaction, but neither one sees the other's half of it, which is worth spelling out once end to end.
From the server's side, a single request looks like this: receive a call without acceptable credentials, return a challenge naming where to find the metadata, receive a follow-up call carrying an access token, validate the token and its issuer, verify its resource or audience, authorize the specific tool operation and target, then return the result, a 401, or a 403 challenge.
From the client's side, the same interaction is a much longer arc: call the server, parse the challenge it returns, discover protected resource metadata, discover and validate the authorization server, identify or register itself, start Authorization Code with PKCE, get the user's authorization, validate the authorization response, exchange the code for tokens, call the server again, and only then handle whatever comes next, expiry, an insufficient-scope response, revocation, or reauthorization.
Neither side can compensate for the other's failure. A client cannot make up for a server that never enforces authorization once a token clears validation. A server cannot make up for a client that mishandles tokens, confuses one issuer for another, or requests more authority than the task in front of it needs.
Token passthrough and the confused deputy problem
Every mistake in the sections above is a failure to do one side's job correctly. This one is different. It's what happens when a server quietly does the client's job, or the client quietly does the server's, because somewhere in the code both roles get treated as one problem instead of two.
Token passthrough is the concrete shape of it. A server receives a token from a client, and instead of validating that token for its own use and then obtaining a separate token to call whatever it needs to call upstream, it just forwards the token it was handed. The moment it does that, the server has stopped being a resource server that happens to also make outbound calls, and become something with no clean name in the specification: a caller with more privilege than the request in front of it justifies, acting with authority nobody actually delegated to it for that specific action. That's the textbook confused deputy, and it's the same family of failure as the two FastMCP advisories above: a server ending up with authority nobody delegated to it.
The reverse direction is quieter and shows up less often in a security advisory, more often as an architectural smell: a client that starts trusting a server's own claims about what token it needs, rather than independently discovering, validating, and scoping its own request. A client that lets the server it's talking to decide what audience or scope to ask for, instead of deriving that from the server's own canonical URI the way the client section describes, has handed the server a say in its own privilege level. Neither direction requires malice. In both cases, one side has simply outsourced a security decision that was never the other side's to make.
Server and client responsibilities
Bookmark this table. It's the one page in this pair of pieces worth returning to mid-implementation.
| Responsibility | Server | Client |
|---|---|---|
| Issues tokens | Never, unless it separately plays the authorization-server role too | Never, obtains them from the authorization server |
| Publishes protected resource metadata | Yes, required | Consumes and validates it |
| Initiates discovery | No | Yes, both hops |
| Selects which advertised authorization server to use | No | Yes |
| Validates token issuer, audience, and resource | Yes, every request | Not applicable |
| Runs the authorization code flow with PKCE | No | Yes |
Sends the resource parameter | Not applicable | Yes, regardless of authorization server support |
Validates the RFC 9207 iss on the callback | Not applicable | Yes |
| Registers or identifies a client ID | Not applicable | Yes, following the CIMD-first priority order |
| Enforces tool- and object-level policy | Yes | Not applicable |
| Issues a 403 insufficient-scope challenge | Yes | Interprets it and requests step-up |
| May call an upstream API on the user's behalf | Yes, with its own separately obtained token | Not applicable |
| May obtain that token via RFC 8693 token exchange rather than passthrough | Yes, this is the legitimate path | Not applicable |
| May forward the token it received to another party | Never | Never |
| Refreshes and stores tokens | Not applicable | Yes |
Two rows never change no matter which side you're building, which is worth reading as its own sentence rather than two table cells: nobody passes a token through, and nobody assumes the other side already performed a check that belonged to its own role.
When your team builds both sides
Some deployments genuinely own both sides, an internal tool with a server your team wrote and a client your team also wrote, talking only to each other. The temptation there is to skip half of the server and client sections above, since you already know what the other side does. Resist it.
The two roles fail differently under change. Your server will eventually get a client it didn't write, whether that's a teammate's agent, a partner's integration, or simply next year's version of the same client with an upgraded SDK that discovers metadata slightly differently. Your client will eventually talk to a server you didn't write to, the moment anyone wants it to reach anything beyond the one you built first. Code that assumes the other side is the one you already know is code that has to be rewritten the first day that assumption breaks, rather than code that was already correct. Shared libraries are fine for common parsing and security utilities, but a shared configuration object should not be allowed to erase the boundary between what the client trusts and what the server trusts.
Build the server as if an arbitrary conformant client might connect. Build the client as if an arbitrary conformant server might answer. If you do both, you'll find you've built two things that happen to talk to each other well, rather than one thing pretending to be two.
Local servers over stdio
Everything above assumes an HTTP-based server, because the OAuth-based flow this piece describes applies to HTTP transports specifically. A server launched over stdio should not run that flow at all, and takes its credentials from the local environment instead.
That doesn't make a local server automatically safe. A local server can still read sensitive files, execute commands, modify the developer's environment, call remote APIs, or hold long-lived credentials, and the local transport changes how the client starts and talks to it, not what the process is allowed to touch. A local MCP server using an environment credential to call a source-control API still needs to constrain which operations and which repositories that credential can reach. Running locally is a transport decision. It is not, by itself, an authorization policy.
Agent identity is a separate layer
A user can authorize an MCP client to access a server, and that alone doesn't describe the complete action that follows. The same user might operate a coding agent, a finance assistant, a support agent, and an internal research agent, each with different instructions, tools, and autonomy. If every operation is recorded only as "performed by the user," an organization loses exactly the context it would need afterward: which agent acted, which host and client initiated it, which configuration the agent was running under, and whether a human approved it before it happened.
An OAuth client identity names the application, not necessarily the specific agent instance acting through it or the authority it's currently operating under. Everything in this piece establishes how a client obtains and presents authority correctly. It doesn't, on its own, solve the identity and governance question for the agent using that authority, and as a deployment grows to include more than one agent behind the same client, that gap stops being theoretical.
What developers should implement
An MCP server should:
- publish correct protected resource metadata;
- return a useful 401 challenge, and a 403 with
insufficient_scopewhen the token is valid but insufficient; - validate issuer, signature, resource, audience, expiry, and scope on every request;
- reject any token intended for a different resource;
- enforce authorization inside the tool handler, not at the token boundary;
- apply tenant, organization, and object-level policy where the operation actually happens;
- avoid token passthrough, and obtain a separate credential for every downstream resource;
- record the user, client, agent context, tool, target, policy decision, and result;
- support revocation and incident response.
An MCP client should:
- support both protected-resource and authorization-server discovery;
- validate every discovered issuer and metadata document before trusting it;
- use PKCE for every interactive flow, and confirm the authorization server supports it first;
- keep registration and token state isolated by authorization-server issuer;
- validate the authorization response, including state and the issuer where present;
- request the minimum authority a task needs, and explain the request to the user;
- handle an insufficient-scope challenge by requesting the union of old and new scope, without looping;
- protect access tokens, refresh tokens, codes, and PKCE verifier material in storage;
- refresh tokens before expiry where practical, not only after a call fails;
- support disconnect, cancellation, and revocation cleanly;
- avoid logging credentials or sensitive tool arguments.
The server protects the resource and decides whether an operation may happen. The client manages the authorization journey and carries the authority required to ask.
Where to go from here
If you're building a server, start with the protected-resource boundary: decide what the server actually protects, which scopes act as a stable capability gate, and where object-level policy has to live. If you're building a client, start with the connection lifecycle, and assume every server you'll ever talk to may use a different authorization server, registration method, scope vocabulary, and consent expectation than the first one you tested against.
Then test both sides on their own terms. For a server: can a missing, invalid, expired, wrongly targeted, or insufficiently privileged token still reach a sensitive operation? For a client: can it discover, obtain, isolate, store, refresh, revoke, and step up authority without ever confusing one server or authorization server for another?
Server auth and client auth are two sides of one interaction, but they are not interchangeable, and neither one is complete on its own. I hope this has drawn that line clearly enough to build against. For the full protocol flow, discovery, client registration, resource binding, just-enough and just-in-time access, human oversight, agent identity, and audit, continue with MCP Authorization: The Complete Developer Guide.
On this page
- The roles behind the specification
- What MCP server authorization means
- What MCP client authorization means
- Server view, client view
- Token passthrough and the confused deputy problem
- Server and client responsibilities
- When your team builds both sides
- Local servers over stdio
- Agent identity is a separate layer
- What developers should implement
- Where to go from here