Menu

How to Build an MCP Server in Next.js: Streamable HTTP, Auth and Tools
📰

How to Build an MCP Server in Next.js: Streamable HTTP, Auth and Tools

DEV Community: nextjs·Waseem Anjum·1 day ago
#d64HN0SC
#devtonextjs#devto#dev#server#tools
Reading 0:00
15s threshold

Cross-posted from my blog. The original, with any updates, lives on fabwaseem.com .

To build an MCP server in Next.js, install the official TypeScript SDK ( @modelcontextprotocol/server ), register your tools on an McpServer with Zod input schemas, wrap it with createMcpHandler , and export that handler as POST from an App Router route handler such as app/api/mcp/route.ts . Put an Origin check and bearer-token auth in front of it, and any MCP client can call your tools over Streamable HTTP.

This guide builds exactly that, step by step, using the current v2 SDK (version 2.3.1 at the time of writing). It is modelled on the real MCP server behind this site, fabwaseem.com , which lets an AI agent list, create and publish blog posts and portfolio projects through one authenticated endpoint.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.