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.

Who should be allowed to call your tools?

Should everyone who can reach an MCP server be allowed to use its tools? Clients such as Claude Desktop, VS Code, and Visual Studio can connect to servers that expose protected APIs. An internet-accessible server outside a VPN needs an authorization boundary just as those APIs do. Reachability is not permission.

Slide with a door lock photograph and three statements: not every server should be open, protection is super-important for remote servers, and not really relevant to local servers.Open full source frame
Not every server should be open: remote and local servers have different authorization needs.

The API behind a tool may need to know which customer is calling, what permissions that customer has, and which administrator policies apply. That user context must remain meaningful at the MCP layer: an administrator may have access to one set of tools, while a contributor receives another. Protecting the server therefore means preserving permission boundaries, not merely placing a login screen in front of an otherwise unrestricted tool catalog.

0:340:54
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

0:34 · section reference included

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.

2:042:12
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

2:04 · section reference included

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.

3:073:28
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

3:07 · section reference included

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.

ComponentResponsibility
MCP clientComplete authorization, acquire a token, send it with requests
MCP resource serverPublish discovery metadata and validate incoming tokens
Authorization serverIssue 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.

Three emoji-marked statements describe the client's end-to-end token dance, server token validation and metadata hosting, and minimal implementation work for developers.Open full source frame
Clients handle the token dance; servers validate tokens and host metadata.

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.

4:324:50
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

4:32 · section reference included

A 401 response starts discovery

The authorization flow begins with an ordinary request that lacks user context:

  1. The MCP client requests data from the protected server.
  2. The server returns HTTP 401. Its WWW-Authenticate header points to a Protected Resource Metadata document, or PRM.
  3. The client retrieves that document and discovers which authorization server to use. The provider could be Entra ID, Okta, Auth0, or Keycloak.
  4. The client completes OAuth discovery and authorization to obtain a token.
  5. 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.

6:597:05
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

6:59 · section reference included

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 AddMcp configuration supply PRM, including header-based bearer authentication and Entra ID authorization metadata.
  • Request processing: UseAuthentication and UseAuthorization add 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.

9:099:25
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

9:09 · section reference included

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.

Architecture diagram connects VS Code and MCP Inspector to an Azure API Management gateway, an Azure Function with three MCP tools, and Microsoft Entra ID below.Open full source frame
Azure API Management sits between MCP clients and an Azure Function MCP server, with Microsoft Entra ID handling identity.

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.

12:5113:08
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

12:51 · section reference included

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.

17:5218:14
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

17:52 · section reference included

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.

Slide lists modelcontextprotocol.io links for the dated authorization specification, draft authorization specification, and draft security best practices beside a castle photograph.Open full source frame
MCP authorization specifications and security best practices provide further guidance.

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.

19:2819:30
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

19:28 · section reference included

Resources

From the talk

Updates since the talk

Transcript download
Full transcript

Loading transcript…