MCP OAuth Integration
AgentArea exposes each MCP server instance as an OAuth 2.0 protected resource. MCP clients that implement RFC 9728 (Protected Resource Metadata) — including Cursor and Claude Desktop — can discover authorization requirements automatically, register as dynamic clients, and obtain access tokens without any manual configuration.The AgentArea API acts as a single Authorization Server URL for all MCP clients. Hydra handles token issuance internally; clients only ever interact with the AgentArea API endpoints.
How It Works
RFC 9728 Discovery
Clients discover the authorization server automatically via
.well-known metadata endpoints — no hardcoded URLs required.Dynamic Client Registration
Clients register via RFC 7591 DCR. AgentArea proxies registration to Hydra and injects sane defaults automatically.
Three Auth Types
MCP instances support
api_key, bearer, and oauth2 authentication. Credentials are stored encrypted and injected at request time.OAuth Links
Generate shareable, OAuth-protected links for MCP instances with workspace-scoped or public access control.
RFC 9728 Discovery Flow
This is the exact sequence a client like Cursor or Claude Desktop follows when it encounters an AgentArea MCP endpoint for the first time.GET /oauth2/auth is a browser redirect, not a proxy. Hydra must set its own session cookies directly in the browser — proxying this endpoint would break the login flow.Step-by-Step
Initial 401 Challenge
The client makes an unauthenticated request to
/mcp/{instance_id}. The API responds with 401 Unauthorized and a WWW-Authenticate header pointing to the protected resource metadata URL:Protected Resource Metadata
The client fetches the resource metadata to discover which authorization servers can issue tokens:
Authorization Server Metadata
The client fetches the AS metadata. AgentArea proxies this from Hydra’s OIDC configuration and rewrites all endpoint URLs to point to the AgentArea API:
Dynamic Client Registration (RFC 7591)
The client registers itself. AgentArea proxies the request to the Hydra admin API and automatically injects:
skip_consent: true— skips the OAuth consent screen for MCP clients- Default audience values scoped to the MCP instance
Authorization Code Flow
The client redirects the user’s browser to
/oauth2/auth. AgentArea forwards this as a browser redirect (302) to Hydra, which handles login and sets its session cookies. After authentication, Hydra redirects back with an authorization code.Auth Types for MCP Instances
MCP server instances can require authentication themselves — separate from the OAuth flow above. AgentArea supports three auth types that control how credentials are injected into outbound requests to the MCP server.- api_key
- bearer
- oauth2
Injects a static key as a custom HTTP header.Config fields:At request time, AgentArea injects:
header_name— the header to set (e.g.,X-API-Key)
header_value— the actual key value (stored encrypted)
Auth Config API
Create an Auth Config
Link Auth Config to an MCP Instance
Get Injected Headers (Internal)
Theget_auth_headers() method is called internally before each request to an MCP server. It returns the appropriate headers based on auth type — callers do not need to handle this manually.
OAuth Links
OAuth links let you share an MCP instance endpoint that enforces an Authorization Code flow before granting access. This is distinct from the DCR flow above — OAuth links use AgentArea’s own identity layer rather than Hydra.workspace
Access restricted to users in the same workspace. Suitable for internal team tooling.
public
Any authenticated AgentArea user can access the link. Suitable for published MCP servers.
Flow
Build Authorization URL
When a user visits the link, the service builds an authorization URL and redirects them to AgentArea’s login/consent flow.
Code Exchange and Session Creation
After the user authenticates, the authorization code is exchanged for an identity. A session is created with a 24-hour TTL and an opaque session token is returned.
Client Configuration
With RFC 9728 discovery, MCP clients authenticate automatically — you only need to point them at the SSE endpoint. No manual token setup required.- Cursor
- Claude Desktop
- Manual (PAT)
Add to your When Cursor connects, it will:
~/.cursor/mcp.json:- Receive a
401withWWW-Authenticateheader - Discover the authorization server via
.well-knownendpoints - Register itself as an OAuth client (DCR)
- Open your browser for authorization
- Exchange the code for tokens and connect
Hydra Proxy Architecture
/oauth2/auth?
Hydra sets session cookies during the login flow. Proxying this endpoint would cause the cookies to be scoped to the AgentArea API domain but sent to Hydra’s domain, breaking the session. The browser must talk to Hydra directly for this step.
Security Considerations
| Concern | Mitigation |
|---|---|
| Credential storage | All secrets encrypted via BaseSecretManager; never stored in plaintext |
| Token expiry | OAuth2 tokens auto-refreshed 30s before expiry; stale tokens never used |
| Consent bypass | skip_consent: true injected only for MCP client registrations |
| Access scope | OAuth links enforce workspace or public access control per-link |
| Session TTL | OAuth link sessions expire after 24 hours; no indefinite sessions |
| DCR exposure | Hydra admin DCR endpoint not exposed publicly; all registration proxied through API |