Agents & MCP
Build a production MCP server as a Next.js route with mcp-handler: design tools as prompt engineering, wire strict zod schemas and Bearer auth, and evaluate every tool so the model actually calls it.
4 files
Description
Build a production MCP server as a Next.js route with mcp-handler: design tools as prompt engineering, wire strict zod schemas and Bearer auth, and evaluate every tool so the model actually calls it.
Build an MCP server whose tools a model can discover, call correctly, and recover from. This goes deeper than basic authoring: it assumes you are shipping a real HTTP server (not a local stdio toy), auth is required, and every tool call costs context or money.
Reach for this when you are:
route.ts pattern), not stdio.Work in this order. Skipping straight to code is the most common way tools end up unusable.
reference/tool-design.md.createMcpHandler with server.registerTool, wrap it in withMcpAuth + a verifyToken that resolves a Bearer key to a caller id, and return readable tool results (never throw across the transport). See reference/typescript_mcp_server.md.reference/evaluation.md.isError: true, not thrown exceptions. A thrown error kills the transport; a readable error lets the model recover..describe() on every field.limit, and summarize instead of dumping full tables.reference/tool-design.md - naming, descriptions, schemas, error results, pagination, free vs metered.reference/typescript_mcp_server.md - the concrete Next.js route.ts pattern with mcp-handler and auth.reference/evaluation.md - inspector, curl, result-shape asserts, an eval harness, and description iteration.Added 2026-07-01. Back to the Skill Library.

New tutorials, open-source projects, and deep dives on coding agents - delivered weekly.