Description
Documentation mentions that authentication providers can be initialized from env vars without code, which is really cool feature! It allows to decouple authentication from the rest of the app. However it does not work for providers other than JWT.
The reason is that providers are registered thanks to decorator @register_provider('Google') but that means the files must be imported before calling registry's get_registered_provider() (see server/auth/registry.py).
It seems that provider classes are pretty light, thus a solution could be to systematically import all of them.
Example code
Using basic server definition as suggested by documentation:
# server.py
from fastmcp import FastMCP
# Authentication automatically configured from environment
mcp = FastMCP(name="My Server")
# .env
FASTMCP_SERVER_AUTH=GOOGLE
FASTMCP_SERVER_AUTH_GOOGLE_BASE_URL=http://localhost:3000
FASTMCP_SERVER_AUTH_GOOGLE_RESOURCE_SERVER_URL=http://localhost:3000/mcp
FASTMCP_SERVER_AUTH_GOOGLE_REDIRECT_PATH=/oauth2callback
FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_ID=...
FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_SECRET=...
FASTMCP_SERVER_AUTH_GOOGLE_REQUIRED_SCOPES=openid
$ fastmcp run server.py
> Loading .env environment variables...
> [09/01/25 18:28:06] ERROR Failed to run: Provider 'GOOGLE' has not been registered.
Workaround
Import the providers directly, but that defeats the purpose of configuring it from env vars.
# server.py
from fastmcp import FastMCP
from fastmcp.server.auth.providers.google import GoogleProvider
mcp = FastMCP('test-server')
Version Information
FastMCP version: 2.12.0
MCP version: 1.13.1
Python version: 3.12.3
Platform: Linux-6.8.0-79-generic-x86_64-with-glibc2.35
OS: Linux Ubuntu 22.04, Ubuntu 24.04, Debian Bookworm
Description
Documentation mentions that authentication providers can be initialized from env vars without code, which is really cool feature! It allows to decouple authentication from the rest of the app. However it does not work for providers other than JWT.
The reason is that providers are registered thanks to decorator
@register_provider('Google')but that means the files must be imported before calling registry'sget_registered_provider()(seeserver/auth/registry.py).It seems that provider classes are pretty light, thus a solution could be to systematically import all of them.
Example code
Using basic server definition as suggested by documentation:
# .env FASTMCP_SERVER_AUTH=GOOGLE FASTMCP_SERVER_AUTH_GOOGLE_BASE_URL=http://localhost:3000 FASTMCP_SERVER_AUTH_GOOGLE_RESOURCE_SERVER_URL=http://localhost:3000/mcp FASTMCP_SERVER_AUTH_GOOGLE_REDIRECT_PATH=/oauth2callback FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_ID=... FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_SECRET=... FASTMCP_SERVER_AUTH_GOOGLE_REQUIRED_SCOPES=openidWorkaround
Import the providers directly, but that defeats the purpose of configuring it from env vars.
Version Information