Skip to main contentArrow Right
Descope, Slack, and Okta logos arranged horizontally across the upper portion of a dark navy-blue gradient background with a subtle blue and teal dotted pattern. Large, glowing cyan text centered below the logos reads “Add MCP Auth to Your Okta App” across two lines.

Table of Contents

Summarize with AI

Don't have the time to read the entire post? Our human writers will be sad, but we understand. Summarize the post with your preferred LLM here instead.

This tutorial was written by Kumar Harsh, a software developer and devrel enthusiast who loves writing about the latest web technology. Visit Kumar's website to see more of his work!


A Model Context Protocol (MCP) server hands its tools to an AI agent, and those tools act with a real user's permissions. The July 2026 revision of the MCP authorization spec handles this with a dedicated OAuth 2.1 layer that issues narrow, revocable tokens to agents.

If you manage identity in Okta, you can keep every user, group, sign-on policy, and app integration as it is. The only change on the Okta side is one new OpenID Connect (OIDC) app integration. What Okta doesn't offer MCP clients is self-service registration: its Dynamic Client Registration API requires an admin credential for every new client, which breaks down once Claude Code, Cursor, and similar clients start registering on the fly. Descope's Bring Your Own Auth for MCP sits in front of your MCP server as its authorization server and federates logins back to Okta. Descope handles discovery, registration, consent, and token issuance, while Okta stays the system of record.

How the pieces fit together

You'll build a Python MCP server with two tools, federate Descope to Okta, gate each tool's scope on Okta group membership, connect Claude Code, and inspect the token where it reaches your server. The same pattern lets employees who already sign in through Okta use internal tools through an agent, or gives business-to-business (B2B) partners MCP access through the identity they already use for your app. Descope's Bring Your Own Auth walkthrough video shows the model in motion, and companion guides cover Amazon Cognito, Auth0, and Microsoft Entra ID.

Sequence diagram of a first connection between four participants: Claude Code, the MCP server, Descope, and Okta. Step 1, Discovery: Claude Code calls a tool with no token, and the MCP server returns 401 with a WWW-Authenticate header pointing to protected resource metadata. Step 2, Registration: Claude Code fetches the discovery document from Descope and registers via CIMD or DCR. Step 3, Login: Claude Code sends an authorization request to Descope with a PKCE challenge and scopes. Step 4, federated login: Descope redirects the user to Okta to sign in, and Okta returns an ID token with group membership. Step 5, Consent: Descope maps groups to roles, applies the access policy, and shows a consent screen listing grantable tools. Step 6, Token exchange and tool call: Claude Code exchanges the authorization code for an access token with the MCP server as its audience, calls the tool with the token, the MCP server verifies the signature against Descope's public JWKS, and returns the tool result.
Fig: How Claude Code, your MCP server, Descope, and Okta interact on a first connection.

A first connection runs through these steps:

  1. Claude Code calls the MCP server with no token and receives a 401 (Unauthorized) response whose WWW-Authenticate header points at the server's protected resource metadata.

  2. The metadata names Descope as the authorization server, so Claude Code fetches Descope's discovery document and registers through Client ID Metadata Documents (CIMD) or Dynamic Client Registration (DCR).

  3. Claude Code opens the browser on Descope's authorization endpoint with a Proof Key for Code Exchange (PKCE) challenge and the requested scopes.

  4. Descope's consent flow sends the user to Okta, and Okta returns an ID token that lists the user's groups.

  5. Descope maps those groups to roles, applies your access policy, and shows a consent screen listing only the tools the user may grant.

  6. Claude Code exchanges the authorization code for an access token whose audience is your MCP server and calls tools with it.

Later connections usually skip registration and, while the user's Okta session is active, the Okta login screen. Descope reapplies the group mapping on each SSO login and the access policy on each authorization request, so a group change in Okta shapes the next token the agent receives. Okta's ID token never leaves Descope.

Prerequisites

  • Python 3.11 or later

  • A Descope account (the Free Forever plan covers this tutorial)

  • An Okta org with admin access, plus two groups named Support Leads and Support Agents, each with a test user (create them under Directory > Groups > Add group)

  • Claude Code installed locally

  • An HTTPS URL for your server, such as a Cloudflare Tunnel pointing at your machine

Building a remote MCP server

The demo server, Acme Tickets, is a small support desk with two tools: get_ticket, which reads a ticket, and close_ticket, which changes data. The difference in risk gives you something concrete to scope.

