Authenticating Clients

Checked against FrontMCP 1.12.2 on

IntermediateMCP 2026-07-28

Authentication answers one question: who is calling? An MCP client answers it with a credential in the Authorization header of every request, and FrontMCP checks that credential before any tool runs. Which credentials count, and what happens to a request without one, depend on the server's auth mode. FrontMCP has five: public, static, transparent, local and remote.

You will learn

  • Who is calling when a request carries no credentials
  • Where credentials travel, and why they never go in tool arguments
  • How to protect a server with a shared key (static)
  • How to accept tokens from your identity provider (transparent)
  • What a client gets back when it isn't let in, and how to choose a mode

A server anyone can call

Every server so far in this course has had no auth option, which means mode: "public": every request is let in. Here the mode is spelled out, and whoami reports who FrontMCP thinks is calling:

Open
import { Tool, ToolContext } from "@frontmcp/sdk";

@Tool({
  name: "whoami",
  description: "Say who the server thinks is calling, and with which scopes.",
  inputSchema: {},
  annotations: { readOnlyHint: true },
})
export class WhoAmI extends ToolContext {
  async execute() {
    return { caller: this.auth.user.sub, scopes: this.auth.scopes };
  }
}

Starting FrontMCP in your browser…

FrontMCP starts when this example comes into view.

The caller is anon: followed by a random id, with one scope, anonymous. this.auth is where a tool finds out who is calling; the next lesson covers what's in it.

Now open the Tests tab. Call whoami twice and you get two different ids. Under MCP 2026-07-28 there are no sessions: each request is authenticated on its own, and a request without credentials is a new stranger every time. Your server can't tell that two anonymous calls came from the same client. That matters for anything that counts per caller: the rate limits later in this chapter count all anonymous callers together, as one. It matters for anything kept per caller too: by default, the Cache plugin never answers an anonymous caller from its cache.

Public mode is right on your laptop and for a server that only exposes public data. On a server that can reach your tickets, anyone who finds the URL can call every tool.

Where credentials travel

A client sends its credential in the HTTP Authorization header, on every request, including tools/list:

POST / HTTP/1.1
Host: desk.example.com
Authorization: Bearer 9c1f4e7a…
Content-Type: application/json
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: close_ticket

{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"close_ticket","arguments":{"id":"T-1"}}}

The header is set by the client application, from what the user configured or signed in with. The model never sees it and can't change it. Tool arguments are the opposite: the model writes them, and it can write anything. So a tool should never learn who is calling from an argument like agent or userId. It reads the identity FrontMCP established from the header. The first challenge below fixes a tool that gets this wrong.

Requiring a shared key: static mode

The smallest step up from public is one secret that every legitimate client sends. Many MCP hosts have a setting for exactly this, often labelled "API key" or "access token", that adds a fixed Authorization: Bearer … header to every request. mode: "static" checks it:

main.ts
@FrontMcp({
  info: { name: "help-desk", version: "1.0.0" },
  apps: [HelpDeskApp],
  auth: { mode: "static", tokens: [process.env.DESK_API_KEY!] },
})
export default class Server {}

A request without the header, or with a key that isn't in tokens, doesn't reach any tool:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="mcp"
Content-Type: application/json; charset=utf-8

{"error":"Unauthorized"}

A wrong key gets the same status, with the reason in the challenge:

WWW-Authenticate: Bearer realm="mcp", error="invalid_token", error_description="The access token is invalid"

This is an HTTP response, not a JSON-RPC error or a tool result. The model never sees it; the client does, and the fix is in the client's settings. A request with the right key gets through, and its caller is static: followed by 12 hex characters derived from the key, with the scope static. The key itself never reaches your tools: it's in neither this.auth nor this.context.authInfo.

OptionDefaultWhat it does
tokensrequiredThe accepted keys. Compared in constant time.
header"authorization"The request header that carries the key, like "x-api-key".
scheme"Bearer"The prefix before the key, matched without regard to case. "" for a header that holds the bare key.
scopes["static"]The scopes an accepted request gets.
realm"mcp"The realm in the WWW-Authenticate challenge.

