Azure API Management (APIM, sometimes marketed as “Azure AI Gateway”) can sit in front ofDocumentation Index
Fetch the complete documentation index at: https://context7-ctx7-1655-azure-apim-integration.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
mcp.context7.com and let your organization control who reaches it from your tenant. APIM validates a Microsoft Entra ID token at the gateway, and Context7 supports two ways of resolving that identity at the backend.
Two integration patterns
| Shared identity | Per-user identity | |
|---|---|---|
| Status | Available today | In development |
| Token on device | Entra-issued | Entra-issued |
| APIM validates | Yes (validate-azure-ad-token) | Yes (validate-azure-ad-token) |
| Forwarded to Context7 | Single teamspace API key | Same Entra JWT |
| Context7 sees | One shared teamspace identity | Each user individually |
| Per-user usage / audit | In APIM logs only | In APIM and in Context7 |
| MFA / conditional access | Enforced by Entra at sign-in | Enforced by Entra at sign-in |
validate-azure-ad-token) plus a one-time tenant configuration on the Context7 side.
Pattern 1: Shared identity (available today)
Architecture
- The MCP client (Claude Code, Cursor, VS Code, ChatGPT) obtains an access token from Entra ID.
- The client calls APIM with
Authorization: Bearer <entra-jwt>. - APIM validates the JWT against your tenant, audience, and required scope.
- APIM strips the Entra token and injects your Context7 teamspace API key.
- The request lands at
mcp.context7.com/mcp/oauthas an authenticated Context7 request.
Before you start
You will need:- An Azure subscription in the same tenant as your Entra users.
- An Entra admin who can register applications.
- A Context7 API key from a teamspace. Generate one at context7.com/dashboard under API Keys. It starts with
ctx7sk_. - The Azure CLI installed locally (
brew install azure-clion macOS) and authenticated to your subscription (az login).
Provision APIM
APIM Basic v2 provisions in about 5 minutes and supports MCP routing. Consumption tier does not support MCP backends. Create a Bicep file:apim.bicep
Register the MCP API in Entra
This Entra app represents the protected MCP resource. Its scope is what Entra users must request when they ask for an access token.-
Microsoft Entra admin center → App registrations → + New registration.
- Name:
Context7 MCP - Supported account types: Accounts in this organizational directory only
- Redirect URI: leave blank
- Register
- Name:
- Note the Application (client) ID and Directory (tenant) ID from the Overview page.
-
Expose an API → Add next to “Application ID URI” → accept the default
api://<client-id>→ Save. -
+ Add a scope:
- Scope name:
mcp.access - Who can consent: Admins and users
- Admin consent display name:
Access Context7 MCP server - Admin consent description: anything descriptive
- State: Enabled
- Add scope
- Scope name:
-
Manifest → find
"requestedAccessTokenVersion"underapi→ set to2. Save. -
API permissions → for each MCP client tool you want to allow (Claude Code, Cursor, VS Code, ChatGPT), register its client app separately and grant it delegated permission on
mcp.access. Pre-authorize these clients in Expose an API → Authorized client applications to skip end-user consent.
Configure APIM
Store the Context7 API key
Create the API and operation
Attach the policy
Save this aspolicy.xml, replacing <your-tenant-id> and <your-mcp-api-app-id> with the values from the Entra registration step:
policy.xml
az apim api policy create):
Test end-to-end
Obtain an Entra access token. The fastest way is device code flow:verification_uri, enter the user_code, sign in. Then exchange the device_code:
access_token and call APIM:
200 with library results streamed back as an SSE event.
Verify the gateway rejects unauthorized requests:
Connecting an MCP client
For a quick test from Claude Code with a static token:Pattern 2: Per-user identity via native Entra validation (in development)
Architecture
One-time tenant onboarding
You provide Context7 with:- Your Entra tenant ID
- Your MCP API app ID (audience)
- The required scope (typically
mcp.access)
oid claim to a per-user Context7 record (auto-provisioned on first sign-in).
Flow
- A developer’s MCP client (e.g. VS Code with GitHub Copilot) calls APIM.
- The client performs OAuth against your Entra tenant for an access token scoped to your MCP API.
- The client retries the request against APIM with the Entra token in the
Authorizationheader. - APIM validates the token locally (
validate-azure-ad-token) as defence-in-depth. - APIM forwards the request to
mcp.context7.comwith the Entra token unchanged. - The Context7 MCP server validates the token against your configured tenant ID and audience.
- The
oidclaim is resolved to a Context7 user record in your teamspace, auto-provisioned on first sign-in. - The request is served attributed to that user.
Migration from Pattern 1
If you start on Pattern 1 and migrate to Pattern 2 later, the move is:- Share your tenant ID, audience, and scope with us. We onboard your tenant configuration.
- Update the APIM policy: keep
validate-azure-ad-token, drop theset-headerswap and therewrite-uri. - APIM now forwards the Entra JWT unchanged to Context7.
context7-api-key) can be deleted after the cutover.
Status
Pattern 2 is currently in development. Contact context7@upstash.com or your Context7 account contact for the latest timeline and to schedule tenant onboarding.Troubleshooting
401 Unauthorized with valid-looking token
Decode the token at jwt.io and verify:
issishttps://login.microsoftonline.com/<your-tenant-id>/v2.0(v2 form). If it ishttps://sts.windows.net/<tid>/, your manifest’srequestedAccessTokenVersionis missing or set tonull.audmatches the value in your<audiences>policy block. v2 tokens use the GUID, notapi://....scpcontainsmcp.access.expis in the future.
Invalid API key. Please check your API key. API keys should start with 'ctx7sk' prefix.
This applies to Pattern 1 only. APIM forwarded successfully but the Context7 backend rejected the key. The context7-api-key named value is missing, set to a placeholder, or the key has been revoked. Generate a fresh key at context7.com/dashboard and update the named value:
AADSTS650057: Invalid resource
The MCP client’s app registration does not list your MCP API as an allowed resource. In your Entra MCP API app → Expose an API → Authorized client applications, add the client’s app ID and check the mcp.access scope.
Streaming responses get cut off
APIM diagnostics with “Number of payload bytes to log” > 0 break MCP’s SSE streams. Set it to0 for Frontend Response at the service level.
What’s not covered
- Self-hosted MCP server. This guide proxies the hosted
mcp.context7.com. For air-gapped or compliance scenarios where MCP traffic cannot leave your network, contact context7@upstash.com about the self-hosted MCP package. - Dynamic Client Registration. Entra does not implement RFC 7591. MCP clients that depend on it (some versions of Claude.ai, ChatGPT) need to be pre-registered in Entra and pre-authorized on the MCP API app. A DCR shim deployed inside APIM is possible but not officially supported by Microsoft; reach out if you need this.