Install FastMCP and python-dotenv:

pip install "fastmcp>=4" python-dotenv

Create server.py. The first part loads configuration, including the issuer URL Descope assigns this MCP server:

import logging
import os

from dotenv import load_dotenv
from fastmcp import FastMCP
from fastmcp.server.auth import require_scopes
from fastmcp.server.auth.providers.descope import DescopeProvider
from fastmcp.server.auth.providers.jwt import JWTVerifier
from fastmcp.server.dependencies import get_access_token

load_dotenv()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("acme-tickets")

PROJECT_ID = os.environ["DESCOPE_PROJECT_ID"]
MCP_SERVER_URL = os.environ["MCP_SERVER_URL"]  # e.g. https://tickets.example.com/mcp
ISSUER = os.environ["DESCOPE_ISSUER"]  # Issuer URL from the MCP server's settings in Descope

Next, set up token validation and attach Descope as the auth provider:

# Accept only tokens that Descope minted for this MCP server
verifier = JWTVerifier(
    jwks_uri=f"https://api.descope.com/{PROJECT_ID}/.well-known/jwks.json",
    issuer=ISSUER,
    audience=MCP_SERVER_URL,
    algorithm="RS256",
)

auth = DescopeProvider(
    config_url=f"{ISSUER}/.well-known/openid-configuration",
    base_url=os.environ["BASE_URL"],
    scopes_supported=["tickets:read", "tickets:write"],
    token_verifier=verifier,
)

mcp = FastMCP(name="Acme Tickets", auth=auth)

Finally, add the ticket data and the two tools, each gated by one scope:

TICKETS = {
    4821: {"title": "CSV export fails on large files", "status": "open", "fixed_in": "v2.14.1"},
    4822: {"title": "SSO login loops on Safari", "status": "open", "fixed_in": None},
}


@mcp.tool(auth=require_scopes("tickets:read"))
def get_ticket(ticket_id: int) -> dict:
    """Fetch a support ticket by ID."""
    ticket = TICKETS.get(ticket_id)
    if ticket is None:
        raise ValueError(f"Ticket {ticket_id} not found")
    return {"id": ticket_id, **ticket}


@mcp.tool(auth=require_scopes("tickets:write"))
def close_ticket(ticket_id: int, resolution: str) -> dict:
    """Close a support ticket with a resolution note."""
    ticket = TICKETS.get(ticket_id)
    if ticket is None:
        raise ValueError(f"Ticket {ticket_id} not found")
    ticket["status"] = "closed"
    claims = get_access_token().claims
    logger.info("close_ticket id=%s user=%s scopes=%s", ticket_id, claims["sub"], claims.get("scope"))
    return {"id": ticket_id, "status": "closed", "resolution": resolution}


if __name__ == "__main__":
    mcp.run(transport="http", host="0.0.0.0", port=8000)

FastMCP's Descope integration does the protocol work. DescopeProvider answers requests that lack a valid bearer token with a 401 and publishes the protected resource metadata, the one piece of OAuth discovery your server owns and the document every MCP client reads to find Descope. The custom JWTVerifier pins the issuer and the audience, and because the audience is this server's URL, a token minted for another MCP server in the same Descope project gets a 401. Each require_scopes decorator ties a tool to one scope. If you build on the official MCP Python SDK instead, Descope's Python MCP SDK provides the same checks.

Add your values to a .env file, replacing tickets.example.com with your tunnel's hostname here and in later commands. You'll get the project ID and issuer URL from Descope in the next section:

DESCOPE_PROJECT_ID=P2abc...
DESCOPE_ISSUER=https://api.descope.com/v1/apps/agentic/P2abc.../MS2xyz...
MCP_SERVER_URL=https://tickets.example.com/mcp
BASE_URL=https://tickets.example.com

Start the server and point your tunnel at port 8000:

python server.py

Then check the discovery chain with curl:

curl -i -X POST https://tickets.example.com/mcp
# HTTP/2 401
# www-authenticate: Bearer resource_metadata="https://tickets.example.com/.well-known/oauth-protected-resource/mcp"

curl https://tickets.example.com/.well-known/oauth-protected-resource/mcp

The second command returns the metadata document, with Descope listed as the authorization server:

{
  "resource": "https://tickets.example.com/mcp",
  "authorization_servers": ["https://api.descope.com/v1/apps/agentic/P2abc.../MS2xyz..."],
  "scopes_supported": ["tickets:read", "tickets:write"],
  "bearer_methods_supported": ["header"]
}

