MCP tools
Connect to Model Context Protocol servers for external tool discovery and execution. MCP tools are automatically prefixed with {serverName}/ (e.g. filesystem/read_file) and injected into the agent’s reasoning loop alongside built-in tools.
Transports
Section titled “Transports”Four transports are supported, covering every MCP server deployment pattern:
| Transport | When to use |
|---|---|
"stdio" |
Local subprocess — npm packages, Docker, Python scripts, any executable |
"streamable-http" |
Modern remote servers (MCP spec 2025-03-26) — Claude.ai, Cursor, Stripe, cloud providers |
"sse" |
Legacy remote servers (MCP spec 2024-11-05) — older self-hosted setups |
"websocket" |
Real-time bidirectional servers |
stdio Transport
Section titled “stdio Transport”Launches a subprocess and communicates via JSON-RPC over stdin/stdout. The subprocess inherits the parent process environment by default.
const agent = await createAgent({ name: "fs-agent", provider: "anthropic", mcpServers: [{ name: "filesystem", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."], }], reasoning: {},});await using agent = await ReactiveAgents.create() .withProvider("anthropic") .withMCP({ name: "filesystem", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."], }) .withReasoning() .build();Per-server environment variables
Section titled “Per-server environment variables”Use env to inject secrets without relying on the global environment. These are merged on top of the parent process environment — only specify what differs:
.withMCP({ name: "github", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-github"], env: { GITHUB_PERSONAL_ACCESS_TOKEN: process.env.GH_TOKEN ?? "", },})Working directory
Section titled “Working directory”Set cwd to control where the subprocess starts. Useful when the MCP server reads relative paths:
.withMCP({ name: "project-tools", transport: "stdio", command: "node", args: ["./mcp-server.js"], cwd: "/home/user/my-project",})Docker containers
Section titled “Docker containers”command accepts any executable — docker works directly. Docker networking flags go in args:
.withMCP({ name: "my-server", transport: "stdio", command: "docker", args: [ "run", "-i", "--rm", "--network", "my-bridge-network", "-e", "INTERNAL_VAR=value", // container-only env (not secret) "ghcr.io/myorg/mcp-server:latest", ], env: { SECRET_KEY: process.env.SECRET_KEY ?? "" }, // passed to docker CLI, not container})Registry-resolved servers (Docker Hub, with more registries planned)
Section titled “Registry-resolved servers (Docker Hub, with more registries planned)”Instead of hand-writing the docker run config above, pass a catalog name as a plain string. .withMCP() resolves it through a pluggable MCPRegistry — Docker Hub’s mcp/* catalog (200+ verified server images) is the first registry, chosen via the registry option (defaults to "docker-hub"), so additional registries (an npm/npx-based catalog, a private org registry) can plug into the same .withMCP() call later without an API change. Image, transport, and args are resolved for you (the catalog-name string form is builder-only — declarative mcpServers accepts config objects, not catalog names):
const agent = await ReactiveAgents.create() .withProvider("anthropic") .withReasoning() .withMCP("filesystem") // single catalog name .withMCP("brave-search", { env: { BRAVE_API_KEY: process.env.BRAVE_API_KEY! } }) .build();A string[] batches multiple catalog names with no per-entry options — .withMCP(["filesystem", "brave-search"]).
A bare string and an MCPServerConfig object are unambiguous at the type level (a string can never be a config object), so both forms compose freely — chain .withMCP() as many times as you need. One call cannot mix a string with an object in the same array (.withMCP(["name", { name: "x", command: "echo" }]) is rejected, both by the TypeScript overloads and at runtime) — call .withMCP() once per input shape instead.
options on the single-name form:
| Option | Type | Purpose |
|---|---|---|
registry |
string |
Registry id to resolve against. Defaults to "docker-hub". |
env |
Record<string, string> |
Env vars the resolver validates against the catalog entry’s declared requirements — throws if a required one is missing. |
volumes |
{ host, container, readOnly? }[] |
Dynamic bind mounts for servers that need host filesystem access (e.g. filesystem, git). |
requireApproval |
boolean |
Whether the approval gate below applies to this call. Defaults to true. |
Streamable HTTP Transport
Section titled “Streamable HTTP Transport”The standard transport for modern remote and cloud-hosted MCP servers (MCP spec 2025-03-26). Uses a single POST endpoint — the server responds with either a plain JSON object or an SSE stream depending on the operation.
.withMCP({ name: "stripe", transport: "streamable-http", endpoint: "https://mcp.stripe.com", headers: { Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}` },})Session management is handled automatically: the session ID returned in the Mcp-Session-Id response header is captured and forwarded on all subsequent requests. When the agent is disposed, an HTTP DELETE is sent to cleanly terminate the session.
Auth Headers (SSE and Streamable HTTP)
Section titled “Auth Headers (SSE and Streamable HTTP)”Pass headers to send authentication credentials on every request. Use for Bearer tokens (OAuth, JWT, PAT), API keys, or any per-server auth:
// Bearer token (OAuth, PAT, JWT)headers: { Authorization: "Bearer ghp_..." }
// API key headerheaders: { "x-api-key": process.env.MCP_API_KEY ?? "" }
// Multiple headersheaders: { Authorization: "Bearer token", "X-Tenant-Id": "my-org",}OAuth 2.1 (auth)
Section titled “OAuth 2.1 (auth)”For remote servers (streamable-http/sse) protected by OAuth 2.1, pass an auth config and RA drives
the whole flow itself — discovery, token exchange, automatic refresh, and secure on-disk storage. The auth
config has no declarative mcpServers equivalent yet, so these examples are builder-only. This
is not available for stdio servers: a stdio config with auth set is a startup error — stdio
servers get credentials from the environment via env (see Per-server environment
variables above), not OAuth.
Picking a grant
Section titled “Picking a grant”| Situation | Grant |
|---|---|
| Unattended / production agent (cron, server, CI) — no human present | client_credentials |
| Same, but the server requires asymmetric client auth (JWT-signed) instead of a shared secret | private_key_jwt |
| A human is running an agent that needs to act on their own account | authorization_code |
client_credentials and private_key_jwt never open a browser or need a human — the agent authenticates
as itself:
const agent = await ReactiveAgents.create() .withMCP({ name: "billing", transport: "streamable-http", endpoint: "https://mcp.example.com/mcp", auth: { type: "client_credentials", clientId: process.env.MCP_CLIENT_ID!, clientSecret: process.env.MCP_CLIENT_SECRET!, }, }) .build();authorization_code delegates access to a specific user. It needs a one-time interactive login before
the agent runs — see rax mcp login below:
const agent = await ReactiveAgents.create() .withMCP({ name: "my-calendar", transport: "streamable-http", endpoint: "https://mcp.example.com/mcp", auth: { type: "authorization_code" }, // run `rax mcp login my-calendar` once first }) .build();interactive defaults to false. An unattended agent run must never unexpectedly try to open a
browser or bind a local port — if credentials aren’t already on disk (or in your tokenStore) when an
authorization_code server connects, the connection fails closed with an error instead of popping a
browser. Only rax mcp login (or explicitly passing interactive: true) triggers the interactive flow.
Secrets are plain config — you source them
Section titled “Secrets are plain config — you source them”clientSecret and privateKey (for private_key_jwt) are ordinary config values. RA does not do any
environment-variable interpolation — read them from process.env yourself, as in the example above.
Never hardcode a secret in source.
Where tokens are stored
Section titled “Where tokens are stored”By default, tokens are persisted to ~/.reactive-agents/mcp-auth/ — one file per resource, named by a
hash of the canonical resource URL (never the raw URL or client id). The directory is created chmod 0700 and each credential file chmod 0600; both get() and list() refuse to read a file whose
permissions have been loosened. You can supply your own store instead — e.g. an in-memory store for
tests/CI so nothing touches disk:
import { createMemoryTokenStore } from "@reactive-agents/tools"
const agent = await ReactiveAgents.create() .withMCP({ name: "billing", transport: "streamable-http", endpoint: "https://mcp.example.com/mcp", auth: { type: "client_credentials", clientId: "...", clientSecret: process.env.MCP_CLIENT_SECRET! }, tokenStore: createMemoryTokenStore(), }) .build();rax mcp login / logout / status
Section titled “rax mcp login / logout / status”Run once, ahead of time, for any server using authorization_code:
rax mcp login <name|--url <endpoint>> [--client-id <id>] [--client-secret <secret>] [--scope <scope>] [--redirect-port <port>] [--no-browser] [--timeout <ms>] [--mcp-config <path>]rax mcp logout <name|--url <endpoint>> [--mcp-config <path>]rax mcp statuslogin— runs the interactive authorization flow and stores the resulting tokens.<name>resolves against.rax/mcp.json(or--mcp-config <path>); use--url <endpoint>for an ad-hoc server with no config file.--no-browserstill prints the authorization URL (for headless/SSH sessions) but doesn’t try to launch one.--client-idskips dynamic client registration when the server needs a statically registered client.--client-secretis for a confidential OAuth client — some authorization servers (e.g. Google’s “Web application” client type) issue a secret alongside the client ID rather than a public/native client.--redirect-portpins the loopback callback to a fixed port instead of an ephemeral one; required by any authorization server that validatesredirect_uriby exact pre-registered match rather than accepting any loopback port — registerhttp://127.0.0.1:<port>/callbackas that server’s authorized redirect URI.logout— deletes the stored credentials for a server, attempting revocation first (best-effort; local deletion always happens even if the revocation endpoint is unreachable).status— lists every stored credential (resource, scope, expiry, whether a refresh token is present). Never prints access or refresh tokens.
What RA does not do
Section titled “What RA does not do”- Host an OAuth authorization server — RA is a client only; you point it at a server you (or a third party) already run.
- Anything beyond the MCP SDK’s own dynamic client registration (RA doesn’t add a second registration layer on top).
- OS keychain storage (macOS Keychain, libsecret, Windows Credential Manager) — the default store is a
permissioned file on disk. Bring your own
tokenStoreif you need keychain-backed storage. - RFC 8693 token exchange (delegating a user’s token to a sub-agent with attenuated scope).
- Tool-description pinning or re-consent when a server’s tool list mutates mid-session.
Multiple MCP Servers
Section titled “Multiple MCP Servers”Pass an array to connect multiple servers at build time:
const agent = await createAgent({ name: "multi-mcp-agent", provider: "anthropic", mcpServers: [ { name: "filesystem", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."], }, { name: "github", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-github"], env: { GITHUB_PERSONAL_ACCESS_TOKEN: process.env.GH_TOKEN ?? "" }, }, { name: "stripe", transport: "streamable-http", endpoint: "https://mcp.stripe.com", headers: { Authorization: `Bearer ${process.env.STRIPE_KEY}` }, }, ], reasoning: {},});await using agent = await ReactiveAgents.create() .withProvider("anthropic") .withMCP([ { name: "filesystem", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."], }, { name: "github", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-github"], env: { GITHUB_PERSONAL_ACCESS_TOKEN: process.env.GH_TOKEN ?? "" }, }, { name: "stripe", transport: "streamable-http", endpoint: "https://mcp.stripe.com", headers: { Authorization: `Bearer ${process.env.STRIPE_KEY}` }, }, ]) .withReasoning() .build();Marking MCP tools read-only
Section titled “Marking MCP tools read-only”By default every MCP tool is unclassified, so it is dropped when an agent is narrowed to read-only tools. Two operator-set fields on the server config change that:
readOnly: truemarks every tool on the server read-only;readOnly: ["lookup", "search"]marks only the named tools (names without theserver/prefix).trustAnnotations: truehonors the server’s own MCPreadOnlyHintannotation. Without it, annotations are ignored, because a malicious or buggy server can lie.
Both fields are part of the declarative agent config (mcpServers[].readOnly, mcpServers[].trustAnnotations), so they survive toConfig() / agentConfigToBuilder() round trips and JSON import/export.
A tool the server annotates destructiveHint: true or openWorldHint: true is never marked read-only, even if listed. Both fields are a promise by you, the operator: a wrong declaration exposes a mutating tool to non-owner senders. Trust is never inferred.
Tool effect: read, write or unknown
Section titled “Tool effect: read, write or unknown”Every tool resolves to one declared effect, exported as toolEffect(definition) (type ToolEffect):
| Effect | Meaning |
|---|---|
"read" |
Declared read-only (mutatesExternalState: false) and needs no approval. |
"write" |
Declared to change state outside the run (mutatesExternalState: true). |
"unknown" |
Nothing declared, or a read-only tool that requires approval. |
unknown is the default for your own defineTool() tools and for unannotated MCP tools. It is never eligible wherever only read-only tools may run (channel narrowing, bounded read-only recon): the effect is declared by the tool or operator, never guessed from a name or description. All built-in tools are classified read or write.
For MCP tools the mapping is: a trusted readOnlyHint: true (or an operator readOnly listing) gives read; destructiveHint: true or readOnlyHint: false gives write, honored even from an untrusted server because those hints only narrow; anything else, including openWorldHint: true alone, stays unknown. To let a server’s list_* tools count as read, set trustAnnotations: true or list them under readOnly.
Approval gating
Section titled “Approval gating”The effect also decides whether an approval policy gates the tool. With any .withApprovalPolicy() set, an MCP tool whose effect is write (destructiveHint: true or readOnlyHint: false) is gated automatically, even from an untrusted server. A read tool is not gated. An unknown tool is not gated by default, the same rule as a custom tool without requiresApproval. To gate one, name it in the policy’s tools by its prefixed name ("github/create_issue", that is server/tool), or match it with a requireFor predicate on toolName.
MCP tools connect after build(), so the gate reads the live tool registry on each reasoning pass. Before 0.19, MCP tools were never gated automatically. The full list of what a policy gates is in Human-in-the-Loop Approval.
Cleanup
Section titled “Cleanup”MCP stdio servers run as subprocesses — the process will hang if they aren’t shut down. Always dispose the agent when done. See Resource Management for full patterns.
// Option A: await using (recommended) — auto-disposes on scope exitawait using agent = await ReactiveAgents.create() .withMCP({ name: "fs", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."] }) .build();
// Option B: runOnce — build + run + dispose in one callconst result = await ReactiveAgents.create() .withMCP({ name: "fs", transport: "stdio", command: "bunx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."] }) .runOnce("What files are in this project?");Protocol Details
Section titled “Protocol Details”The MCP client is spec-compliant with MCP 2025-03-26:
- Sends
notifications/initializedafter the handshake (required by spec before any tool calls) - Negotiates protocol version
2025-03-26(servers may respond with an older supported version) - Tool results are extracted from the MCP
contentarray format — the model receives clean text, not raw JSON isError: trueresults from servers surface as tool execution errors in the agent loop
Install
Bun (recommended)bun add reactive-agentsNode 22.5+npm install reactive-agentsGet notified on new releases