Expose Next.js functions as MCP tools with Dendra A developer built Dendra, an open source MIT-licensed TypeScript framework that lets a single procedure definition—input schema plus handler—be exposed both as a Next.js API route and as a Model Context Protocol tool. In a walkthrough using Dendra 0.7.1 and the MCP TypeScript SDK 1.32.1, an addition procedure is served through a Next.js route and a local stdio MCP server sharing the same handler, with input validation rejecting non-numeric values with HTTP 400 and procedures lacking an explicit .ai() declaration excluded from the generated tool list. Expose a Next.js operation as an MCP tool with Dendra, sharing its input validation and handler. Your application already knows how to look up a record, calculate a result or create a task. When you add an AI assistant, those same operations need a tool name, an input schema and a way to execute them. I built Dendra, the open source framework used in this example, to keep those definitions together. Dendra is an open source TypeScript framework for typed APIs and explicitly enabled AI tools. A procedure contains the input contract and handler. Adapters connect that procedure to the interfaces your application needs, including Next.js API routes and Model Context Protocol tools. In this tutorial, we will expose one small operation through a Next.js route and a local MCP server. Both will use the same handler. We will also verify what happens when a tool receives invalid input or tries to call a procedure that has not been enabled for AI access. The example uses addition so the connection between the two interfaces is easy to inspect. The same structure can hold application logic such as searching your own records or calculating a project estimate. There are three pieces: The MCP server in this tutorial uses local standard input and output, usually called stdio. It runs as a separate process beside the Next.js application. A remote MCP endpoint requires additional HTTP transport and authentication setup. Start in an existing Next.js App Router project with TypeScript and Node.js 22 or later. The paths below assume an app directory at the project root. If your project uses src/app , place the router in src/server and adjust the MCP server import accordingly. This walkthrough uses Dendra 0.7.1 and the MCP TypeScript SDK 1.32.1: npm install dendra@0.7.1 @modelcontextprotocol/sdk@1.32.1 npm install --save-dev tsx@4.23.15 Use a supported, patched Next.js release for your application. The example adds Dendra and the MCP SDK to your existing project; it does not change your Next.js version. Dendra is released under the MIT license and is currently before version 1.0. Pinning the version makes this walkthrough reproducible while the framework develops. Create server/router.ts : js import { initDendra, s, type RouterRecord } from "dendra"; const { route } = initDendra