How to Deploy an MCP Server to Vercel
Updated 2026-11-24
Deploying an MCP server to Vercel turns a small TypeScript tool handler into a public Streamable HTTP endpoint your IDE or agent can call. Vercel’s mcp-handler package exposes tools on a Next.js App Router route; clients connect to https://your-app.vercel.app/api/mcp. Start locally with Build an MCP server in Python if you prefer Python, then mirror the same tool surface in TypeScript for hosting. Last tested 2026-11-24.
Prerequisites
- Node.js 22+ and a Vercel account
- A Next.js App Router project (create one with
create-next-appif needed) - Vercel CLI installed for deploy (
npm i -g vercel)
Docs used:
Steps
1. Add mcp-handler and MCP server packages
In your Next.js app directory:
npm i mcp-handler@2 @modelcontextprotocol/server@2 zod@4
Vercel’s guide pins mcp-handler v2 with @modelcontextprotocol/server v2 and Zod v4. Do not mix the older SDK-only stack unless you follow Vercel’s migration notes.
2. Create the MCP route
app/api/mcp/route.ts:
import { createMcpHandler } from "mcp-handler";
import { z } from "zod";
const handler = createMcpHandler((server) => {
server.registerTool(
"roll_dice",
{
description: "Roll an N-sided die",
inputSchema: z.object({ 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}!` }],
};
},
);
});
export { handler as GET, handler as POST };
Clients use Streamable HTTP against this route. Your framework chooses the path; Vercel’s examples mount at /api/mcp.
3. Test locally with MCP Inspector
npm run dev
npx @modelcontextprotocol/inspector@latest \
--server-url http://localhost:3000/api/mcp \
--transport http
Connect in the Inspector UI, list tools, and execute roll_dice. CLI check:
npx @modelcontextprotocol/inspector@latest --cli http://localhost:3000/api/mcp \
--transport http --method tools/list
4. Deploy to Vercel
vercel deploy
Production URL shape: https://your-project.vercel.app/api/mcp. Note the exact hostname Vercel prints.
5. Register the remote server in Cursor
Project or global .cursor/mcp.json:
{
"mcpServers": {
"vercel-dice": {
"url": "https://your-project.vercel.app/api/mcp"
}
}
}
Restart Cursor and confirm the server shows active under MCP settings. If the route is behind preview protection, send the x-vercel-protection-bypass header documented in Vercel’s deployment protection guide.
6. Call the same server from an AI SDK agent (optional)
import { createMCPClient } from "@ai-sdk/mcp";
import { generateText, isStepCount } from "ai";
const client = await createMCPClient({
transport: { type: "http", url: "https://your-project.vercel.app/api/mcp" },
});
try {
const { text } = await generateText({
model: "anthropic/claude-sonnet-4",
tools: await client.tools(),
prompt: "Roll a six-sided die once.",
stopWhen: isStepCount(5),
});
console.log(text);
} finally {
await client.close();
}
See Vercel’s AI SDK MCP guide for provider-specific model strings.
7. Add OAuth before production tools mutate data
For tools that write customer data, wrap the handler with withMcpAuth and publish OAuth metadata as in Vercel’s Enabling authorization section. Unauthenticated public dice demos can stay open; production CRM or billing tools should require bearer tokens.
Common errors
404 on /api/mcp after deploy. Confirm the file lives under app/api/mcp/route.ts in an App Router project and that you deployed the same branch.
Inspector connects locally but not in Cursor. Use the https production URL, not localhost. Cursor cannot reach your laptop from the cloud.
Function timeout on slow tools. Export maxDuration from the route or move long jobs to a Vercel Workflow, per Vercel’s MCP FAQ.
Package mismatch errors. Stay on mcp-handler@2 + @modelcontextprotocol/server@2. Mixing v1 SDK imports breaks registerTool.
FAQ
Do I need Next.js specifically?
Vercel documents Next.js App Router first, but createMcpHandler returns a Web Request → Response handler you can mount in other frameworks Vercel supports (FAQ on other frameworks).
How is this different from the Python MCP guide?
Build an MCP server in Python uses stdio for local clients. Vercel hosting needs HTTP transport so remote IDEs can connect.
Can I deploy without adding new npm dependencies to aiagenthowto.com?
This guide targets your MCP project’s package.json, not the Astro site repo. Run npm audit in that project before production.
What about Docker instead?
For always-on stdio bots, use How to deploy an AI agent with Docker. Use Vercel when you want a managed HTTPS MCP endpoint.
Related guides
- Build an MCP server in Python (local stdio server first)
- Connect an AI agent to an MCP server (Python client)
- GitHub MCP server (hosted remote MCP pattern)
- Fix: MCP server not connecting
- Fix: MCP authorization bearer error
- What is an AI agent?