Accepting tokens from your identity provider

If your users already sign in with an identity provider, like Auth0, Okta or Keycloak, the client can get an access token (a signed JWT) from it and send that. mode: "transparent" checks those tokens and doesn't issue any of its own:

main.ts
@FrontMcp({
  info: { name: "help-desk", version: "1.0.0" },
  apps: [HelpDeskApp],
  auth: {
    mode: "transparent",
    provider: "https://auth.example.com",
    expectedAudience: "https://desk.example.com",
    requiredScopes: ["tickets:read"],
  },
})
export default class Server {}

For each request, FrontMCP checks that the token is signed by one of the provider's keys, that its issuer (iss) is provider, that it hasn't expired, and, if it names an audience (aud), that the audience is expectedAudience. The caller is then the token's sub, its scopes come from the token's scope claim (or scp, which some providers use instead), and the rest of its claims are available to your tools. A request that fails gets a 401 or 403 that says why:

RequestStatusWWW-Authenticate
No token401Bearer resource_metadata="https://desk.example.com/.well-known/oauth-protected-resource"
Not a JWT401The same, plus error="invalid_token", error_description="Token is not a valid JWT"
Expired, wrong issuer, or a signature the provider's keys don't match401The same, plus error="invalid_token", error_description="no_provider_verified (kid=…)"
No sub, client_id or azp: it doesn't say who is calling401The same, plus error="invalid_token" and a description naming the missing claims
Issued for another audience401The same, plus error="invalid_token" and a description naming both audiences
Missing a scope in requiredScopes403The same, plus error="insufficient_scope" and scope="tickets:read"

The URLs in these headers start with the server's address. FrontMCP's Node server builds it from http:// and the request's Host header, so behind a proxy that terminates TLS they say http://; set FRONTMCP_PUBLIC_URL=https://desk.example.com to get the addresses above. The server's public address has the details.

resource_metadata points at a document FrontMCP serves, which tells an MCP client where to get a token. That's how a client that has never seen your server knows to start a sign-in instead of just failing.

Letting anonymous callers in, with less

A token-only server shuts out everyone who hasn't signed in. allowAnonymous: true lets requests without a token in, as anonymous callers with the scopes in anonymousScopes. Requests that do carry a token are still checked, and a bad token is still refused. Because an anonymous request needs no header, this one runs in the Playground:

Open
import { App, FrontMcp } from "@frontmcp/sdk";
import { WhoAmI } from "./whoami.tool";

@App({ id: "help-desk", name: "Help Desk", tools: [WhoAmI] })
class HelpDeskApp {}

@FrontMcp({
  info: { name: "help-desk", version: "1.0.0" },
  apps: [HelpDeskApp],
  auth: {
    mode: "transparent",
    provider: "https://auth.example.com",
    allowAnonymous: true,
    anonymousScopes: ["tickets:read"],
  },
})
export default class Server {}

Starting FrontMCP in your browser…

FrontMCP starts when this example comes into view.

The caller is still anon:…, now with the scope tickets:read. A signed-in support agent would arrive with the scopes in their token, like tickets:read tickets:write. Letting each tool decide what those scopes allow is the subject of the next lesson.

Letting FrontMCP run the sign-in

transparent assumes someone else issues the tokens. In the other two modes, FrontMCP is itself an OAuth 2.1 authorization server: MCP clients register with it, send the user to sign in, and get tokens FrontMCP signed.

  • local: FrontMCP shows its own sign-in page and issues tokens for the users who complete it. For a server with no identity provider behind it.
  • remote: FrontMCP sends the user to an upstream provider (provider, with your clientId and clientSecret there) to sign in, then issues its own token for that identity. For providers that MCP clients can't register with directly, or when you want FrontMCP's consent screen between the user and your tools.
