Meet Prefect Horizon, the enterprise MCP gateway built by the team behind FastMCP

fastmcp.client.auth.oauth

Functions

check_if_auth_required

check_if_auth_required(mcp_url: str, httpx_kwargs: dict[str, Any] | None = None) -> bool

Check if the MCP endpoint requires authentication by making a test request.Returns:

  • True if auth appears to be required, False otherwise

Classes

ClientNotFoundError

Raised when OAuth client credentials are not found on the server.

TokenStorageAdapter

Methods:

clear
clear(self) -> None
get_tokens
get_tokens(self) -> OAuthToken | None
set_tokens
set_tokens(self, tokens: OAuthToken) -> None
get_token_expiry
get_token_expiry(self) -> float | None
get_client_info
get_client_info(self) -> OAuthClientInformationFull | None
set_client_info
set_client_info(self, client_info: OAuthClientInformationFull) -> None

OAuth

OAuth client provider for MCP servers with browser-based authentication. This class provides OAuth authentication for FastMCP clients by opening a browser for user authorization and running a local callback server.

Methods:

redirect_handler
redirect_handler(self, authorization_url: str) -> None

Open browser for authorization, with pre-flight check for invalid client.

callback_handler
callback_handler(self) -> tuple[str, str | None]

Handle OAuth callback and return (auth_code, state).

async_auth_flow
async_auth_flow(self, request: httpx.Request) -> AsyncGenerator[httpx.Request, httpx.Response]

HTTPX auth flow with automatic retry on stale cached credentials. If the OAuth flow fails due to invalid/stale client credentials, clears the cache and retries once with fresh registration.