Skip to content
Dashboard

OAuth support added to MCP Adapter

app/[transport]/route.ts
import { createMcpHandler, withMcpAuth } from 'mcp-handler';
const handler = createMcpHandler((server) => {
server.tool(
'roll_dice',
'Rolls an N-sided die',
{ sides: z.number().int().min(2) },
async ({ sides }) => {
const value = 1 + Math.floor(Math.random() * sides);
return { content: [{ type: 'text', text: `🎲 You rolled a ${value}!` }] };
}
);
})
const verifyToken = async (
req: Request,
bearerToken?: string,
) => {
if (!bearerToken) return undefined;
const isValid = bearerToken === '123';
if (!isValid) return undefined;
return {
token: bearerToken,
scopes: ['read:stuff'],
clientId: 'client123',
};
};
const authHandler = withMcpAuth(handler, verifyToken, {
required: true,
});
export { authHandler as GET, authHandler as POST };

Link to headingStart building secure MCP servers

MCP Server with Next.js

Get started building your first MCP server on Vercel.

Deploy now

Ready to deploy?