main.ts
@FrontMcp({
  info: { name: "help-desk", version: "1.0.0" },
  apps: [HelpDeskApp],
  auth: {
    mode: "remote",
    provider: "https://auth.example.com",
    clientId: process.env.DESK_CLIENT_ID!,
    clientSecret: process.env.DESK_CLIENT_SECRET!,
  },
})
export default class Server {}

To a client without a token, both answer like transparent: a 401 with resource_metadata, except that the document it points to names FrontMCP itself as the place to get a token. The tokens they issue are kept in memory by default (tokenStorage: "memory"), so they're lost on restart and not shared between instances; tokenStorage also takes { redis } or { sqlite }. Their sign-in pages, consent screens and storage have many options of their own, beyond this lesson: see Local auth, Custom login UI, Remote and proxied auth, and Client ID metadata for clients that identify themselves by a URL.

How the modes map to MCP authorization

In the terms of the MCP authorization specification (revision 2026-07-28, the newest of the revisions FrontMCP speaks), a FrontMCP server in transparent mode is an OAuth 2.1 resource server only: your identity provider is the authorization server, and FrontMCP verifies the JWTs it issues. In local and remote mode, FrontMCP is both the resource server and the authorization server: it publishes authorization server metadata (RFC 8414), registers clients (RFC 7591) or accepts Client ID Metadata Documents, advertises PKCE (RFC 7636) with S256, and issues the tokens it then checks. In all three, a request without a token gets a 401 that points to the server's Protected Resource Metadata (RFC 9728), unless transparent mode's allowAnonymous lets it in. public and static mode don't use OAuth.

The specification lets the authorization server be the MCP server itself or a separate service. That choice is what separates transparent from local and remote:

ModeRole in MCP authorizationWhat it servesPKCEHow it checks tokensDetails
publicNone: every request gets inProtected Resource Metadata without authorization_servers. Authorization server metadata is 404NoneNo token needed. A bearer JWT must be one this server signedWhat the server advertises, requests without credentials
staticNone: a shared key, not OAuthThe same as public. Its 401 has no resource_metadata, since a client can't get a key by itselfNoneCompares the key with tokens, in constant timeStatic keys, requests without credentials
transparentResource server only. Your identity provider is the authorization serverProtected Resource Metadata, naming this server. /.well-known/oauth-authorization-server redirects to your provider's. Registration and CIMD are up to your providerAt your provider: FrontMCP serves no OAuth endpointsSignature against your provider's keys, iss, exp, nbf, requiredScopes, and aud against expectedAudience. A token without aud passes unless requireAudience is trueWhat the server advertises, What's checked, CIMD caveats
localResource server and authorization server. Users sign in on FrontMCP's pageProtected Resource Metadata, authorization server metadata, dynamic client registration (off in production unless dcr.enabled), and CIMDRequired, S256 only: plain is refusedIts own HS256 JWTs: signature, exp, iss, and aud, which must be this server's URL or one of expectedAudience. An authorization request's resource (RFC 8707) must be this server's URLEndpoints, /oauth/authorize parameters, Tokens
remoteResource server and authorization server. Users sign in at your provider, through FrontMCPThe same as local, with registration outside production only, for loopback redirect URIsS256, from the client. FrontMCP uses PKCE of its own with your providerThe same as local. FrontMCP never asks your provider to check its tokensWhat FrontMCP serves, How a sign-in works

The specification requires an MCP server to accept only tokens issued for it. Tokens from local and remote mode name the server's address in aud, and the server refuses a token whose aud is another address, unless expectedAudience lists it. In transparent mode, set expectedAudience to your server's public URL, and requireAudience: true so that a token with no aud is refused too: by default it's accepted. Auth in production lists the checks to tighten.

MCP 2026-07-28 deprecates dynamic client registration in favour of Client ID Metadata Documents. In production, registration is off in remote mode, and in local mode unless you set dcr.enabled, so a client your server has never seen signs in with a metadata URL as its client_id: see Client ID metadata (CIMD).

