New in version 3.2.4This guide shows you how to secure your FastMCP server using Keycloak OAuth. This integration uses the Remote OAuth pattern with Dynamic Client Registration (DCR), where Keycloak handles user login and your FastMCP server validates the tokens.
Keycloak 26.6.0 or later is required. Earlier versions had a DCR incompatibility with MCP clients (PR #45309) that is fixed in 26.6.0.
Production security: Always configure the audience parameter in production. Without it, your server accepts tokens issued for any audience. Configure Keycloak audience mappers and set audience to your server’s base URL to ensure tokens are specifically intended for your server.
Local infrastructure tooling is deliberately kept out of the FastMCP core library to keep auth integrations slim and the associated maintenance burden as low as possible. That said, Keycloak is a popular identity provider for local development and testing, so a dedicated FastMCP-compatible setup blueprint lives in the companion project fastmcp-keycloak-local.It provides everything needed to develop and test FastMCP servers with Keycloak OAuth locally: a Docker-based Keycloak setup with a pre-configured fastmcp realm (Dynamic Client Registration enabled, test user included), cross-platform start scripts, and integration guides for the MCP Inspector, Claude Desktop, and Claude Code CLI.