Requirements
Before installing, make sure your environment meets these requirements:- Node.js ≥ 20 — Anvil relies on the native
Request,Response,Headers, andReadableStreamAPIs that ship with Node 20. - ESM project — Anvil is ESM-only. Your
package.jsonmust declare"type": "module". - npm, yarn, or pnpm — any of the three major package managers work.
Install the package
zod is a direct dependency of your route and tool schemas — install it alongside Anvil.
Configure package.json
Add"type": "module" to enable ESM, then add the Anvil CLI commands as scripts:
package.json
If you omit
"type": "module", Node treats your files as CommonJS and imports from anvil fail with a syntax error. ESM is required.Minimal project structure
Anvil expects your route handlers to live underserver/routes/. Everything else is up to you.
tsconfig.json for an Anvil project:
tsconfig.json
Optional peer dependencies
Anvil’s core routing and middleware work with no extra packages. The AI provider integrations and persistence adapters are optional peer dependencies, loaded lazily — install only what you use.Anthropic (Claude)
Required if you use
AnthropicDriver in an agent route or LLM client.OpenAI (GPT / o-series)
Required if you use
OpenAIDriver.Google Gemini
Required if you use
GeminiDriver.SQLite persistence
Required for
SqliteStateStore, SqliteTraceStore, or SqliteVectorStore — persistent traces, checkpoints, memory, and vectors across restarts.If you try to use a driver or store whose peer dependency is not installed, Anvil throws a clear error at the call site pointing you to the missing package and the in-memory alternative — it will not silently fail.
CLI commands reference
Once installed, theanvil binary is available in your node_modules/.bin/. Running it through npm run (or your package manager equivalent) is the recommended approach.
| Command | What it does |
|---|---|
anvil dev | Starts the dev server on port 3000 with watch mode. TypeScript routes are loaded on the fly via jiti. |
anvil build | Scans server/routes/, generates .gen/routes.ts, and bundles dist/server.mjs for production. |
anvil start | Runs the production bundle. Requires anvil build first. |
anvil lint | Validates all routes: checks paramsSchema keys match folder params, verifies MCP-exposed schemas convert cleanly to JSON Schema. Add --strict to fail on warnings. |
anvil mcp | Serves MCP-exposed routes and server/tools/ over Streamable HTTP on port 3100. Pass --stdio for Claude Desktop and similar local clients. |
anvil eval <file> | Runs a defineEvalSuite test file against an agent route; exits non-zero if any case fails. |
anvil replay <traceId> | Re-runs a captured agent trace with mocked model responses and recorded tool outputs — no live model calls. |
Verify the installation
Create a minimal route and start the dev server to confirm everything is working:server/routes/get.ts
Scaffold instead of hand-writing
Once installed,npx anvil init writes package.json (scripts + dependencies), tsconfig.json, .gitignore, and a starter route for you — pick a basic API, MCP server, or agent route template. See anvil init.
Next steps
Quickstart
Build a route, expose it as an MCP tool, and add a streaming agent — in one walkthrough.
File-Based Routing
The full routing convention: verbs, groups, catch-alls, and the route manifest.