Registering the MCP server in Descope

In the Descope Console, open Agentic Identity Hub > MCP Servers and create a server named Acme Tickets. Set the MCP Server URL to https://tickets.example.com/mcp. Descope writes this URL into the aud (audience) claim of every token it issues for the server, so it has to match MCP_SERVER_URL exactly.

Under MCP Server Scopes, add one scope per tool:

Scope name

Consent description

Allow user to decline scope

tickets:read

Read support tickets and their status

Off

tickets:write

Close support tickets

On

Under MCP Client Registration, keep DCR enabled and turn on CIMD. The July 2026 spec revision, covered in our MCP authorization spec breakdown, prefers CIMD and keeps DCR for backward compatibility. Either way, clients register on first contact with no admin involvement. See the registration methods guide and our post on DCR vs. CIMD for the tradeoffs.

Set Dynamic Registration Template to Custom, which gives Acme Tickets its own consent flow and exposes the Always include all user authorization info on the token checkbox. Check it so the token carries the user's tenants and roles for auditing. It doesn't widen access: the granted scopes still decide which tools the agent reaches. Custom is available on servers that use their own MCP Server Issuer. A server on the project issuer uses the project's template or one picked under Override project settings, as the MCP server settings docs explain.

The Create MCP Server page in the Descope Console. Under MCP Server Details, the MCP Server name is Acme Tickets, with fields for ID, Description, and MCP Server URL. Under MCP Server Scopes, tickets:read has the consent description Read support tickets and their status with Allow user to decline scope off, and tickets:write has the description Close support tickets with Allow user to decline scope on.
Fig: Creating the Acme Tickets MCP server in Descope.

Finally, copy two values into .env: the project ID from the top nav (click the project name, then Copy ID) as DESCOPE_PROJECT_ID, and the Issuer URL from the server's Connection Information section as DESCOPE_ISSUER. Depending on the project, the issuer is either project-wide or specific to this server, so copy it rather than building it by hand. Restart the server.

Federating Descope to Okta over OIDC

A Descope tenant groups one company's users under one set of login settings. You'll create a tenant, Acme, whose OIDC single sign-on (SSO) connection federates its users to Okta and carries their group memberships.

Create and configure the Okta app integration

In the Okta Admin Console, go to Applications and Resources > Applications > Create App Integration, choose OIDC - OpenID Connect under the Classic experience tab, and select Web Application. Name it Descope MCP, choose Configure in Okta under Client definition, and set the Sign-in redirect URI to https://api.descope.com/v1/oauth/callback. Under Assignments, choose Limit access to selected groups, add both support groups, and click Save.

On the app's settings page:

  1. On the Assignments tab, click Assign > Assign to People and assign each test user directly. Without this, Okta can return a "User is not assigned to the client application" error even though the groups show as assigned.

  2. On the Sign On tab, under Token claims, click Add expression. Name it support_groups and set the expression to user.getGroups({'group.profile.name': 'Support.*'}).![profile.name]. The trailing projection is required: without it, the claim saves without error but stays empty, as Okta's support article on user.getGroups shows.

  3. Still on Sign On, check the User authentication policy. If it requires two factors and your test user only has a password, sign-in fails. For testing, select a one-factor policy from Security > Authentication Policies; in production, keep your org's existing policy.

  4. On the General tab, copy the client ID and client secret.

The Token claims section of the Okta app's Sign On tab, with an Add expression button and one claim named support_groups whose expression is user.getGroups({'group.profile.name': 'Support.*'}).![profile.name].
Fig: The support_groups token claim in Okta.

Configure SSO in Descope

  1. Open Tenants, create a tenant named Acme, and add your email domain (for example, acme.com) as its SSO domain.

  2. In the tenant's Authentication Methods > SSO, choose OIDC. Under Account Settings, enter a Provider Name (Okta), the client ID and client secret, and scopes including openid, profile, email, and groups. Under Connection Settings, enter your Okta discovery URL (https://<your-org>.okta.com/.well-known/openid-configuration) and click Fetch to fill in the issuer and endpoints. Enter the SSO domain again in this configuration's own domain field, or Descope rejects it with an "acme.com not allowed on SSO" error.

  3. Under Group Attribute Mapping, set Groups claim name to support_groups, matching the Okta claim name exactly, as the Descope OIDC guide explains.

