- Outbound – the agent authenticates to downstream MCP servers or third-party APIs (OAuth 2.1, API keys, service accounts).
- Inbound – the agent itself acts as an OAuth-protected MCP server, validating bearer tokens before exposing tools or workflows.
Authenticating to downstream MCP servers
OAuth 2.1
Use themcp.servers.<name>.auth.oauth block to configure delegated flows. mcp-agent ships with a full OAuth client implementation that handles loopback callbacks, Redis-backed token storage, and background refresh.
mcp_agent.secrets.yaml, environment variables (export NOTION_CLIENT_SECRET=...), or MCP_APP_SETTINGS_PRELOAD.
Static headers / environment variables
When a server expects API keys or custom headers, configure them directly underauth or env. The Slack example (examples/usecases/mcp_basic_slack_agent) injects credentials via environment variables:
examples/mcp/mcp_sse_with_headers):
examples/model_providers show how to configure providers such as Azure OpenAI, Amazon Bedrock, Google Gemini, and Ollama using env vars or header-based credentials.
Protecting your agent with OAuth
If your MCP app should require bearer tokens from clients, enable theauthorization section. mcp-agent advertises the protected-resource metadata (/.well-known/oauth-protected-resource) and validates tokens via JWKS or introspection endpoints.
mcp_agent.secrets.yaml, environment overrides, preload strategies), see Configuring your application → Secrets.
Example projects
- examples/basic/oauth_basic_agent – minimal OAuth client that authenticates to GitHub and Notion MCP servers.
- examples/oauth/interactive_tool – demonstrates interactive authorisation from within a tool.
- examples/oauth/pre_authorize – seeds refresh tokens before launching a durable Temporal workflow.
- examples/mcp_agent_server/temporal – combines resource-server protection with long-running workflows and human approvals.
