Skip to content
Dashboard

How to add OAuth 2.1 authorization to an MCP server on Vercel

Copy link to headingStep 1: Treat your MCP server as an OAuth resource server

Copy link to headingWhy the split happened

Copy link to headingStep 2: Install mcp-handler and pin a secure SDK version

Terminal
npm install mcp-handler@1.1.0 @modelcontextprotocol/sdk@1.26.0 zod@^3

Copy link to headingStep 3: Expose the protected resource metadata endpoint

import {
protectedResourceHandler,
metadataCorsOptionsRequestHandler,
} from 'mcp-handler';
const handler = protectedResourceHandler({
authServerUrls: ['https://your_auth_server_issuer_url_here'],
});
const corsHandler = metadataCorsOptionsRequestHandler();
export { handler as GET, corsHandler as OPTIONS };

Copy link to headingMatch resourceMetadataPath to your well-known path

Copy link to headingStep 4: Validate bearer tokens with withMcpAuth

import { withMcpAuth } from 'mcp-handler';
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
const verifyToken = async (
req: Request,
bearerToken?: string,
): Promise<AuthInfo | undefined> => {
if (!bearerToken) return undefined;
// Verify the signature against your IdP's JWKS endpoint,
// confirm the token was issued for this server, and read its claims.
const payload = await verifyWithYourIdp(bearerToken);
if (!payload) return undefined;
return {
token: bearerToken,
scopes: payload.scopes,
clientId: payload.client_id,
extra: { userId: payload.sub },
};
};
const authHandler = withMcpAuth(handler, verifyToken, {
required: true,
requiredScopes: ['read:stuff'],
resourceMetadataPath: '/.well-known/oauth-protected-resource',
});

export { authHandler as GET, authHandler as POST };

Copy link to headingRead auth info in your tools

Copy link to headingStep 5: Register OAuth clients with Client ID Metadata Documents

Copy link to headingStep 6: Fix the failure modes that break MCP server authorization in production

Copy link to headingStep 7: Verify the OAuth authorization chain end-to-end

Copy link to headingHarden your MCP server beyond the OAuth spec on Vercel

Copy link to headingFrequently asked questions about MCP server authorization

Copy link to headingDoes withMcpAuth work with STDIO transport?

Copy link to headingMy identity provider does not support Dynamic Client Registration. What do I do?

Copy link to headingCan I pass a user's bearer token to a third-party API my tool calls?

Copy link to headingWhich clients support the 2026-07-28 spec?

Copy link to headingWhat changed in mcp-handler v2 that could break my deployment?

Ready to deploy?