The SSO Configuration page for the Acme tenant in Descope. Account Settings shows Provider Name Okta, a client ID, Client Secret selected under Client Authentication, scopes openid, email, profile, address, phone, offline_access, and groups, and Grant Type Authorization code. Connection Settings shows the Okta discovery URL with a Fetch button and the issuer, authorization, token, and user info endpoints filled in.
Fig: The OIDC SSO configuration for the Acme tenant in Descope.

Wire Okta into the consent flow

Open the built-in Inbound apps - user consent flow (inbound-apps-user-consent) in Flows. On its Welcome Screen, add an SSO sign-in button connected to a new SSO action, and connect the action's Successful authentication output to the flow's existing Is consent already granted? step.

Part of the Inbound apps - user consent flow in Descope. The Is the user logged in? condition routes True to Load User and False to the Welcome Screen. The Welcome Screen's SSO button leads to an SSO action, and both Load User and the SSO action's Successful authentication output lead to the Is consent already granted? condition.
Fig: The consent flow with an SSO sign-in option added.

Back on the Acme Tickets settings page, select this flow from the User Consent Flow dropdown, which the Custom template exposed.

The User Consent Flow section of the Acme Tickets MCP server settings in Descope, with the Flow dropdown set to Inbound apps - user consent, a Flow hosting URL link, and an unchecked Skip consent screen option.
Fig: Selecting the user consent flow for the MCP server.

The SSO button never checks a password. It redirects the browser to Okta over OIDC, Okta confirms the user and returns an ID token, and Descope trusts that token. A user with an active Okta session goes straight to the consent screen, and Okta's sign-on policy still applies.

Mapping Okta groups to MCP scopes

Turning groups into tool access takes three pieces: roles, a groups claim on the token, and an access policy. Access then follows the group model your Okta admins already manage.

Map groups to roles

On the Acme tenant's RBAC page, add two tenant roles (RBAC is role-based access control): support-lead and support-agent. Then, on the tenant's SSO settings, open the Roles & Groups tab and, under RBAC Group Mapping, map Support Leads to support-lead and Support Agents to support-agent. Descope applies these mappings on SSO logins.

The RBAC page for the Acme tenant in Descope, listing the tenant roles support-agent and support-lead and the project role Tenant Admin.
Fig: The two support roles on the Acme tenant.
The Roles & Groups tab of the Acme tenant's SSO settings in Descope. Under RBAC Group Mapping, the IdP group Support Agents maps to the Descope role support-agent and Support Leads maps to support-lead.
Fig: Mapping Okta groups to Descope roles on the Acme tenant.

Record Okta's groups on the token

Add a Custom Claims action between the SSO action and the Is consent already granted? step. Set Key to okta_groups, switch the value to the dynamic type, and set Value to {{idpGroups}}, the flow context key Descope fills from Okta's response. Every access token then carries the user's Okta groups as Okta sent them.

The Custom Claims action in Descope Flows, with step name Custom Claims, Key okta_groups, Type Dynamic, and Value {{idpGroups}}. The optional Context Key for Custom Claims Map field is empty and Set Custom Refresh Duration is unchecked.
Fig: Configuring the Custom Claims action.
The Inbound apps - user consent flow in the Descope flow editor. The Welcome Screen's SSO button leads to the SSO action, then to a Custom Claims action, then to the Is consent already granted? condition, which Load User also feeds.
Fig: The consent flow with the Custom Claims action.

Grant scopes by role with an access policy

Roles alone don't decide which tools a user can hand to an agent. An access policy does: it filters requested scopes before the consent screen renders, so a scope no rule allows is never offered and never lands in the token. Open the Access Policy page in the Descope Console (its Resources & Connections tab, if the page is split) and add two rules targeting Acme Tickets, with Grant type set to User access, the authorization code flow Claude Code uses.

The rules, summarized as configuration rather than code:

Rule 1: Acme Tickets - Read and close for support leads
  Conditions:      user.roles CONTAINS "support-lead"
  Grant type:      User access
  Allowed resource: Acme Tickets
  Allowed scopes:  tickets:read, tickets:write

Rule 2: Acme Tickets - Read for support agents
  Conditions:      user.roles CONTAINS "support-agent"
  Grant type:      User access
  Allowed resource: Acme Tickets
  Allowed scopes:  tickets:read

Default rule: Block All

