# Anvil JS ## Docs - [defineAgent: Create Streaming Anvil Agent Handlers](https://anvil.thatdevguy.in/agents/define-agent.md): Use defineAgent to turn any route file into a streaming AI agent. Configure the model client, system prompt, tools, and context pipeline in one place. - [LlmClient: Provider-Agnostic Model Calls in Anvil JS](https://anvil.thatdevguy.in/agents/llm-client.md): LlmClient wraps Anthropic, OpenAI, and Gemini behind one interface. Configure fallback chains, retries, structured output, and observability hooks. - [Multi-Agent Orchestration with Anvil AgentRegistry](https://anvil.thatdevguy.in/agents/orchestration.md): Use Anvil AgentRegistry to register agents, wrap them as tools, and delegate work in-process — no HTTP round-trips, no separate orchestration framework. - [Anvil JS Agent Routes: Build Streaming AI Agents](https://anvil.thatdevguy.in/agents/overview.md): Build streaming AI agents in Anvil JS. Drop an agent.ts into any route folder and Anvil streams responses using the Vercel AI SDK data protocol. - [Anvil Agent Tools: Zod Schemas and Execute Functions](https://anvil.thatdevguy.in/agents/tools.md): Define Anvil agent tools with Zod schemas and execute functions. The runtime validates inputs and feeds results back to the model in the tool loop. - [A2A Protocol: Expose Agents via Agent-to-Agent Standard](https://anvil.thatdevguy.in/background/a2a-protocol.md): Expose your Anvil agents over Google's Agent2Agent protocol alongside REST and MCP from a single route definition, using A2AServer and a2aHttpHandler. - [Scheduled Agents: Run Background Tasks on a Schedule](https://anvil.thatdevguy.in/background/scheduled-agents.md): Use defineSchedule and Scheduler to run background agent tasks on a cron schedule with full tracing, cost-governor, and guardrail support. - [Triggered Agents: Fire Tasks on Webhooks and Events](https://anvil.thatdevguy.in/background/triggered-agents.md): Use defineTrigger and TriggerRegistry to run background agent tasks in response to webhooks, queue messages, and other external events. - [anvil build: Generate the Manifest and Production Bundle](https://anvil.thatdevguy.in/cli/build.md): Scan routes, validate schemas, emit .gen/routes.ts, and bundle a self-contained dist/server.mjs production artifact ready to deploy. - [anvil dev: Start the Live-Reload Development Server](https://anvil.thatdevguy.in/cli/dev.md): Run a live-reload dev server that watches your routes directory and hot-reloads TypeScript route files without a separate compilation step. - [anvil eval: Run Deterministic and Judge-Based Eval Suites](https://anvil.thatdevguy.in/cli/eval.md): Run a defineEvalSuite test file against an agent route with deterministic and LLM-as-judge assertions; exits non-zero on failure for CI use. - [anvil init: Scaffold a New Anvil JS Project](https://anvil.thatdevguy.in/cli/init.md): Scaffold package.json, tsconfig.json, and starter routes for a new Anvil project — pick from a basic API, MCP server, or agent route template. - [anvil lint: Validate Routes, Params, and Tool Schemas](https://anvil.thatdevguy.in/cli/lint.md): Validate routes for param mismatches and lossy MCP schemas, printing structured diagnostics and exiting non-zero on errors or strict-mode warnings. - [anvil mcp: Serve Your Routes as an MCP Tool Server](https://anvil.thatdevguy.in/cli/mcp.md): Serve MCP-annotated routes and server/tools/ as an MCP tool server over Streamable HTTP or stdio for AI agents and clients like Claude Desktop. - [Anvil CLI Overview: Commands for Building Anvil Apps](https://anvil.thatdevguy.in/cli/overview.md): The anvil CLI is the primary interface for developing, building, and running Anvil apps — covering dev, build, MCP serving, lint, eval, and replay. - [anvil replay — Replay a Trace Without Live Calls](https://anvil.thatdevguy.in/cli/replay.md): Re-run a captured agent trace with mocked model responses and recorded tool outputs — no live model spend, no re-fired side effects. - [anvil start: Run Your Built Production Server Bundle](https://anvil.thatdevguy.in/cli/start.md): Launch the production server bundle built by anvil build, with an optional port override via flag or the PORT environment variable. - [Install Anvil JS: Setup, ESM Config, and Peer Deps](https://anvil.thatdevguy.in/installation.md): Install Anvil JS via npm, yarn, or pnpm, configure your ESM project, add optional AI provider peer deps, and set up your package.json scripts. - [Anvil JS: Node.js Backend Framework for AI Developers](https://anvil.thatdevguy.in/introduction.md): Anvil is a Node.js backend framework with file-based routing, compile-time validation, and a native agentic layer: MCP, tools, tracing, and more. - [Connect Anvil MCP Server to Claude Desktop — Guide](https://anvil.thatdevguy.in/mcp/claude-desktop.md): Use anvil mcp --stdio to connect your Anvil tools to Claude Desktop with a single config snippet — no separate server process required. - [Expose Anvil Routes as MCP Tools — Step-by-Step](https://anvil.thatdevguy.in/mcp/exposing-routes.md): Add two exports to any route file and Anvil automatically converts it into a fully typed MCP tool — same handler, no extra code. - [Anvil JS MCP: Expose Any Route as an AI Agent Tool](https://anvil.thatdevguy.in/mcp/overview.md): Anvil's MCP layer exposes your routes and standalone tools to any AI agent or MCP client — one codebase, one handler, no duplicated schemas. - [Standalone MCP Tools in Anvil JS via server/tools/](https://anvil.thatdevguy.in/mcp/standalone-tools.md): Add tool files to server/tools/ to expose MCP-callable functions that aren't tied to any HTTP route — served by the same anvil mcp command. - [Prompt Registry: Version, Diff, and Manage Prompts](https://anvil.thatdevguy.in/memory/prompt-registry.md): Store prompts as versioned, immutable artifacts with PromptRegistry. Pin routes to specific versions, diff changes, and roll back without a code deploy. - [RAG Pipeline: Build Retrieval-Augmented Generation](https://anvil.thatdevguy.in/memory/rag-retrieval.md): Index documents with Retriever, embed and store chunks in a VectorStore, then inject the most relevant context into your agent loop automatically. - [Semantic Cache: Skip Redundant LLM Calls by Similarity](https://anvil.thatdevguy.in/memory/semantic-cache.md): Use SemanticCache to skip redundant LLM calls when a semantically equivalent prompt has already been answered, cutting latency and token spend. - [Session Memory: Persist Agent Conversational State](https://anvil.thatdevguy.in/memory/session-memory.md): Use MemoryStore and the withMemory middleware to give each conversation its own typed, namespaced key-value memory backed by a pluggable StateStore. - [Cost Governor: Cap Per-Request Token and USD Spend](https://anvil.thatdevguy.in/observability/cost-governor.md): Cap per-request token usage and USD spend. Choose to block, degrade to a cheaper model, or route to human approval when a budget limit is hit. - [The /_anvil Dashboard: Inspect Traces and Agent Costs](https://anvil.thatdevguy.in/observability/dashboard.md): Anvil's built-in observability UI shows trace trees, token usage, and per-run costs in your browser — no extra tooling required. - [OpenTelemetry Export: Forward Agent Traces to Any Backend](https://anvil.thatdevguy.in/observability/otel.md): Forward Anvil traces to any OTel-compatible backend — Datadog, Grafana, Langfuse, Braintrust — using the built-in OTLP/HTTP exporter. - [Agent Tracing: Capture and Inspect Every Run in Anvil JS](https://anvil.thatdevguy.in/observability/tracing.md): Record every model call, tool execution, and retrieval step as a structured span tree. Query traces in the dashboard or export them to any OTel backend. - [Quickstart: Build Your First Anvil JS API in Minutes](https://anvil.thatdevguy.in/quickstart.md): Install Anvil, create your first file-based route, run the dev server, and expose a route as an MCP tool — all in under five minutes. - [The Anvil Context Object: Request and Response API](https://anvil.thatdevguy.in/routing/context.md): Reference for the Context class: typed request properties, cached body parsing, response helpers, ctx.state for middleware data, and HttpError. - [Dynamic Routes: URL Params and Catch-All Segments in Anvil](https://anvil.thatdevguy.in/routing/dynamic-routes.md): Use [param] folders for named path parameters and [...param] for catch-all segments. Validate params at compile time with a Zod paramsSchema. - [File-Based Routing: Map Files to HTTP Endpoints in Anvil](https://anvil.thatdevguy.in/routing/file-based-routing.md): How Anvil maps server/routes/ to HTTP endpoints: one file per HTTP verb, auto-serialization, route groups, and the build-time static manifest. - [Middleware in Anvil JS: Scoped _middleware.ts Files](https://anvil.thatdevguy.in/routing/middleware.md): Use _middleware.ts files to run middleware for all routes under a folder. Compose multiple functions, pass data via ctx.state, and add CORS with cors(). - [Durable Execution: Checkpoint and Resume Agent Runs](https://anvil.thatdevguy.in/safety/durable-execution.md): Checkpoint every agent iteration so a crash or redeploy resumes from the last completed step. Completed side-effect tools are never re-executed on resume. - [Guardrails: Content Filtering, PII Redaction and Tool Policy](https://anvil.thatdevguy.in/safety/guardrails.md): Add centrally-enforced content filters, PII redaction, tool allowlists, and prompt-injection defences to every agent route in Anvil JS. - [Human-in-the-Loop: Pause and Approve Agent Actions](https://anvil.thatdevguy.in/safety/human-in-the-loop.md): Suspend an agent run mid-execution, persist its state, and resume it after a human reviews and approves or rejects a pending action.