How to Deploy a FastMCP Server to Production
Run your server over HTTP, add health checks, scale with stateless mode and put it behind systemd and nginx.
Read articleProtect remote servers with JWT verification, token introspection or OAuth, and adopt habits that keep secrets safe.

FastMCP(..., auth=verifier).JWTVerifier with JWKS when your identity provider publishes keys.StaticTokenVerifier is for development only.A server that runs over HTTP is reachable by anyone who knows its address. Authentication ensures that only approved clients can list and call its tools. FastMCP builds this in through a single auth parameter, and this guide shows how to use it for every common scenario.
MCP tools often have real power: they read databases, send messages and modify records. Without authentication, anyone who discovers the endpoint can use that power. The FastMCP deployment guide strongly recommends authentication for remote servers, and some clients refuse to connect without it.
STDIO servers rarely need this, because the client launches them locally under the user’s own account. The guidance below applies to the HTTP transport.
Clients send a token in the Authorization: Bearer <token> header. Before any request reaches your tools, the server passes that token to a verifier, which checks its signature, issuer, audience, expiry and, optionally, its scopes. Requests that fail are rejected with an HTTP 401 response, and your tool code never runs.
| Verifier | Use it when | Production-ready |
|---|---|---|
JWTVerifier with JWKS | Your identity provider publishes signing keys | Yes |
JWTVerifier with a key or secret | You hold a public key or a shared HMAC secret | Yes |
IntrospectionTokenVerifier | Tokens are opaque and must be checked with the provider | Yes |
| OAuth providers | Users sign in with an existing account | Yes |
StaticTokenVerifier | Local development and tests | No |
If your organisation already issues JSON Web Tokens, point FastMCP at the provider’s public keys:
from fastmcp import FastMCP
from fastmcp.server.auth.providers.jwt import JWTVerifier
verifier = JWTVerifier(
jwks_uri="https://auth.yourcompany.com/.well-known/jwks.json",
issuer="https://auth.yourcompany.com",
audience="mcp-production-api",
)
mcp = FastMCP(name="Protected API", auth=verifier)The verifier fetches signing keys from the JWKS endpoint, so key rotation on the provider’s side needs no change to your server. If your provider signs with a non-default algorithm, such as Ed25519, pass it with the algorithm argument.
When no JWKS endpoint is available, supply the public key directly:
verifier = JWTVerifier(
public_key=public_key_pem, # "-----BEGIN PUBLIC KEY-----..."
issuer="https://auth.yourcompany.com",
audience="mcp-production-api",
)Internal services sometimes sign tokens with a shared HMAC secret. Despite its name, the public_key argument accepts that secret too:
import os
verifier = JWTVerifier(
public_key=os.environ["JWT_SECRET"], # at least 32 characters
issuer="internal-auth-service",
audience="mcp-internal-api",
algorithm="HS256",
)During local development, a fixed list of tokens is often enough:
from fastmcp.server.auth.providers.jwt import StaticTokenVerifier
verifier = StaticTokenVerifier(
tokens={
"dev-alice-token": {"client_id": "alice@company.com", "scopes": ["read:data", "write:data"]},
"dev-guest-token": {"client_id": "guest-user", "scopes": ["read:data"]},
},
required_scopes=["read:data"],
)
mcp = FastMCP(name="Development Server", auth=verifier)Clients then send Authorization: Bearer dev-alice-token. The required_scopes list means every token must include read:data to be accepted.
Some providers issue opaque tokens that cannot be decoded locally. In that case the server asks the provider whether a token is valid, following RFC 7662:
import os
from fastmcp.server.auth.providers.introspection import IntrospectionTokenVerifier
verifier = IntrospectionTokenVerifier(
introspection_url="https://auth.yourcompany.com/oauth/introspect",
client_id="mcp-resource-server",
client_secret=os.environ["INTROSPECTION_SECRET"],
required_scopes=["api:read"],
)Introspection adds a network call to each request, so it suits servers where immediate revocation matters more than the last few milliseconds of latency.
For servers that let people sign in with an existing account, FastMCP includes ready-made providers for services such as GitHub, Google, Discord, WorkOS, Azure, Clerk and Hugging Face. Each provider has its own configuration page in the official documentation, covering client IDs, redirect URLs and scopes.
OAuth is the right choice when the people using an AI application should act under their own identity, so that the server can apply their individual permissions.
Scopes describe what a token may do. A small, consistent set is easier to reason about than many fine-grained ones:
read:data for listing and reading;write:data for changes;admin:users for administrative actions.Grant each client the narrowest set it needs. A reporting dashboard, for example, should never hold a token that can write.
The FastMCP client attaches a bearer token through its auth argument:
import os
from fastmcp import Client
client = Client("https://mcp.example.com/mcp", auth=os.environ["MCP_TOKEN"])mask_error_details=True stops unexpected exception details reaching clients.Confirm both outcomes before you deploy: a request with a valid token should succeed, and a request without one, or with an expired one, should receive a 401. A StaticTokenVerifier makes the positive case easy to automate in a test suite, while the production verifier is configured through environment variables in each deployed environment.
Usually not. A STDIO server runs as a local process launched by the client under the user's own account, so there is no network endpoint for others to reach.
No. Custom routes created with @mcp.custom_route bypass the authentication middleware, which suits load-balancer probes but means they must never expose sensitive data.
If your identity provider issues JWTs and publishes a JWKS endpoint, use JWTVerifier. For opaque tokens, use introspection. For user sign-in with existing accounts, use one of the OAuth providers.
In the Authorization: Bearer <token> header. The FastMCP client does this for you when you pass the token through its auth argument.
Run your server over HTTP, add health checks, scale with stateless mode and put it behind systemd and nginx.
Read articleWrite quick, reliable tests with an in-memory client, pytest fixtures, parametrised cases and snapshots.
Read articleLet tools return forms, tables and charts that render in the conversation, and preview them locally.
Read article