Skip to content

Server Auth providers not loaded #1700

Description

@maximehardy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions