Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
An MCP server is an OAuth 2.0 protected resource. Register the server as an API in Microsoft Entra ID, publish protected-resource metadata, and validate each access token before processing an MCP request.
This guidance supports Microsoft identity platform v2.0 access tokens only.
Prerequisites
- A Microsoft Entra tenant.
- An HTTPS endpoint for the MCP server.
- Permission to create an app registration and grant consent.
- An MCP client that supports OAuth protected-resource metadata.
Register the MCP server
- Register an application for the MCP server.
- Set an Application ID URI that uniquely identifies the server.
- Expose the delegated scopes required by MCP clients.
- Define application roles only if the server supports app-only access.
- Record the tenant ID, application client ID, and Application ID URI.
Grant only the permissions required by the tools and resources that the server exposes.
Publish protected-resource metadata
Publish a metadata document at <server-url>/.well-known/oauth-protected-resource. MCP clients that support OAuth protected-resource discovery fetch this document to find the authorization server and supported scopes before requesting a token.
The following example shows a minimal document for a Microsoft Entra-backed MCP server:
{
"resource": "https://mcp.contoso.com",
"authorization_servers": [
"https://login.microsoftonline.com/<tenant-id>/oauth21/2026-08"
],
"scopes_supported": [
"mcp.access"
],
"bearer_methods_supported": [
"header"
]
}
resource— The Application ID URI registered for the MCP server. This value must match theaudclaim the server expects in incoming tokens.authorization_servers— The Microsoft Entra authorization server URL,https://login.microsoftonline.com/<tenant>/oauth21/2026-08. Use your tenant ID for a server that accepts users from a single tenant, orcommonfor a server that accepts users from any organization. Clients append/.well-known/openid-configurationto this URL to discover the authorization and token endpoints.scopes_supported— The delegated scopes exposed by the MCP server. List only the scopes clients need to call the server.bearer_methods_supported— Set to["header"]to indicate that clients must send the token in theAuthorizationrequest header.
For the full metadata format and discovery behavior, see the MCP authorization specification.
Validate access tokens
Require an access token on protected MCP requests. Validate the token's signature, issuer, audience, lifetime, tenant, client, and permissions.
Use the MCP server's Application ID URI or client ID as the expected audience, according to its registration. Enforce delegated scopes from scp and application permissions from roles.
For the complete validation checklist, see Validate Agent ID tokens in a downstream API.
Configure token validation in ASP.NET Core
Install Microsoft.Identity.Web:
dotnet add package Microsoft.Identity.Web
Configure the tenant and MCP server registration:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"TenantId": "<tenant-id>",
"ClientId": "<mcp-server-client-id>"
}
}
Register token validation and define a policy for the MCP delegated scope or application role:
using Microsoft.Identity.Web;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMicrosoftIdentityWebApiAuthentication(
builder.Configuration);
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("McpAccess", policy =>
{
policy.RequireAuthenticatedUser();
policy.RequireAssertion(context =>
context.User.IsInRole("Mcp.Access")
|| context.User.FindAll("scp").Any(claim =>
claim.Value
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.Contains("mcp.access", StringComparer.Ordinal)));
});
});
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapPost("/mcp", () => Results.Ok())
.RequireAuthorization("McpAccess");
app.Run();
Replace mcp.access with the delegated scope exposed by the MCP server. Replace Mcp.Access with its application role. Apply the McpAccess policy to the endpoint mapped by the MCP server framework rather than adding a second /mcp route.
The Results.Ok() handler is an authorization placeholder, not an MCP implementation. After applying the policy to your framework's endpoint, verify that an authorized client can perform the intended MCP tool or resource operation. Also test a missing token and a valid token without the required permission; an HTTP success from the placeholder alone doesn't verify MCP interoperability.
The authentication middleware returns 401 Unauthorized for a missing or invalid token. The authorization policy returns 403 Forbidden when a valid token lacks both the required delegated scope and application role.
For complete framework and authorization guidance, see Configure protected web API apps and Verify scopes and app roles in a protected web API.
Connect a client
The client discovers the protected-resource metadata, signs in or authenticates through Microsoft Entra ID, requests a token for the MCP server, and sends the token in the request's Authorization header.
Use one of these client identity models:
- A registered Agent ID.
- A local public-client Agent ID using authorization code flow with PKCE.
- A Client ID Metadata Document URL when preregistration isn't practical.
The MCP server doesn't need different token-validation logic for CIMD clients. Microsoft Entra ID still issues the access token, and the server validates it against the same issuer and audience policy.