Skip to main content
12 min read

Custom MCP OAuth

Custom MCP OAuth

Custom MCP integrations accept three ways to authenticate: a static header, application credentials (OAuth 2.0 client credentials), or per-user sign-in (OAuth/OIDC). This page covers the two OAuth flows. For the basics of adding a custom MCP server, see Integrations.

Available for roles: Admin Workspace Admin

Scope: Workspace

Which flow do you need?​

QuestionUse this flow
Does the MCP server accept one application identity, and must scheduled runs and webhooks work without a person signed in?Client credentials (M2M)
Does the server need to know who is calling, with each person signed in through your identity provider (IdP)?Per-user sign-in
Does the server accept a long-lived static bearer token or API key in a header?Static header, covered in Integrations; no OAuth needed

Both flows work with any standards-compliant OIDC provider: AWS Cognito, Okta, Microsoft Entra ID, Keycloak, and others.

Client credentials (application to application)​

Best for an MCP gateway or API that authenticates the application itself. AWS Bedrock AgentCore MCP Gateway fronted by a Cognito app client is the reference example. No browser sign-in, no callback URL. This flow also serves scheduled runs, webhooks, and other unattended automation.

How it works​

  1. On save, Aiden tests the token endpoint with your client ID and secret (negotiating either HTTP Basic auth or POST-body credentials automatically). A wrong secret, a bad scope, or an unreachable endpoint fails immediately with a clear error.
  2. On each use, Aiden exchanges the client ID and secret for a short-lived access token, caches it in memory per pod until 60 seconds before expires_in (or for 5 minutes if the provider omits expires_in), and sends Authorization: Bearer <token> on tool discovery and every tool call.
  3. When the token expires, or if the MCP server returns HTTP 401 or 403 on either tool discovery (tools/list) or a tool call (tools/call), Aiden evicts the cached token and mints a fresh one on the next request. Nothing runs with a missing credential: if the identity provider is down, the call fails with an error instead of a silent empty header.
  4. Your client secret never leaves Aiden's vault. Only the resulting bearer token is sent to the MCP server.

Rotation and editing are straightforward: when you open Edit Connection on a saved integration, the Token URL, Client ID, and Scopes are prefilled while the Client Secret remains masked. Leave the Client Secret field blank to keep the saved secret, or enter a new value to rotate it immediately.

Set up the app client (Cognito example)​