The Playground's client can't sign in, so the tests play a client that has no token yet. They start a server in each mode, send the request a client sends first, and read the documents the 401 points to:

Open
import { test, expect } from "@frontmcp/testing";
import { listTools, request } from "./client";

const transparent = { mode: "transparent", provider: "https://auth.example.com", expectedAudience: "https://desk.example.com" };
const local = { mode: "local" };
const remote = { mode: "remote", provider: "https://auth.example.com", clientId: "help-desk-mcp" };
const withoutOAuth = [{ mode: "public" }, { mode: "static", tokens: ["desk-key-1"] }];

test("a request without a token is refused, and pointed at the Protected Resource Metadata", async () => {
  for (const auth of [transparent, local]) {
    const response = await request(auth, "/", listTools);
    expect(response.status).toBe(401);
    expect(response.headers.get("www-authenticate")).toContain('resource_metadata="https://desk.example.com/.well-known/oauth-protected-resource"');
  }
});

test("transparent: a resource server that sends clients to the provider's metadata", async () => {
  const metadata = await (await request(transparent, "/.well-known/oauth-protected-resource")).json();
  expect(metadata).toMatchObject({ resource: "https://desk.example.com", authorization_servers: ["https://auth.example.com"] });

  const response = await request(transparent, "/.well-known/oauth-authorization-server");
  expect(response.status).toBe(302);
  expect(response.headers.get("location")).toBe("https://auth.example.com/.well-known/oauth-authorization-server");
});

test("local and remote: the authorization server too, with PKCE, registration and CIMD", async () => {
  for (const auth of [local, remote]) {
    const response = await request(auth, "/.well-known/oauth-authorization-server");
    expect(response.status).toBe(200);
    expect(await response.json()).toMatchObject({
      issuer: "https://desk.example.com",
      registration_endpoint: "https://desk.example.com/oauth/register",
      code_challenge_methods_supported: ["S256"],
      client_id_metadata_document_supported: true,
    });
  }
});

test("public and static: no authorization server", async () => {
  for (const auth of withoutOAuth) {
    const metadata = await (await request(auth, "/.well-known/oauth-protected-resource")).json();
    expect(metadata).not.toHaveProperty("authorization_servers");
    expect((await request(auth, "/.well-known/oauth-authorization-server")).status).toBe(404);
  }
});

Starting FrontMCP in your browser…

FrontMCP starts when this example comes into view.

Under createFetchHandler(), the URLs in these documents start with the address the request was sent to, here https://desk.example.com. On FrontMCP's Node server, set FRONTMCP_PUBLIC_URL so they name your public address: see The server's public address.

Choosing a mode

ModeWho gets inWho your tools seeUse it when
publicEveryoneanon:…, new on every request, scope anonymousLocal development, or only public data
staticClients that send one of your keysstatic:…, one id per keyYou configure every client yourself: an internal agent, a host's "API key" setting
transparentClients with a valid token from your identity providerThe token's sub, scopes and claimsYour users already sign in with a provider that issues JWTs
localUsers who sign in on FrontMCP's own pageThe signed-in userThere's no identity provider, and each user should have an identity
remoteUsers who sign in with an upstream provider, through FrontMCPThe signed-in userYour provider doesn't work with MCP clients directly, or you want FrontMCP's consent screen

Start with the simplest mode that tells you what your tools need to know. If a tool only needs to know "one of ours", a shared key is enough. If it needs to know which agent is closing a ticket, it needs tokens.

Recap

  • Without auth, a server is public: every request gets in as anon:…, with a new id each time under 2026-07-28.
  • Credentials travel in the Authorization header of every request, set by the client. Never take identity from tool arguments.
  • static checks a shared key from tokens. Every caller with the same key is the same static:… caller.
  • transparent verifies JWTs from provider: signature, issuer, expiry and audience, plus requiredScopes. allowAnonymous lets requests without a token in with anonymousScopes.
  • A refused request gets 401 (or 403 for missing scopes) with a WWW-Authenticate header, before any tool runs. The model never sees it.
  • local and remote make FrontMCP an OAuth server that signs users in, on its own page or through an upstream provider.
  • In MCP authorization terms, transparent makes FrontMCP a resource server only; local and remote make it the authorization server too, with its own metadata, registration or CIMD, and PKCE.

