Turning existing Next.js API procedures into MCP tools: one public server, one admin
piotrkulpinski · reddit · 2026-10-30
The maker of Dirstarter, a paid Next.js directory boilerplate, explains how he built its MCP servers without writing a separate API for agents.
Architecture: two MCP servers run from Next.js route handlers — /mcp is public and read-only (assistants can search listings), while /api/mcp sits behind a bearer secret for write operations. The app's existing typed oRPC procedures become tools by adding a meta.mcp entry; a registry walks the router at startup and converts each Zod input to JSON Schema. Permission decides placement: guest-callable procedures go public, the rest go admin. Tool calls run the procedure itself, so permissions, rate limits, emails and webhooks behave exactly as in the UI.
Agent-friendliness details: errors start with a code (BADREQUEST, NOTFOUND) and list invalid fields so agents fix their input; tools that email in the UI default to not emailing over MCP; there is no delete tool at all; server instructions state that user-written text is data, never instructions; a test keeps each server under 25 tools and 25 KB of definitions since some clients load everything into context.
In a real Claude Code session, adding a listing from a URL took 7 tool calls and 54 seconds. Both servers are stateless and run fine on serverless hosting.
More from coding & agent
- Agentic MRI review takes 9th place out of 6299 teams in Kaggle RSNA knee abnormality detection — kagglingdieter · 2026-10-30
- Open-source Row-Bot demo: autonomous multi-turn agent finishes shop launch in 3 turns — Acceptable-Object390 · 2026-10-30
- Model choice is the least important decision in an AI project — alex_verem · 2026-10-30
- CapCut GPT in ChatGPT turns a prompt into a finished short video with script and voiceover in 5 minutes — thisguyknowsai · 2026-10-30
- Agent harness engineering: lessons from 57 papers — same model, 6x performance gap — Marmelab · 2026-10-30
- Two-person AI fight choreography on an RTX 3060: MiniMax H3 with first-frame, 18 storyboard frames and 3 LoRAs — JinnTsui · 2026-10-30