mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-14 17:49:11 +02:00
102 lines
3.2 KiB
Text
102 lines
3.2 KiB
Text
---
|
|
title: oauth
|
|
sidebarTitle: oauth
|
|
---
|
|
|
|
# `fastmcp.client.auth.oauth`
|
|
|
|
## Functions
|
|
|
|
### `default_cache_dir` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L38"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
default_cache_dir() -> Path
|
|
```
|
|
|
|
### `OAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L295"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
OAuth(mcp_url: str, scopes: str | list[str] | None = None, client_name: str = 'FastMCP Client', token_storage_cache_dir: Path | None = None, additional_client_metadata: dict[str, Any] | None = None) -> _MCPOAuthClientProvider
|
|
```
|
|
|
|
|
|
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 a
|
|
- `client_name`: Name for this client during registration
|
|
- `token_storage_cache_dir`: Directory for FileTokenStorage
|
|
- `additional_client_metadata`: Extra fields for OAuthClientMetadata
|
|
|
|
**Returns:**
|
|
- OAuthClientProvider
|
|
|
|
|
|
## Classes
|
|
|
|
### `ServerOAuthMetadata` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L43"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
|
|
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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L68"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
|
|
OAuth client provider with more flexible OAuth metadata discovery.
|
|
|
|
|
|
### `FileTokenStorage` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L116"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
|
|
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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L131"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
get_base_url(url: str) -> str
|
|
```
|
|
|
|
Extract the base URL (scheme + host) from a URL.
|
|
|
|
|
|
#### `get_cache_key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L136"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
get_cache_key(self) -> str
|
|
```
|
|
|
|
Generate a safe filesystem key from the server's base URL.
|
|
|
|
|
|
#### `clear` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L208"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
clear(self) -> None
|
|
```
|
|
|
|
Clear all cached data for this server.
|
|
|
|
|
|
#### `clear_all` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L217"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
clear_all(cls, cache_dir: Path | None = None) -> None
|
|
```
|
|
|
|
Clear all cached data for all servers.
|
|
|