MCP OAuth
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), 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, mcpLogin 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-stdin] [--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. A confidential OAuth client also needs a secret: some authorization servers (e.g. Google’s “Web application” client type) issue one alongside the client ID rather than a public/native client. SetRA_MCP_CLIENT_SECRET, or pass--client-secret-stdinand pipe the secret in or type it at a hidden prompt. The secret is never an argument (shell history,ps):--client-secret <value>exits2without echoing the value.--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). Revocation goes only to the authorization server the login was made with. A login stored before v0.20, or one whose server now names a different authorization server, is signed out locally without revoking, andraxsays so; revoke it at the provider if needed.status— lists every stored credential (resource, scope, expiry, whether a refresh token is present). Never prints access or refresh tokens.
Sign in from your own app (mcpLogin)
Section titled “Sign in from your own app (mcpLogin)”To run the sign-in from your own server or UI instead of the CLI, use the public API in
@reactive-agents/tools (also re-exported from reactive-agents/tools). mcpLogin runs the same flow as
rax mcp login: discovery, dynamic client registration when you pass no clientId, then authorization
code + PKCE with the redirect going to a loopback listener on 127.0.0.1. Tokens go to the same store
(~/.reactive-agents/mcp-auth/ unless you pass store), so a login from either one works for the other.
import { Effect } from "effect";import { mcpAuthStatus, mcpLogin, mcpLogout, listMcpLogins } from "@reactive-agents/tools";
const endpoint = "https://mcp.example.com/mcp";const showLinkToUser = (link: string) => console.log(`Sign in: ${link}`); // replace with your UI
const result = await Effect.runPromise( mcpLogin(endpoint, { onAuthorizationUrl: (url) => showLinkToUser(url.toString()), }),);// result.expiresAt, result.scopes, result.hasRefreshToken: no token values
const status = await Effect.runPromise(mcpAuthStatus(endpoint)); // status.state: "signed-in" | "expired" | "absent"const logins = await Effect.runPromise(listMcpLogins());await Effect.runPromise(mcpLogout(endpoint));mcpLogin(endpoint, options)takesclientId,clientSecret,expectedIssuer(see Issuer binding),scopes,redirectPort,timeoutMs(default 5 minutes) andname. The endpoint must be HTTPS unless it is a loopback address. WithonAuthorizationUrlset, no browser opens unless you also passopenBrowser: true; without it, the system browser opens.mcpAuthStatus(endpoint)reads only the store (no network call).expiredmeans the access token is past its reported lifetime; ifhasRefreshTokenis true, the next connection may still refresh it.mcpLogout(endpoint)tries to revoke the refresh token (best-effort; passrevoke: falseto skip), then deletes the stored credentials. The result’srevocationfield says what happened:"revoked","none","unsupported","insecure-endpoint","issuer-mismatch"or"failed".listMcpLogins()lists every stored login, signed-in or expired.
None of them return token values. Each returns an Effect; failures are typed McpLoginError (login) or
McpAuthStoreError (store read or delete).
Stored logins are reused automatically
Section titled “Stored logins are reused automatically”A streamable-http or sse server configured with only its endpoint (no auth) uses a stored login for
that exact URL. RA sends the stored token and refreshes it when it expires, and never opens a browser.
The token is only looked up under that endpoint’s own key, so it never goes to a different server. No
stored login means the server connects without auth, as before.
const agent = await ReactiveAgents.create() .withMCP({ name: "my-calendar", transport: "streamable-http", endpoint: "https://mcp.example.com/mcp", // signed in earlier with mcpLogin or rax mcp login }) .build();The reuse is skipped when the endpoint is plain HTTP to a non-loopback host, or when you set your own
Authorization header. To turn it off for a server, set auth: false on its MCPServer config.
A server that needs a login and has none fails build() with MCPConnectionError and
reason: "auth-required" (see Connection failures). In Cortex, the same
login can be made with Sign in under Lab › Tools › Servers (see Cortex MCP
sign-in).
Issuer binding and guarded discovery
Section titled “Issuer binding and guarded discovery”An MCP server names its authorization server during discovery, and it can name a different one each time. RA’s OAuth providers bind to one authorization server and send credentials only there:
- Binding. Set
expectedIssuer(on aclient_credentials,private_key_jwtorauthorization_codeconfig, or onmcpLogin) to the authorization server’s issuer URL and the provider is bound to it from the start. Without it, the first discovery of each connect or login binds. A trailing/difference still matches. - Mismatch. A later discovery that names a different authorization server, for example between the
browser redirect and the code exchange, fails with
McpIssuerMismatchErrorbefore anything is sent to it. The code, PKCE verifier and client secret never reach the new server.mcpLoginreports it as anMcpLoginErrorcarrying the same message. - Guarded fetch. Discovery and token requests go through a guarded
fetch. Requests to the configured MCP endpoint’s own origin pass. Anything else must be HTTPS and not a private or reserved IP literal; cloud-metadata and link-local targets are refused everywhere; loopback is allowed only when the endpoint itself is loopback. Redirects are not followed. A refused request fails withMcpAuthFetchRefusedErrorand nothing is sent. Hostnames are not resolved, so a public name that resolves to a private address is not caught. - Logout.
mcpLogoutrevokes only at the authorization server stamped on the stored login. If the server now names a different one, or the login predates issuer binding (v0.20), the result isrevocation: "issuer-mismatch": the credentials are deleted locally and nothing is sent.
const agent = await ReactiveAgents.create() .withMCP({ name: "my-calendar", transport: "streamable-http", endpoint: "https://mcp.example.com/mcp", auth: { type: "authorization_code", expectedIssuer: "https://auth.example.com" }, }) .build();A type: "provider" config (your own OAuthClientProvider) gets neither the binding nor the guarded
fetch; it owns its network policy.
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.
Install
Bun (recommended)bun add reactive-agentsNode 22.5+npm install reactive-agentsGet notified on new releases
Release notes, about once a month.