Descope checks rules top to bottom, and the first match decides, so a user in both groups gets the lead grant. Once you create a rule, the default becomes Block All, so a user in neither group gets no scopes. The policies documentation covers other condition keys, such as client.tags, which you can add to rule 1 to limit write access to clients you've tagged as trusted.

Consent adds a second layer. Because tickets:write is declinable, a support lead can approve tickets:read alone and give Claude Code read-only access. The agent never holds more than its user granted, and the user never grants more than the policy allows.

This only works because scopes map one-to-one with tools. A single server-wide scope such as mcp:access is the most common mistake in MCP authorization, because it leaves the policy and the user nothing to choose between. FastMCP's authorization checks also filter tool listings, so a client holding only tickets:read sees get_ticket alone, and a direct call to close_ticket fails with an unknown-tool error.

End-to-end walkthrough: client registration to token at the server

With the server and tunnel running, add the server to Claude Code:

claude mcp add --transport http acme-tickets https://tickets.example.com/mcp

Run /mcp in Claude Code, where Acme Tickets shows as needing authentication, and select Authenticate. The browser opens Descope's authorization endpoint with Claude Code's client_id, a PKCE code_challenge, the requested scope, and a resource parameter naming your server. It then passes through Okta and the consent screen, and Claude Code redeems the authorization code.

To see what Descope put in the token, temporarily log the claims your server already validated in get_ticket. This avoids writing the bearer token itself to your logs:

logger.info("token claims: %s", get_access_token().claims)  # remove after testing

Ask Claude Code to "summarize ticket 4821." The support lead's token carries claims along these lines:

{
  "iss": "https://api.descope.com/v1/apps/agentic/P2abc.../MS2xyz...",
  "sub": "U2lead...",
  "aud": ["https://tickets.example.com/mcp"],
  "scope": "tickets:read tickets:write",
  "okta_groups": ["Support Leads"],
  "tenants": {
    "T2acme...": { "roles": ["support-lead"], "permissions": [] }
  },
  "iat": 1791378000,
  "exp": 1791378600
}

The same token decoded in jwt.guru, Descope's free JWT decoder:

The support lead's access token decoded in jwt.guru. The payload shows iat, an iss on api.descope.com, okta_groups with the value Support Leads, rexp, scope tickets:read tickets:write, sub, and a tenants claim whose tenant lists the role support-lead.
Fig: The support lead's access token decoded in jwt.guru.

The token traces the whole chain. The okta_groups claim shows Okta authenticated the user, the group mapping produced the support-lead role, the policy granted both scopes, and iss and aud tie the token to Acme Tickets alone. The support agent's token has "okta_groups": ["Support Agents"], the support-agent role, and "scope": "tickets:read", and that user's tool list shows only get_ticket. Remove the logging line when you're done.

Audit and revocation

Every consent creates an agentic identity, one per user per client. Agentic Identity Hub > Agentic Identity lists each one with its agent name, agent ID, client ID, agent type, associated user, and IP address. Claude Code's client ID is a URL on claude.ai, which shows it registered through CIMD.

The Agentic Identity page in Descope, listing one agent, Claude Code, with its agent ID, a client ID beginning https://claude.ai/oauth/, agent type User-delegated, an associated user ID, and an IP address.
Fig: The Agentic Identity view with a connected agent.

Check the support lead's Claude Code row and click Revoke Access to invalidate that consent. The user's Okta account, their other apps, and the client registration stay intact. Because your server validates tokens locally, a token issued before the revocation stays valid until it expires, so set a short lifetime under the server's Session Management.

The Agentic Identity page in Descope with the Claude Code row selected, and the Manage Tags and Revoke Access buttons shown above the table.
Fig: Revoking a connected agent's access.

Descope's audit trail records the SSO login, the consent and its scopes, token issuance, and the revocation. Tool calls run on your server, which is why close_ticket logs the sub (subject) claim and scopes. Joining the two on the user ID shows what an agent did and under whose Okta identity, a record that lives independently of Okta and that a partner's admin can ask you to act on.

What changed in Okta, and what didn't

Okta's users, groups, and existing apps stayed as they were, with one new OIDC app integration for Descope. Descope added the MCP-specific layer, from client registration to group-gated, tool-level consent, and the decoded token confirms the chain end to end. The complete code is in this GitHub repository.

To try it with your own Okta org, sign up for a Free Forever Descope account and follow the Bring Your Own Auth for MCP guide. Have questions? Join AuthTown, our open user community for developers, or book time with our auth experts.

FAQ