---
title: "MCP with Next.js"
description: "Run an Model Context Protocol (MCP) server on Vercel with Next.js."
url: "https://vercel.com/templates/next.js/model-context-protocol-mcp-with-next-js"
links:
  repository: "https://github.com/vercel-labs/mcp-for-next.js"
  demo: "https://github.com/vercel-labs/mcp-for-next.js"
  deploy: "https://vercel.com/new/clone?demo-title=MCP+with+Next.js&demo-description=Run+an+Model+Context+Protocol+%28MCP%29+server+on+Vercel+with+Next.js.&demo-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fmcp-for-next.js&demo-image=%2F%2Fimages.ctfassets.net%2Fe5382hct74si%2F73N0dZEENNBHEK030NFGlR%2F643235f2fbd7c082c7333bb315fab891%2FMCP__6_.jpg&project-name=MCP+with+Next.js&repository-name=model-context-protocol-mcp-with-next-js&repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fmcp-for-next.js&from=templates&skippable-integrations=1"
---

# MCP with Next.js

Run an Model Context Protocol (MCP) server on Vercel with Next.js.

# Example Next.js MCP Server

**Uses `mcp-handler`**

## Usage

This sample app uses the [Vercel MCP Adapter](https://www.npmjs.com/package/mcp-handler) that allows you to drop in an MCP server on a group of routes in any Next.js project.

Update `app/[transport]/route.ts` with your tools, prompts, and resources following the [MCP TypeScript SDK documentation](https://github.com/modelcontextprotocol/typescript-sdk/tree/main?tab=readme-ov-file#server).

## Notes for running on Vercel

- To use the SSE transport, requires a Redis attached to the project under `process.env.REDIS_URL` and toggling the `disableSse` flag to `false` in `app/mcp/route.ts`
- Make sure you have [Fluid compute](https://vercel.com/docs/functions/fluid-compute) enabled for efficient execution
- After enabling Fluid compute, open `app/route.ts` and adjust `maxDuration` to 800 if you using a Vercel Pro or Enterprise account
- [Deploy the Next.js MCP template](https://vercel.com/templates/next.js/model-context-protocol-mcp-with-next-js)

## Sample Client

`script/test-client.mjs` contains a sample client to try invocations.

```sh
node scripts/test-client.mjs https://mcp-for-next-js.vercel.app
```

## Related Templates

### [Block AI Bots Firewall Rule](https://vercel.com/templates/other/block-ai-bots-firewall-rule)

Adds a rule to your Vercel Firewall that detects common AI Bots.

### [AI SDK Image Generator](https://vercel.com/templates/next.js/ai-sdk-image-generator)

An open-source AI image generator built with Next.js, the AI SDK, and various AI providers (Replicate, Fireworks, Google Vertex AI, OpenAI)

### [Liveblocks Notion-like AI Editor](https://vercel.com/templates/next.js/liveblocks-notion-like-ai-editor)

A Notion-like collaborative text editor with AI features built with Liveblocks, Lexical, Vercel AI SDK, and Next.js.

---

## Additional documentation

The [Vercel Knowledge Base](https://vercel.com/kb) contains guides and answers to common questions about Vercel, including deployment, framework configuration, domains, caching, and troubleshooting.
