AI Engineer World's Fair 2025
Building Protected MCP Servers
Loading slides…
Read the talk
Building Protected MCP Servers
Follow a protected MCP request from its first HTTP challenge through OAuth discovery, C# token validation, Azure deployment, and authenticated tool use in VS Code.
From a talk by Den Delimarsky and Julia Kasper
Before you start: Familiarity with HTTP requests, bearer tokens, and basic ASP.NET Core configuration will help you follow the examples.
Local binaries have a different authentication boundary
A local MCP server is a program running in the machine’s execution context. It can authenticate to downstream APIs using secrets, certificates, passkeys associated with credentials on the machine, or ordinary authentication libraries. MCP does not need to prescribe one mechanism for all of those possibilities. Remote desktop and shared virtual-machine arrangements add their own identity questions, which Den Delimarsky leaves to implementers.
The precise protocol distinction is HTTP versus STDIO, rather than simply remote versus physically local. The March 26 authorization specification excludes STDIO from this HTTP authorization flow. A server listening on localhost over HTTP can still participate—which is how the later C# demonstration works.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Separate the resource server from the token factory
At recording time, the March 26 specification was stable and a revised authorization model was still a draft. Den describes the earlier model as making MCP developers operate a token factory: minting, signing, refreshing, and managing tokens. The historical specification did allow an authorization server to run as a separate service, so building a custom issuer was not literally mandatory; the coupling lay in authorization discovery through the MCP server’s origin. The practical concern remains substantial: implementing token issuance is a much larger security responsibility than implementing a tool.
The draft refined with Anthropic and security experts makes the roles explicit: the MCP server is a resource server, while an authorization server manages token issuance and lifetime. That authorization server can be an existing provider such as Okta, Auth0, or Microsoft Entra ID. The MCP application no longer needs to own the token factory.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Less security code, with clear responsibilities
Julia Kasper’s implementation question is straightforward: what must a developer still build? The server publishes metadata pointing to its authorization server, and it validates the tokens presented by clients. Existing identity services and OAuth libraries supply the machinery around that boundary. The speakers use OAuth 2.0 terminology; MCP’s authorization requirements are based on OAuth 2.1 alongside OAuth 2.0 metadata standards.
| Component | Responsibility |
|---|---|
| MCP client | Complete authorization, acquire a token, send it with requests |
| MCP resource server | Publish discovery metadata and validate incoming tokens |
| Authorization server | Issue tokens and manage their lifetime |
The client completing authorization does not relieve the resource server of validation. A client’s possession of a token is not enough; the server must establish that the token authorizes access to this resource.
This division also reduces the amount of custom security code in an MCP application. Developers can concentrate on the problem their tools solve while relying on established identity providers and framework components for security-sensitive operations.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A 401 response starts discovery
The authorization flow begins with an ordinary request that lacks user context:
- The MCP client requests data from the protected server.
- The server returns HTTP
401. ItsWWW-Authenticateheader points to a Protected Resource Metadata document, or PRM. - The client retrieves that document and discovers which authorization server to use. The provider could be Entra ID, Okta, Auth0, or Keycloak.
- The client completes OAuth discovery and authorization to obtain a token.
- The client retries the resource request with that token. The MCP server validates it before returning data.
The talk’s diagram’s authorization step compresses an entire OAuth flow into one interaction. It does not mean the MCP server performs that flow on the client’s behalf.
Token validation also has a destination boundary. The subsequent June 18 specification requires validation that a token is intended for the MCP server and prohibits token passthrough to upstream APIs. Preserving downstream user context therefore requires appropriate, separate upstream credentials—not forwarding the MCP client’s bearer token unchanged.
PRM supplies the information needed to bootstrap discovery. In the explanation, it is a JSON document hosted by the MCP server that identifies the resource, lists its authorization servers, and can declare supported methods for bearer tokens and scopes. Den also mentions a JWT variation, but the demonstration uses JSON. The document tells a client where and how to begin authorization; it is not itself a credential.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Protect an ASP.NET Core MCP server
The C# demonstration uses an ASP.NET Core application and the official MCP C# SDK. The OAuth integration shown here was still in a pull request. Den begins with AddAuthentication, selecting the MCP authentication scheme and framework-provided validation. After repairing the screen sharing, he walks through the configuration again with the code visible.
The configuration has distinct layers:
- Authentication and validation: MCP authentication defaults select the scheme, while framework JWT components validate the incoming token.
- Discovery: Metadata events and the demonstrated
AddMcpconfiguration supply PRM, including header-based bearer authentication and Entra ID authorization metadata. - Request processing:
UseAuthenticationandUseAuthorizationadd the middleware that applies authentication and authorization to requests.
For the JWT-validation layer, the following C# helper makes the trusted issuer and intended resource explicit. It complements the MCP-specific discovery configuration described above:
csharp
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
public static class TokenValidationConfiguration
{
public static AuthenticationBuilder AddResourceTokenValidation(
this AuthenticationBuilder authentication,
string authority,
string audience)
{
return authentication.AddJwtBearer(
JwtBearerDefaults.AuthenticationScheme,
options =>
{
options.Authority = authority;
options.Audience = audience;
options.TokenValidationParameters =
new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true
};
});
}
}
The JWT handler supplies validation machinery; the application still supplies the identity provider and resource it trusts. The server then starts locally for the end-to-end test.
In the browser, the localhost PRM identifies login.microsoftonline.com as the authorization server and declares scopes and header-based bearer authentication. On the client side, Den configures a generic OAuth provider with a client ID and scopes, then uses the normal transport setup to connect to the test server. The client’s authorization logic is not specific to Microsoft.
The client run finishes quickly because Den is already authorized; it does not show a fresh interactive sign-in. He reports that the client discovers metadata, acquires a token from Entra ID, and sends it to the server. The server verifies the token and invokes the weather tool, which returns no alerts. This completes the protected request path using the pending SDK integration.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Put a gateway in front of the deployed server
Moving from localhost to a deployed service introduces another place to enforce protection: a gateway. Julia, who works on Azure API Management, recommends placing it between clients and the remote MCP server. She starts a public sample deployment with the Azure Developer CLI:
bash
azd up
The command provisions the sample’s Azure resources while she explains the architecture.
Azure API Management fronts an Azure-hosted MCP server with three implemented tools. The architecture slide shows the server in Azure Functions, with VS Code and MCP Inspector as clients. The Azure Remote MCP Proxy arrangement includes an OAuth API that coordinates Entra ID login and consent, alongside the MCP API that exposes the backend.
Julia estimates that this sample deployment takes “maybe five minutes max.” That is an estimate for her demonstration, without measured timing conditions. Provisioning also creates an App Service plan and Log Analytics for hosting, monitoring, analysis, and logging. These are the operational components behind her description of the example as production ready; they do not establish that an arbitrary deployment has passed a security review.
Before connecting a client, Julia checks API Management’s APIs tab for both expected endpoints: the MCP API and the OAuth API. She also notes that the samples will evolve with the specification. This deployment check establishes that both the resource path and the authorization path are present before testing consent.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Authorize Inspector, then VS Code
MCP Inspector provides the first client test:
- Enter the deployed endpoint and select Connect.
- Check the application name on the consent page and allow access.
- Accept the requested permissions on first use.
- Return to Inspector and list the tools.
After consent, Inspector connects and displays the sample’s tool catalog. The user-facing authorization step is now visible, unlike the already-authorized C# run.
Next, Julia adds the endpoint to VS Code’s user settings under the name AI Engineer. Starting the server triggers an OAuth notification. Opening it leads to the same consent flow, this time with VS Code’s application name. Once she grants consent, the tools become available in VS Code Insiders. Authorization is associated with the client application requesting access, not merely with having visited a consent page earlier in another client.
GitHub Copilot detects the tools, and Julia submits a simple Hello World prompt. Copilot selects and runs the tool through the authenticated connection. Expanding the tool call shows the successful output, “Hello, I'm an MCP tool”. This demonstration goes beyond discovering a tool catalog: it shows an authorized invocation and its returned result.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Expose existing REST operations as tools
A custom MCP implementation is not the only starting point. Julia next demonstrates API Management’s ability to expose selected operations from an existing REST API as MCP tools. Instead of rewriting those operations, a developer configures which endpoints should become tools and connects the generated MCP endpoint to a client.
Julia copies that endpoint into VS Code and starts it, explicitly reminding developers to implement authorization. API Management can secure the interface as well as host it. Copilot detects the server, and VS Code lists three tools backed by the REST API. This final example reaches discovery and readiness to interact; the recording does not show a completed invocation of those REST-backed tools.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Build against the specification and security guidance
The closing guidance returns to the security contract beneath the demos. Den points developers to the authorization specifications and to Security Best Practices, which he says was developed with Anthropic. Those documents matter whether the interface comes from a handwritten server or an existing REST API: the implementation still needs a sound authorization boundary.
At recording time, VS Code Insiders supports the new authorization model and provides a concrete client for trying it. Den encourages developers to install it, test their servers, and provide feedback, with Harold available at the conference to help debug problems. The next step is to exercise the full path—discovery, consent, validation, and tool access—with an actual client, not stop once the endpoint responds.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
The historical authorization specification discussed in the talk, including discovery, OAuth flows and token handling.
Source code, packages and examples for building MCP clients and servers in C#.
Further reading
An experimental Azure sample with gateway authorization, Functions hosting, monitoring and azd deployment instructions.
Updates since the talk
- MCP authorization: June 2025 specificationDocumentation
The subsequent specification formalizing resource-server discovery and token audience requirements.
- OAuth in the MCP C# SDKArticle
Den's follow-up walkthrough of OAuth client configuration and protected ASP.NET Core MCP servers.
- MCP Security Best PracticesDocumentation
Later security guidance covering client consent, token passthrough and other MCP implementation risks.
Azure API Management instructions for creating an MCP interface from existing REST API operations.
- VS Code 1.101 authorization supportDocumentation
June 12, 2025 release notes documenting support for both the March authorization specification and its draft successor.
Full transcript
Loading transcript…