mcp_agent.config.yaml to specify how your agent should authenticate when acting as an MCP client.
API key (static) authentication
mcp_agent.config.yaml
- Store the actual token in
mcp_agent.secrets.yaml(deployment secret) ormcp_agent.configured.secrets.yaml(user secret). - At runtime,
ServerRegistryinjects theAuthorizationheader when connecting to the MCP server. - Supports any header name via
auth.headersif the server expects a custom format.
OAuth client credentials / authorization code
For MCP servers that implement OAuth (Linear, Notion, custom internal IdPs), configure theoauth block:
- When the agent first needs the server, the OAuth manager checks the token store.
- If no token exists, it launches an authorization flow (internal callback inside the deployment or local loopback while running locally).
- Access + refresh tokens are stored in the configured token store (memory or Redis).
- Tokens are refreshed automatically before expiry (
refresh_leeway_seconds).
Token store configuration
memory(default) – in-memory, process-scoped. Great for development but not shared across workers.redis– recommended for cloud deployments if your app uses multiple processes or needs persistence across restarts.
Seeding tokens manually
If you already have an access token:Request-time headers
For bespoke auth schemes, you can specify arbitrary headers or environment variables:Best practices
Keep secrets out of code
Keep secrets out of code
Always reference
${ENV_VAR} placeholders in config and store the actual values in secrets files. Never hardcode tokens in Python modules.Differentiate developer vs user secrets
Differentiate developer vs user secrets
If every user needs their own credential (e.g., personal GitHub PAT), mark it as
!user_secret so mcp-agent cloud configure collects it when they onboard the app.Token sharing
Token sharing
For OAuth-protected upstream servers you probably want a shared token cache (Redis) to avoid re-authorizing for every workflow run.
Handle scope failures
Handle scope failures
Downstream servers may reject requests if scopes are missing. Log the response body and expose a clear error so users know to re-run the configure flow.