Try some challenges

Each challenge runs hidden checks against your code. Edit the code, then press Check.

Read all challenge instructions

Take the author from the credentials

This challenge is open below.

Let anonymous callers read

The help desk wants signed-in agents to use tokens from https://auth.example.com, and everyone else to be able to search tickets without signing in. search_tickets already requires the tickets:read scope, and close_ticket requires tickets:write. Don't change the tools: change the server's auth so that requests without a token get in with tickets:read, and nothing more.

import { App, FrontMcp } from "@frontmcp/sdk";
import { CloseTicket, SearchTickets } from "./tickets.tools";

@App({ id: "help-desk", name: "Help Desk", tools: [SearchTickets, CloseTicket] })
class HelpDeskApp {}

@FrontMcp({
  info: { name: "help-desk", version: "1.0.0" },
  apps: [HelpDeskApp],
  auth: { mode: "public" },
})
export default class Server {}
import { PublicMcpError, Tool, ToolContext, z } from "@frontmcp/sdk";

const tickets = [
  { id: "T-1", title: "Cannot log in", status: "open" },
  { id: "T-2", title: "Invoice total is wrong", status: "open" },
  { id: "T-3", title: "Login link expired", status: "open" },
];

@Tool({
  name: "search_tickets",
  description: "Search support tickets by words in their title. Needs the tickets:read scope.",
  inputSchema: { query: z.string().min(1) },
  annotations: { readOnlyHint: true },
})
export class SearchTickets extends ToolContext {
  async execute({ query }: { query: string }) {
    if (!this.auth.hasScope("tickets:read")) {
      this.fail(new PublicMcpError("Searching tickets needs the tickets:read scope.", "FORBIDDEN"));
    }
    const q = query.toLowerCase();
    return { tickets: tickets.filter((t) => t.title.toLowerCase().includes(q)) };
  }
}

@Tool({
  name: "close_ticket",
  description: "Close a support ticket. Needs the tickets:write scope, which signed-in agents have.",
  inputSchema: { id: z.string().describe("Ticket id, like T-1") },
})
export class CloseTicket extends ToolContext {
  async execute({ id }: { id: string }) {
    if (!this.auth.hasScope("tickets:write")) {
      this.fail(new PublicMcpError("Closing tickets needs the tickets:write scope. Ask the user to sign in as an agent.", "FORBIDDEN"));
    }
    const ticket = tickets.find((t) => t.id === id);
    if (!ticket) this.fail(new PublicMcpError(`There's no ticket ${id}.`));
    ticket.status = "closed";
    return { id, closed: true };
  }
}

Challenge 1 of 2

Take the author from the credentials

add_note records who wrote a note from an author argument, so the model can sign a note with any name it likes: the call below signs it "Nour". Remove the argument, and record the caller FrontMCP authenticated instead. In the Playground, that's an anon: id.

Open
import { Tool, ToolContext, z } from "@frontmcp/sdk";

const notes: { ticket: string; text: string; author: string }[] = [];

@Tool({
  name: "add_note",
  description: "Add an internal note to a support ticket.",
  inputSchema: {
    ticket: z.string().describe("Ticket id, like T-1"),
    text: z.string().min(1),
    author: z.string().describe("Who is writing the note"),
  },
})
export class AddNote extends ToolContext {
  async execute({ ticket, text, author }: { ticket: string; text: string; author: string }) {
    const note = { ticket, text, author };
    notes.push(note);
    return { note };
  }
}

Starting FrontMCP in your browser…

FrontMCP starts when this example comes into view.

Report a docs issue · Report a security concern privately