oauth
fastmcp.client.auth.oauth
Functions
default_cache_dir
OAuth
Create an OAuthClientProvider for an MCP server.
This is intended to be provided to the auth
parameter of an
httpx.AsyncClient (or appropriate FastMCP client/transport instance)
Args:
mcp_url
: Full URL to the MCP endpoint (e.g. “http://host/mcp/sse/”)scopes
: OAuth scopes to request. Can be aclient_name
: Name for this client during registrationtoken_storage_cache_dir
: Directory for FileTokenStorageadditional_client_metadata
: Extra fields for OAuthClientMetadata
Returns:
- OAuthClientProvider
Classes
ServerOAuthMetadata
More flexible OAuth metadata model that accepts broader ranges of values than the restrictive MCP standard model.
This handles real-world OAuth servers like PayPal that may support additional methods not in the MCP specification.
OAuthClientProvider
OAuth client provider with more flexible OAuth metadata discovery.
FileTokenStorage
File-based token storage implementation for OAuth credentials and tokens. Implements the mcp.client.auth.TokenStorage protocol.
Each instance is tied to a specific server URL for proper token isolation.
Methods:
get_base_url
Extract the base URL (scheme + host) from a URL.
get_cache_key
Generate a safe filesystem key from the server’s base URL.
clear
Clear all cached data for this server.
clear_all
Clear all cached data for all servers.