Install and scaffold
Create a project directory, install Anvil plus Zod (used for route and tool schemas), then scaffold:Plain objects returned from a handler are automatically serialized to JSON — no
anvil init prompts you to pick a template — choose basic for this walkthrough. It writes package.json ("type": "module" plus the dev/build/start/lint scripts), tsconfig.json, .gitignore, and a starter route at server/routes/get.ts:server/routes/get.ts
res.json(...) boilerplate. See anvil init for the MCP and agent templates, and Installation for optional peer dependencies (Anthropic, OpenAI, Gemini, SQLite).Start the dev server
jiti, so edits to route files take effect immediately — no separate compile step. Confirm it works:Add a dynamic route
Add a See Dynamic Routes for catch-all segments and Zod-validated params.
[param] folder for a path parameter:server/routes/users/[id]/get.ts
Expose the route as an MCP tool
Add two exports — Serve it:Any MCP client (Claude Desktop, an agent framework,
meta and a paramsSchema — and the same handler becomes an MCP tool, with zero duplicated schema:server/routes/users/[id]/get.ts
curl) can now call get_users_by_id — see MCP Overview.Next steps
File-Based Routing
Learn the full routing convention: verbs, groups, catch-alls, and the route manifest.
Dynamic Routes
Understand
[param] and [...param] segments, Zod validation, and naming rules.MCP Overview
Expose routes and standalone tools as MCP tools — no separate MCP server.
Agent Routes
Turn a route into a streaming AI agent with
defineAgent and an LlmClient.