In your Cognito user pool:

  1. Configure a user pool domain (prefix or custom domain). Cognito serves /oauth2/token from the pool domain (for example https://<your-domain>.auth.<region>.amazoncognito.com/oauth2/token), while OIDC discovery stays on https://cognito-idp.<region>.amazonaws.com/<user-pool-id>/.well-known/openid-configuration.
  2. Create an app client with a client secret, and enable the Client credentials grant (client_credentials).
  3. Create a custom resource-server scope (for example mcp-api/read or mcp-api/invoke) and allow it on the app client. Cognito rejects this grant with invalid_scope when the scope is not a custom resource scope; openid, email, and profile do not work for client_credentials. Multiple scopes can be separated by spaces or commas (for example mcp-api/read mcp-api/invoke).
  4. Configure your MCP gateway or server's JWT authorizer to accept the Cognito token:
    • Claim difference (client_id vs aud): Cognito access tokens place the application client ID in the client_id claim and omit aud (unlike Okta, Auth0, and Microsoft Entra ID, which populate aud). In a 2-legged client_credentials token, sub equals client_id and there is no username claim.
    • Amazon Bedrock AgentCore MCP Gateway (CUSTOM_JWT): set discoveryUrl to https://cognito-idp.<region>.amazonaws.com/<user-pool-id>/.well-known/openid-configuration and add the Cognito app client ID under allowedClients (not allowedAudience).
    • Amazon API Gateway v2 (HTTP API) JWT Authorizer: set Issuer to https://cognito-idp.<region>.amazonaws.com/<user-pool-id> and add the Cognito app client ID to Audience (API Gateway matches Cognito's client_id claim against its audience list).

For other providers, create a client allowed to use the client_credentials grant and note its token URL and allowed scopes.

Verify the token exchange with curl (optional pre-flight check)​

Before saving the integration in Aiden, you can verify that your IdP issues a token for your client credentials and scope:

curl -s -X POST 'https://<your-domain>.auth.<region>.amazoncognito.com/oauth2/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=<CLIENT_ID>' \
--data-urlencode 'client_secret=<CLIENT_SECRET>' \
--data-urlencode 'scope=<resource-server>/invoke'

A working client returns HTTP 200:

{
"access_token": "<ACCESS_TOKEN_JWT>",
"expires_in": 3600,
"token_type": "Bearer"
}

Connect the integration​

  1. Open Workspace Settings -> Connections -> Integrations and click Add integration.
  2. Choose Custom MCP, select Streamable HTTP or SSE, and enter the server URL.
  3. Under authentication, choose OAuth 2.0 client credentials and enter the token URL, client ID, client secret, and the scope.
The token URL must be public HTTPS

Aiden only sends your client secret to token endpoints it can reach and verify: private, loopback, and cloud metadata addresses are refused at save time. If your identity provider is only reachable behind your network, see OAuth, IP allowlists, and private networks.

  1. Click Validate and discover. A successful discovery lists the tools the server serves; a failure names the exact problem (rejected credentials, missing scope, unreachable endpoint).

Per-user sign-in​

Best for servers that authorize per person: each user signs in with your IdP, and Aiden calls the MCP server with that person's token. Tool calls carry the caller's identity, so the server's own logs and permission checks know who acted.

How it works​

  1. An admin registers your IdP details with Aiden once, per environment.
  2. Each user opens the integration, clicks Connect, and signs in with their IdP account.
  3. Aiden stores the returned tokens and refreshes them automatically before they expire.
  4. On tool discovery and every tool call, Aiden sends that user's access token. If the IdP session was revoked, the user sees a reconnect prompt, not a broken integration for everyone else.

A static header you set on the secret wins over the user token. Keep static headers off per-user integrations so the signed-in identity is the one the server sees.

Set up the app client (Cognito example)​

In your Cognito user pool:

  1. Configure a user pool domain; /oauth2/authorize and /oauth2/token are served from the pool domain (https://<your-domain>.auth.<region>.amazoncognito.com), not from the cognito-idp API host.
  2. Create an app client with the Authorization code grant (code), a client secret, and refresh tokens enabled.
  3. Add the exact Vault callback URL to the app client's Allowed callback URLs: {oauth.publicBaseUrl}/v1/credential-providers/<provider-name>/token (for example https://<your-aiden-host>/api/vault/v1/credential-providers/<provider-name>/token). The callback must use HTTPS behind your ingress.
  4. Allow the scopes your server validates, typically openid, email, profile, plus any custom resource-server scopes (such as mcp-api/read and mcp-api/invoke).

The MCP server or gateway in front of it must validate the access tokens (iss, expiry, and client_id or aud). On Cognito, 3-legged user access tokens carry the signed-in user's identity in sub and username, and the app client ID in client_id. If the same MCP gateway serves both 2-legged M2M and 3-legged per-user traffic, include both Cognito app client IDs in the gateway authorizer's allowedClients (Bedrock AgentCore Gateway) or Audience (API Gateway v2 JWT Authorizer) list.

Register the provider (admin, once)​

An admin registers the IdP client with Aiden, one provider per environment or region. Multiple providers can share the mcp subcategory; when one provider is registered it is selected automatically, and when two or more exist the wizard displays a provider dropdown.

You can register the provider directly in the Aiden UI wizard or through the REST API:

Option 1: Register inline in the Aiden UI

  1. Open Workspace Settings -> Connections -> Integrations -> Add integration -> Model Context Protocol.
  2. Under Authentication, choose OAuth 2.0 User Sign-In.
    • If no mcp provider is registered yet, the inline registration form opens automatically. If providers already exist, click + Register new OAuth provider.
  3. Enter a Provider Name (for example cognito-prod) and click Copy next to the auto-computed OAuth Callback URL (https://<your-aiden-host>/api/vault/v1/credential-providers/cognito-prod/token) to add it to your IdP app client's Allowed Callback URLs.
  4. Enter the Authorization URL, Token URL, OAuth Client ID, OAuth Client Secret, and OAuth Scopes (openid email profile mcp-api/read mcp-api/invoke), then click Register OAuth provider.

Option 2: Register via the REST API

POST /api/vault/v1/credential-providers
{
"name": "cognito-prod",
"subcategory": "mcp",
"client_id": "YOUR_APP_CLIENT_ID",
"client_secret": "YOUR_APP_CLIENT_SECRET",
"auth_url": "https://<your-domain>.auth.<region>.amazoncognito.com/oauth2/authorize",
"token_url": "https://<your-domain>.auth.<region>.amazoncognito.com/oauth2/token",
"scopes": [
{ "name": "openid", "label": "Sign in", "required": true },
{ "name": "email", "label": "Read your email address", "required": true },
{ "name": "profile", "label": "Read your profile", "required": false },
{ "name": "mcp-api/read", "label": "Discover MCP tools", "required": true },
{ "name": "mcp-api/invoke", "label": "Invoke MCP tools", "required": true }
]
}

The subcategory must be mcp. The name appears in the sign-in picker, and the callback URL registered with your IdP must match /v1/credential-providers/<name>/token. Client ID and secret are encrypted at rest; rotate the secret with a provider update, no restart.

Workspace and organization scoping:

  • Calling POST /api/vault/v1/credential-providers without ?orgId=... registers the provider at the tenant level so it is available to all workspaces in your tenant.
  • Passing ?orgId=<workspace-id> scopes the provider to that workspace only. Two independent organizations can register the exact same provider name (such as cognito-prod) pointing to their own separate IdP app clients without collision; each organization receives an isolated provider ID.

Connect, per user​

  1. Open Workspace Settings -> Connections -> Integrations and add a Model Context Protocol integration.
  2. Enter the Server URL and choose OAuth 2.0 User Sign-In under Authentication (without adding a static Authorization header).
  3. In the Sign in with your account section, pick your provider (for example cognito-prod) and click Connect.
  4. Complete the sign-in at your IdP. You return to the wizard with your form draft preserved and a Connected badge shown.
  5. Click Validate and discover, then Save. The integration binds both the server URL secret and the credential provider so tool discovery and every tool call carry your personal access token.

Credential precedence​

When more than one credential source is present on a Custom MCP integration, Aiden evaluates Authorization in a fixed 4-tier order:

  1. Static Authorization header stored in the integration's Custom Headers (always wins if present).
  2. Per-call 3-legged user OAuth token from the signed-in user's connected account.
  3. 2-legged OAuth 2.0 client_credentials token minted and cached from the secret's client credentials.
  4. Staged 3-legged discovery token held in memory during initial wizard discovery.

OAuth, IP allowlists, and private networks​

Both flows need Aiden to reach the IdP token endpoint from its own pods. The endpoints must be public HTTPS. This is a deliberate rule: the client secret travels to the token endpoint, so Aiden restricts where that POST may go (private, loopback, link-local, and cloud metadata addresses are refused at save time and at socket dial time).

The MCP server is different:

  • Public MCP server with an IP allowlist: if your MCP gateway is internet-facing but restricts inbound traffic by IP (via AWS WAF, API Gateway resource policy, security group, or handler IP check), allowlist Aiden's outbound NAT egress IP(s) in addition to your operator workstation IP. Otherwise, Validate and discover and chat tool calls from Aiden will be rejected with HTTP 403 Forbidden.
  • Private MCP server behind a firewall: keep the server off the public internet and bind the integration to a remote runner inside your network, the same pattern as on-prem integrations. When a runner is selected, Aiden automatically sets skip_connectivity_check on secret save (still validating required fields and scope format locally), resolves the bearer token in the cloud, and delivers it to the runner to dial your private MCP server.

On-prem checklist:

  • IdP: public HTTPS token endpoint reachable from Aiden (direct, or through your proxy allowlist).
  • MCP server: any address your runner can reach.
  • Proxy: Aiden honors the standard HTTPS_PROXY/NO_PROXY settings on its pods; a corporate proxy that re-signs TLS needs the proxy's root certificate trusted by Aiden.
  • Clocks: token expiry uses the pod clock; keep NTP running.
  • Rotation: rotate the client secret by updating the integration (client credentials) or the provider (per-user); short token lifetimes bound any cached old token.

Troubleshooting​

SymptomLikely cause and fix
Save fails with invalid_scope (MCP_OAUTH_CLIENT_CREDENTIALS_REJECTED)The app client does not allow the requested scope. On Cognito client_credentials, use a custom resource-server scope (such as mcp-api/read or mcp-api/invoke), never openid.
Save fails naming the token URL (MCP_TOKEN_URL_EGRESS_DENIED)Endpoint is not public HTTPS, resolves to a private/loopback/metadata IP, or is blocked by your proxy allowlist. Use the public HTTPS IdP domain (for Cognito, https://<your-domain>.auth.<region>.amazoncognito.com/oauth2/token).
Save fails on a delimiter-only scope (MCP_OAUTH_SCOPE_EMPTY)The scope field contains only spaces or commas; list at least one valid scope or leave the optional field empty if your IdP assigns default scopes.
Connect redirects to Cognito with redirect_mismatchThe callback URL in the Cognito app client does not match {oauth.publicBaseUrl}/v1/credential-providers/<provider-name>/token (for example https://<your-aiden-host>/api/vault/v1/credential-providers/<provider-name>/token).
Validate and discover fails with 403 Forbidden while local curl worksYour MCP gateway or firewall has an IP allowlist that permits your workstation IP but blocks Aiden's cloud egress NAT IP. Add Aiden's egress IP to the allowlist, or bind the integration to a Remote Runner inside your network.
Discovery or tools fail with 401 on the MCP server even though token minting succeedsYour MCP gateway's JWT authorizer is checking aud instead of client_id for a Cognito access token. On Bedrock AgentCore Gateway, add the Cognito client ID to allowedClients; on API Gateway v2 JWT Authorizer, add it to Audience.
Per-user prompt asks to reconnectIdP session or refresh token was revoked. The signed-in user clicks Connect (or Reconnect) again; other users are unaffected.
Scheduled run or webhook fails, chat worksPer-user OAuth requires an interactive signed-in user. Use OAuth 2.0 Client Credentials for unattended runs.