Skip to main content
The Model Context Protocol (MCP) is an open standard that lets AI agents and clients like Claude discover and call tools over a well-defined interface. Anvil builds MCP support directly into the framework: the same route handler you write for your REST API can simultaneously be an agent-callable tool, with zero schema duplication.

Why Anvil’s approach is different

Most frameworks require you to maintain two parallel surfaces — an HTTP API and a separate tool definition — each with its own schema and validation logic. Anvil eliminates that split. When you mark a route with meta.mcp.expose, Anvil reads its paramsSchema (a Zod object you already defined for HTTP validation), converts it to JSON Schema automatically, and advertises the tool to MCP clients. The same handler function runs in both contexts.
┌─────────────────────────────────────────────────┐
│  server/routes/users/[id]/get.ts                │
│                                                 │
│  meta.mcp.expose = true  ──────────────────┐   │
│  paramsSchema = z.object({ id: z.string() })│   │
│  export default (ctx) => findUser(ctx.params.id) │
└─────────────────────────────────────────────────┘
         │                        │
         ▼                        ▼
  GET /users/:id          MCP tool: get_users_by_id
  (HTTP route)            (agent-callable)
Standalone tools that don’t map to an HTTP route live in server/tools/ and are served by the same command.

How it works

1

Annotate a route (or add a standalone tool)

Add meta.mcp.expose = true and a paramsSchema to any route file, or drop a new file in server/tools/ with a default function and an inputSchema.
2

Run anvil mcp

Start the MCP server with anvil mcp. By default it listens on :3100/mcp over Streamable HTTP. Pass --stdio for local clients like Claude Desktop.
anvil mcp              # Streamable HTTP → http://localhost:3100/mcp
anvil mcp --stdio      # stdio transport for Claude Desktop
3

Tools appear in your agent or client

Any MCP-compatible client — Claude Desktop, a custom agent built with the Vercel AI SDK, LangChain, or your own JSON-RPC client — can now discover and call your tools. Anvil handles the tools/list and tools/call protocol methods.

Transport modes

ModeCommandEndpointBest for
Streamable HTTPanvil mcphttp://localhost:3100/mcpRemote agents, AI frameworks, CI
stdioanvil mcp --stdiostdin/stdoutClaude Desktop, local CLI tools
The default port and endpoint (--port / --endpoint flags) can be changed at the command line. See the CLI reference for all flags.

What gets served

anvil mcp collects tools from two places and merges them into a single MCP server:
  1. Route-derived tools — every route file that exports meta.mcp.expose = true
  2. Standalone tools — every file in server/tools/ that default-exports a function
Tool names must be globally unique. Collisions are caught at startup with a clear error pointing to both files.
anvil lint validates MCP-exposed routes at build time: it checks that paramsSchema keys match the folder params in the path and that the schema converts losslessly to JSON Schema. Run anvil lint --strict to treat schema-conversion warnings as errors.

Learn more

Exposing Routes

Mark a route with meta.mcp.expose and let Anvil generate the tool definition from your existing Zod schema.

Standalone Tools

Define tools that aren’t tied to an HTTP route in server/tools/ and serve them from the same anvil mcp command.

Claude Desktop

Connect your Anvil MCP server to Claude Desktop in minutes using stdio mode and a one-line config snippet.