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.…