This setup is optional, and you do not need it for single sign-on. To let your team sign in to Context7 with Microsoft Entra ID, follow Microsoft Entra ID SSO. If your gateway is Azure API Management, follow Azure APIM gateway, which has ready-made APIM policies.
oid claim of their Entra token.
How it works
Your gateway uses the On-Behalf-Of (OBO) flow. The developer’s MCP client gets an Entra token for your gateway. Your gateway exchanges that token for a second Entra token for the Context7 MCP API app in your tenant, and sends the second token to Context7.Before you start
You need:- A Context7 Enterprise teamspace or an Enterprise trial. The dashboard shows the Enterprise tab only on these teamspaces.
- An Entra admin who can register applications and grant admin consent.
- An MCP gateway that can validate a JWT, call the Entra token endpoint, and forward Streamable HTTP, including Server-Sent Events.
- Network access from the gateway to
https://mcp.context7.comandhttps://login.microsoftonline.com.
Step 1: Register the Context7 MCP API app
This app stands for Context7 in your tenant. The OBO token carries its Application (client) ID as theaud claim.
- Microsoft Entra admin center → App registrations → + New registration.
- Name:
Context7 MCP API - Supported account types: Single tenant only
- Redirect URI: leave it empty.
- Name:
- Copy the Application (client) ID. You enter it in Context7 in Step 3.
- Expose an API → Add next to “Application ID URI” → keep
api://<client-id>→ Save. - + Add a scope: name
mcp.access, Who can consent: Admins and users, State: Enabled. - Manifest → set
requestedAccessTokenVersionto2underapi→ Save.
Step 2: Register your gateway app
This app stands for your gateway. MCP clients get tokens for it, and the gateway uses its client secret for the OBO exchange. If your gateway already has an Entra app, use that app and add what is missing.- App registrations → + New registration, single tenant. Copy the Application (client) ID and the Directory (tenant) ID.
- Expose an API → keep
api://<gateway-client-id>→ add the scopeMcp.Gateway.Access. - Manifest → set
requestedAccessTokenVersionto2. - Certificates & secrets → + New client secret. Store the value in your gateway’s secret store. Entra shows it only once.
- API permissions → + Add a permission → My APIs → Context7 MCP API → Delegated permissions →
mcp.access→ Add permissions. Then click Grant admin consent. - In the Context7 MCP API app: Expose an API → Authorized client applications → add the gateway app’s client ID with the
mcp.accessscope. Users then see no extra consent prompt during the OBO exchange. - In the gateway app: Expose an API → Authorized client applications → add the client ID of each MCP client you allow, with the
Mcp.Gateway.Accessscope. For the smoke test in Step 6, add the Azure CLI:04b07795-8ddb-461a-bbee-02f9e1bf7b46.
Step 3: Configure your teamspace in Context7
An owner or admin of the teamspace does this in the dashboard. Context7 checks every OBO token in two stages, and both are mandatory:- The token’s signature, issuer, audience and scope must match the teamspace’s tenant configuration.
- The token’s
oidmust belong to a user on the teamspace’s Entra user list. Context7 rejects any other user with401, even when the token is valid.
- Open context7.com/dashboard and select the teamspace.
- Enterprise tab → Microsoft Entra ID → Configure, and fill in:
- Tenant ID: your Directory (tenant) ID.
- Audience: the Context7 MCP API app’s client ID from Step 1. Do not use the gateway app’s ID.
- Required scope:
mcp.access
- Click Test connection, then Save.
- Add your developers in the Microsoft Entra ID users card. You can add each user by email and Entra object ID, or sync an Entra security group every 30 minutes. For the group sync setup, see Auto-provision from an Entra security group. To let the Entra provisioning service add and remove them, set up SCIM provisioning.
One Context7 MCP API app (audience) belongs to one teamspace. To connect a second teamspace, register a second Context7 MCP API app.
Step 4: Configure your gateway
Your gateway must do these six things for each request to Context7:-
Validate the incoming token. Check the signature against your tenant’s keys (
https://login.microsoftonline.com/<tenant-id>/discovery/v2.0/keys), the issuer,aud= the gateway app’s client ID, andscpcontainsMcp.Gateway.Access. If the token is missing or not valid, answer401with a challenge (see Step 5). -
Exchange the token On-Behalf-Of the user. Send this request to Entra:
-
Cache the OBO token per user. Key the cache by the user’s
oid, and renew the token a minute before itsexp. Without a cache, every MCP message causes one more call to Entra. -
Forward the request to
https://mcp.context7.com/mcp, with the same method, body and headers, andAuthorization: Bearer <OBO token>in place of the user’s token. Do not changeAcceptorContent-Type. - Stream the response. Context7 answers with JSON or with a Server-Sent Events stream. Pass the body through without buffering, and do not set a short read timeout.
-
Pass status codes through. A
401from Context7 means the configuration or the user mapping is wrong (see Troubleshooting). A405onGETis normal: the server has no standalone event stream, and clients continue without it.
- The server is read-only and has two tools:
resolve-library-idandquery-docs. - The server is stateless. It sends no
Mcp-Session-Id, so the gateway needs no sticky sessions.
Step 5: Expose OAuth discovery for MCP clients
MCP clients find out how to sign in from the gateway. Your gateway must:-
Answer a request without a token with
401and this header: -
Serve that document, with your gateway’s MCP URL as
resource:
Step 6: Smoke test
Test the whole chain from a terminal before you connect MCP clients:200 OK with an event stream that names the Context7 server. Then call tools/list and one query-docs through your MCP client to see real documentation.
Token claims
Troubleshooting
What this does not cover
- Context7’s own OAuth through a pass-through gateway. If your gateway only passes the client’s sign-in through to Context7’s OAuth, the token is issued for the gateway’s URL and Context7 rejects it. Use the Entra flow in this guide, or give the gateway a Context7 API key if one shared identity is enough.
- On-premise. This guide proxies the hosted
mcp.context7.com. For an on-premise deployment, contact context7@upstash.com.