π The fast, Pythonic way to build MCP servers and clients.
Clean up settings
Jeremiah Lowin0824b3783d5e
diff --git a/src/fastmcp/server/auth/providers/bearer_env.py b/src/fastmcp/server/auth/providers/bearer_env.pyindex 63eb8c725..ff02af62f 100644--- a/src/fastmcp/server/auth/providers/bearer_env.py+++ b/src/fastmcp/server/auth/providers/bearer_env.py@@ -1,15 +1,10 @@-from enum import Enum-from pydantic_settings import BaseSettings, SettingsConfigDictfrom fastmcp.server.auth.providers.bearer import BearerAuthProvider-class NotSet(Enum):- sentinel = 0---NOTSET = NotSet.sentinel+class NotSet:+ passclass EnvBearerAuthProviderSettings(BaseSettings):@@ -35,11 +30,11 @@ class EnvBearerAuthProvider(BearerAuthProvider):def __init__(self,- public_key: str | None | NotSet = NOTSET,- jwks_uri: str | None | NotSet = NOTSET,- issuer: str | None | NotSet = NOTSET,- audience: str | None | NotSet = NOTSET,- required_scopes: list[str] | None | NotSet = NOTSET,+ public_key: str | None | type[NotSet] = NotSet,+ jwks_uri: str | None | type[NotSet] = NotSet,+ issuer: str | None | type[NotSet] = NotSet,+ audience: str | None | type[NotSet] = NotSet,+ required_scopes: list[str] | None | type[NotSet] = NotSet,):kwargs = {"public_key": public_key,@@ -49,6 +44,6 @@ class EnvBearerAuthProvider(BearerAuthProvider):"required_scopes": required_scopes,}settings = EnvBearerAuthProviderSettings(- **{k: v for k, v in kwargs.items() if v is not NOTSET}+ **{k: v for k, v in kwargs.items() if v is not NotSet})super().__init__(**settings.model_dump())diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.pyindex fe95ec6e1..a092ed3b8 100644--- a/src/fastmcp/server/server.py+++ b/src/fastmcp/server/server.py@@ -187,7 +187,7 @@ class FastMCP(Generic[LifespanResultT]):lifespan=_lifespan_wrapper(self, lifespan),)- if auth is None and self.settings.auth_provider == "bearer_env":+ if auth is None and self.settings.default_auth_provider == "bearer_env":auth = EnvBearerAuthProvider()self.auth = authdiff --git a/src/fastmcp/settings.py b/src/fastmcp/settings.pyindex 6a2075b91..96939d11c 100644--- a/src/fastmcp/settings.py+++ b/src/fastmcp/settings.py@@ -180,7 +180,23 @@ class ServerSettings(BaseSettings):)# Auth settings- auth_provider: Literal["bearer_env"] | None = None+ default_auth_provider: Annotated[+ Literal["bearer_env"] | None,+ Field(+ description=inspect.cleandoc(+ """+ Configure the authentication provider. This setting is intended only to+ be used for remote confirugation of providers that fully support+ environment variable configuration.++ If None, no automatic configuration will take place.++ This setting is *always* overriden by any auth provider passed to the+ FastMCP constructor.+ """+ ),+ ),+ ] = Nonesettings = Settings()