Skip to content
DocsStar33Playground

rax serve

ReferenceLast updated 2026-12-04 · 99b8f5257Quickstart

Serve one agent to other programs. Part of the CLI reference.

  • --protocol a2a (default) serves the agent over the A2A protocol, so other agents can discover and call it.
  • --protocol mcp serves the agent to MCP hosts (Claude Code, Cursor, Codex) as one tool, run_agent. Walkthrough with host setup: Serve an agent over MCP.
Terminal window
rax serve [--agent <file> [--trust-file] [--allow-file-endpoint]]
[--protocol a2a|mcp] [--transport http|stdio] [--port <number>]
[--response-format text|json] [--run-timeout-ms <ms>]
[--steering [--allow-unauthenticated-steering]]
[--name <name>] [--provider <provider>] [--model <model>]
[--with-tools] [--with-reasoning] [--with-memory [enhanced]] [--expose-tools]

Serve an agent file (Open Agent Spec or AgentConfig JSON). --provider, --model and --name override the file, with the same rules as rax run --agent; --with-* flags add to it. An agent file problem exits with code 2.

Serve an agent file that starts local commands (stdio MCP servers), calls remote agents (agentTools[].remoteUrl), gives the model a shell (tools.terminal) or reads values from your environment. Without it, rax asks on a terminal and exits 2 elsewhere, including when an MCP host starts it over stdio. It also keeps the file’s telemetry and Cortex URL, which are dropped otherwise. See Files that run commands

Let the agent file’s llm_config.url receive your API key. Without it, rax exits 2 when a key would be sent there. See The file’s model endpoint

a2a or mcp

http or stdio. stdio needs --protocol mcp: the MCP host starts rax itself and talks to it over stdin and stdout

MCP only. json puts the full JSON result (answer, runId, …) in the tool’s text block, so an external agent can pipe it to jq. Works over HTTP and stdio. The same as responseFormat in agent.serveMCP(). A value other than text or json, or the flag with --protocol a2a, exits 2

MCP only. Wall-clock budget for one run, an integer from 1 to 2147483647. A run past it gets the tool error Agent run timed out. Works over HTTP and stdio. A bad value, or the flag with --protocol a2a, exits 2

MCP only. Also lists the steer_run tool, which queues a message onto a live run by id. The same as steering: true in agent.serveMCP(). The runtime does no authentication, so over HTTP the flag needs RA_MCP_TOKEN, else it exits 2; stdio is allowed because the host owns the pipe. The flag with --protocol a2a exits 2

Accepts --steering over HTTP without RA_MCP_TOKEN. Any caller that reaches the endpoint can then steer any run the server started whose id it knows. The flag reaches the runtime as allowUnauthenticatedSteering. Needs --steering, else exits 2

HTTP port. Not accepted with --transport stdio

Agent name: the A2A Agent Card name, or the MCP server name and the key in the printed host config

LLM provider: any built-in provider, including groq and xai, or test. Without --provider or an agent file, the served agent answers with the test provider

Model name

Enable the built-in tools (files, web, code), equivalent to .withTools({ builtins: true })

Enable reasoning strategies

Enable memory. With no extra token: default tier (.withMemory()). Pass enhanced or 2 immediately after the flag for full four-layer memory with embeddings (.withMemory({ tier: "enhanced" })). basic or 1 after the flag keeps the default tier.

Silence the tools warning for a non-loopback bind

When the agent has tools (built-ins, shell-execute or MCP servers) and the bind address is not loopback (RA_A2A_HOST, or RA_MCP_HOST for MCP over HTTP), rax serve prints a warning on stderr. It names the tools and the variable, because every caller with the token can then use those tools on this machine: read and write files, run code. Pass --expose-tools if that is what you want, or bind to 127.0.0.1. The server starts either way. stdio has no bind address and never warns.

Variable Applies to Description
<PROVIDER>_API_KEY both Provider key, for example ANTHROPIC_API_KEY. Without it, the key saved with rax keys set <provider> is used. A provider that needs a key and has neither exits with code 2
RA_A2A_HOST A2A Interface to bind. Default: loopback
RA_A2A_TOKEN A2A Static bearer token required on every request
RA_MCP_HOST MCP over HTTP Interface to bind. Default 127.0.0.1. A non-loopback address requires RA_MCP_TOKEN
RA_MCP_TOKEN MCP over HTTP Static bearer token: every request needs Authorization: Bearer <token>. The token authenticates the HTTP request only and never reaches the agent
RA_MCP_ALLOWED_HOSTS MCP over HTTP Comma-separated host names accepted in the Host header, for example agents.example.com,10.0.0.5. Required when RA_MCP_HOST is 0.0.0.0 or ::. Unset or empty: the defaults from the bind address apply

RA_SERVE_HOST and RA_SERVE_TOKEN still work for A2A, with a deprecation warning on stderr.

rax serve has no OAuth flags: for a remote deployment, set RA_MCP_TOKEN and put the server behind a TLS proxy. OAuth 2.1 resource-server mode is available from code with agent.serveMCP({ oauth }); see OAuth 2.1 resource server.

  • GET /.well-known/agent.json: Agent Card (A2A discovery)
  • GET /agent/card: Agent Card (fallback)
  • POST /: JSON-RPC 2.0 (message/send, tasks/get, tasks/cancel, agent/card)
Terminal window
rax serve --name researcher --provider anthropic --model claude-sonnet-4-6 --with-tools --port 4000
rax serve --agent helper.agent.json --port 4000
Terminal window
rax serve --agent researcher.agent.json --protocol mcp

The server listens on http://127.0.0.1:3001/mcp and prints the line to add to your MCP host config, for example {"mcpServers":{"researcher":{"url":"http://127.0.0.1:3001/mcp"}}}. With RA_MCP_TOKEN set, the printed config adds "headers": {"Authorization": "Bearer <RA_MCP_TOKEN>"}, a placeholder: rax never prints the token.

The endpoint accepts POST only (GET and DELETE get 405), and every other path gets 404. A request gets 403 when its Host header names a host other than an accepted one, or when it carries an Origin header. The accepted hosts are RA_MCP_ALLOWED_HOSTS when set, else the bind address (localhost, 127.0.0.1 or [::1] for the loopback default). Desktop hosts and CLIs send no Origin.

To bind every interface, set RA_MCP_HOST to 0.0.0.0 or :: together with RA_MCP_TOKEN and RA_MCP_ALLOWED_HOSTS, the host names clients use to reach the server:

Terminal window
RA_MCP_HOST=0.0.0.0 RA_MCP_TOKEN=... RA_MCP_ALLOWED_HOSTS=agents.example.com \
rax serve --agent researcher.agent.json --protocol mcp

A wildcard bind has no address clients can use, so the banner and the printed host config show the first RA_MCP_ALLOWED_HOSTS entry instead, for example http://agents.example.com:3001/mcp.

RA_MCP_ALLOWED_HOSTS entries are host names only. An entry with a port (agents.example.com:8080, [::1]:80) exits with code 2 before the server starts and says to drop the port. Write IPv6 addresses bracketed or bare ([::1] or ::1).

A wildcard RA_MCP_HOST without RA_MCP_ALLOWED_HOSTS exits with code 2 and names the missing variable. With the list but without RA_MCP_TOKEN, the server does not start and rax exits with code 1. To accept browser clients, use agent.serveMCP() with allowedOrigins: rax serve has no setting for it.

Terminal window
rax serve --agent researcher.agent.json --protocol mcp --transport stdio

The MCP host starts this command and exchanges JSON-RPC on stdin and stdout. stdout carries MCP messages only: the banner, the agent’s own output and logs go to stderr. On start, rax prints the host config on stderr, with the agent file path made absolute because hosts start the command from their own working directory:

{
"mcpServers": {
"researcher": {
"command": "rax",
"args": ["serve", "--agent", "/home/me/agents/researcher.agent.json", "--protocol", "mcp", "--transport", "stdio"]
}
}
}

The host starts rax without a terminal, so an agent file that starts local commands, calls remote agents, enables the shell or reads environment values needs --trust-file in those args; without it, rax exits 2. rax must be on the host’s PATH. Provider API keys come from the environment the host passes to the command (the env block in most host configs), else from the key saved with rax keys set <provider>, so a saved key keeps it out of the host config. Host-specific setup: Connect a host.

Stopped by SIGINT or SIGTERM. With --transport stdio, also when the host closes stdin

The agent failed to build or the server could not start (for example the port is in use, or a non-loopback RA_MCP_HOST without RA_MCP_TOKEN)

Usage or config error: an unknown option, a missing option value, an unknown --provider, --protocol or --transport, a --port outside 0-65535, --transport stdio without --protocol mcp, a --response-format other than text or json, a --run-timeout-ms outside 1-2147483647, --response-format or --run-timeout-ms with --protocol a2a, --port with --transport stdio, --steering with --protocol a2a or over HTTP without RA_MCP_TOKEN (and without --allow-unauthenticated-steering), --allow-unauthenticated-steering without --steering, a wildcard RA_MCP_HOST (0.0.0.0 or ::) without RA_MCP_ALLOWED_HOSTS, an RA_MCP_ALLOWED_HOSTS entry with a port, or an agent file problem (including a file that needs --trust-file off a terminal, or a file endpoint that would receive your key without --allow-file-endpoint)

The rest of the rax run process contract (pause, inspect, outcome exit codes) does not apply to rax serve.

Install

Bun (recommended)bun add reactive-agents
Node 22.5+npm install reactive-agents

Get notified on new releases

Release notes, about once a month.