Spaces:
Running
Running
Jeremiah Lowin commited on
Docs updates (#1336)
Browse files- docs/clients/auth/bearer.mdx +0 -1
- docs/docs.json +25 -10
- docs/integrations/authkit.mdx +1 -1
- docs/integrations/chatgpt.mdx +1 -1
- docs/integrations/claude-code.mdx +0 -1
- docs/integrations/eunomia-authorization.mdx +0 -1
- docs/integrations/mcp-json-configuration.mdx +1 -1
- docs/integrations/openai.mdx +0 -1
- docs/integrations/permit.mdx +1 -2
- docs/python-sdk/fastmcp-cli-cli.mdx +2 -2
- docs/python-sdk/fastmcp-cli-run.mdx +14 -8
- docs/python-sdk/fastmcp-client-auth-oauth.mdx +40 -51
- docs/python-sdk/fastmcp-client-transports.mdx +31 -25
- docs/python-sdk/fastmcp-prompts-prompt.mdx +7 -7
- docs/python-sdk/fastmcp-resources-resource.mdx +14 -14
- docs/python-sdk/fastmcp-resources-template.mdx +18 -18
- docs/python-sdk/fastmcp-server-auth-auth.mdx +96 -2
- docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx +3 -142
- docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx +10 -10
- docs/python-sdk/fastmcp-server-auth-providers-jwt.mdx +149 -0
- docs/python-sdk/fastmcp-server-auth-providers-workos.mdx +58 -0
- docs/python-sdk/fastmcp-server-auth-registry.mdx +43 -0
- docs/python-sdk/fastmcp-server-context.mdx +46 -36
- docs/python-sdk/fastmcp-server-dependencies.mdx +1 -1
- docs/python-sdk/fastmcp-server-http.mdx +14 -14
- docs/python-sdk/fastmcp-server-middleware-middleware.mdx +15 -17
- docs/python-sdk/fastmcp-server-proxy.mdx +44 -35
- docs/python-sdk/fastmcp-server-server.mdx +53 -49
- docs/python-sdk/fastmcp-tools-tool.mdx +11 -11
- docs/python-sdk/fastmcp-tools-tool_transform.mdx +16 -12
- docs/python-sdk/fastmcp-utilities-components.mdx +24 -10
- docs/python-sdk/fastmcp-utilities-mcp_config.mdx +4 -4
- docs/python-sdk/fastmcp-utilities-openapi.mdx +10 -9
- docs/python-sdk/fastmcp-utilities-tests.mdx +34 -3
- docs/python-sdk/fastmcp-utilities-types.mdx +10 -10
- docs/servers/auth/authentication.mdx +4 -3
- docs/servers/auth/full-oauth-server.mdx +2 -1
- docs/servers/auth/{remote-authentication.mdx → remote-oauth.mdx} +5 -4
- docs/servers/auth/token-verification.mdx +1 -0
docs/clients/auth/bearer.mdx
CHANGED
|
@@ -3,7 +3,6 @@ title: Bearer Token Authentication
|
|
| 3 |
sidebarTitle: Bearer Auth
|
| 4 |
description: Authenticate your FastMCP client with a Bearer token.
|
| 5 |
icon: key
|
| 6 |
-
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
|
|
| 3 |
sidebarTitle: Bearer Auth
|
| 4 |
description: Authenticate your FastMCP client with a Bearer token.
|
| 5 |
icon: key
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
docs/docs.json
CHANGED
|
@@ -65,7 +65,10 @@
|
|
| 65 |
{
|
| 66 |
"group": "Essentials",
|
| 67 |
"icon": "cube",
|
| 68 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 69 |
},
|
| 70 |
{
|
| 71 |
"group": "Core Components",
|
|
@@ -95,8 +98,8 @@
|
|
| 95 |
"icon": "shield-check",
|
| 96 |
"pages": [
|
| 97 |
"servers/auth/authentication",
|
|
|
|
| 98 |
"servers/auth/token-verification",
|
| 99 |
-
"servers/auth/remote-authentication",
|
| 100 |
"servers/auth/full-oauth-server"
|
| 101 |
]
|
| 102 |
}
|
|
@@ -108,7 +111,10 @@
|
|
| 108 |
{
|
| 109 |
"group": "Essentials",
|
| 110 |
"icon": "cube",
|
| 111 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 112 |
},
|
| 113 |
{
|
| 114 |
"group": "Core Operations",
|
|
@@ -134,7 +140,10 @@
|
|
| 134 |
{
|
| 135 |
"group": "Authentication",
|
| 136 |
"icon": "user-shield",
|
| 137 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
]
|
| 140 |
},
|
|
@@ -181,12 +190,17 @@
|
|
| 181 |
},
|
| 182 |
{
|
| 183 |
"anchor": "What's New",
|
| 184 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 185 |
},
|
| 186 |
{
|
| 187 |
"anchor": "Community",
|
| 188 |
"icon": "users",
|
| 189 |
-
"pages": [
|
|
|
|
|
|
|
| 190 |
}
|
| 191 |
]
|
| 192 |
},
|
|
@@ -275,10 +289,12 @@
|
|
| 275 |
"pages": [
|
| 276 |
"python-sdk/fastmcp-server-auth-providers-__init__",
|
| 277 |
"python-sdk/fastmcp-server-auth-providers-bearer",
|
| 278 |
-
"python-sdk/fastmcp-server-auth-providers-
|
| 279 |
-
"python-sdk/fastmcp-server-auth-providers-
|
|
|
|
| 280 |
]
|
| 281 |
-
}
|
|
|
|
| 282 |
]
|
| 283 |
},
|
| 284 |
"python-sdk/fastmcp-server-context",
|
|
@@ -315,7 +331,6 @@
|
|
| 315 |
"group": "fastmcp.utilities",
|
| 316 |
"pages": [
|
| 317 |
"python-sdk/fastmcp-utilities-__init__",
|
| 318 |
-
"python-sdk/fastmcp-utilities-cache",
|
| 319 |
"python-sdk/fastmcp-utilities-cli",
|
| 320 |
"python-sdk/fastmcp-utilities-components",
|
| 321 |
"python-sdk/fastmcp-utilities-exceptions",
|
|
|
|
| 65 |
{
|
| 66 |
"group": "Essentials",
|
| 67 |
"icon": "cube",
|
| 68 |
+
"pages": [
|
| 69 |
+
"servers/server",
|
| 70 |
+
"deployment/running-server"
|
| 71 |
+
]
|
| 72 |
},
|
| 73 |
{
|
| 74 |
"group": "Core Components",
|
|
|
|
| 98 |
"icon": "shield-check",
|
| 99 |
"pages": [
|
| 100 |
"servers/auth/authentication",
|
| 101 |
+
"servers/auth/remote-oauth",
|
| 102 |
"servers/auth/token-verification",
|
|
|
|
| 103 |
"servers/auth/full-oauth-server"
|
| 104 |
]
|
| 105 |
}
|
|
|
|
| 111 |
{
|
| 112 |
"group": "Essentials",
|
| 113 |
"icon": "cube",
|
| 114 |
+
"pages": [
|
| 115 |
+
"clients/client",
|
| 116 |
+
"clients/transports"
|
| 117 |
+
]
|
| 118 |
},
|
| 119 |
{
|
| 120 |
"group": "Core Operations",
|
|
|
|
| 140 |
{
|
| 141 |
"group": "Authentication",
|
| 142 |
"icon": "user-shield",
|
| 143 |
+
"pages": [
|
| 144 |
+
"clients/auth/oauth",
|
| 145 |
+
"clients/auth/bearer"
|
| 146 |
+
]
|
| 147 |
}
|
| 148 |
]
|
| 149 |
},
|
|
|
|
| 190 |
},
|
| 191 |
{
|
| 192 |
"anchor": "What's New",
|
| 193 |
+
"pages": [
|
| 194 |
+
"updates",
|
| 195 |
+
"changelog"
|
| 196 |
+
]
|
| 197 |
},
|
| 198 |
{
|
| 199 |
"anchor": "Community",
|
| 200 |
"icon": "users",
|
| 201 |
+
"pages": [
|
| 202 |
+
"community/showcase"
|
| 203 |
+
]
|
| 204 |
}
|
| 205 |
]
|
| 206 |
},
|
|
|
|
| 289 |
"pages": [
|
| 290 |
"python-sdk/fastmcp-server-auth-providers-__init__",
|
| 291 |
"python-sdk/fastmcp-server-auth-providers-bearer",
|
| 292 |
+
"python-sdk/fastmcp-server-auth-providers-in_memory",
|
| 293 |
+
"python-sdk/fastmcp-server-auth-providers-jwt",
|
| 294 |
+
"python-sdk/fastmcp-server-auth-providers-workos"
|
| 295 |
]
|
| 296 |
+
},
|
| 297 |
+
"python-sdk/fastmcp-server-auth-registry"
|
| 298 |
]
|
| 299 |
},
|
| 300 |
"python-sdk/fastmcp-server-context",
|
|
|
|
| 331 |
"group": "fastmcp.utilities",
|
| 332 |
"pages": [
|
| 333 |
"python-sdk/fastmcp-utilities-__init__",
|
|
|
|
| 334 |
"python-sdk/fastmcp-utilities-cli",
|
| 335 |
"python-sdk/fastmcp-utilities-components",
|
| 336 |
"python-sdk/fastmcp-utilities-exceptions",
|
docs/integrations/authkit.mdx
CHANGED
|
@@ -10,7 +10,7 @@ import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
| 10 |
|
| 11 |
<VersionBadge version="2.11.0" />
|
| 12 |
|
| 13 |
-
This guide shows you how to secure your FastMCP server using **WorkOS AuthKit**, a complete authentication and user management solution. This integration uses the [**Remote
|
| 14 |
|
| 15 |
|
| 16 |
## Configuration
|
|
|
|
| 10 |
|
| 11 |
<VersionBadge version="2.11.0" />
|
| 12 |
|
| 13 |
+
This guide shows you how to secure your FastMCP server using **WorkOS AuthKit**, a complete authentication and user management solution. This integration uses the [**Remote OAuth**](/servers/auth/remote-oauth) pattern, where WorkOS handles user login and your FastMCP server validates the tokens.
|
| 14 |
|
| 15 |
|
| 16 |
## Configuration
|
docs/integrations/chatgpt.mdx
CHANGED
|
@@ -3,7 +3,7 @@ title: ChatGPT 🤝 FastMCP
|
|
| 3 |
sidebarTitle: ChatGPT
|
| 4 |
description: Connect FastMCP servers to ChatGPT Deep Research
|
| 5 |
icon: message-smile
|
| 6 |
-
|
| 7 |
---
|
| 8 |
|
| 9 |
ChatGPT supports MCP servers through remote HTTP connections, allowing you to extend ChatGPT's capabilities with custom tools and knowledge from your FastMCP servers.
|
|
|
|
| 3 |
sidebarTitle: ChatGPT
|
| 4 |
description: Connect FastMCP servers to ChatGPT Deep Research
|
| 5 |
icon: message-smile
|
| 6 |
+
|
| 7 |
---
|
| 8 |
|
| 9 |
ChatGPT supports MCP servers through remote HTTP connections, allowing you to extend ChatGPT's capabilities with custom tools and knowledge from your FastMCP servers.
|
docs/integrations/claude-code.mdx
CHANGED
|
@@ -3,7 +3,6 @@ title: Claude Code 🤝 FastMCP
|
|
| 3 |
sidebarTitle: Claude Code
|
| 4 |
description: Install and use FastMCP servers in Claude Code
|
| 5 |
icon: message-smile
|
| 6 |
-
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
|
|
| 3 |
sidebarTitle: Claude Code
|
| 4 |
description: Install and use FastMCP servers in Claude Code
|
| 5 |
icon: message-smile
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
docs/integrations/eunomia-authorization.mdx
CHANGED
|
@@ -3,7 +3,6 @@ title: Eunomia Authorization 🤝 FastMCP
|
|
| 3 |
sidebarTitle: Eunomia Auth
|
| 4 |
description: Add policy-based authorization to your FastMCP servers with Eunomia
|
| 5 |
icon: shield-check
|
| 6 |
-
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
Add **policy-based authorization** to your FastMCP servers with one-line code addition with the **[Eunomia][eunomia-github] authorization middleware**.
|
|
|
|
| 3 |
sidebarTitle: Eunomia Auth
|
| 4 |
description: Add policy-based authorization to your FastMCP servers with Eunomia
|
| 5 |
icon: shield-check
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
Add **policy-based authorization** to your FastMCP servers with one-line code addition with the **[Eunomia][eunomia-github] authorization middleware**.
|
docs/integrations/mcp-json-configuration.mdx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: MCP JSON Configuration 🤝 FastMCP
|
| 3 |
-
sidebarTitle: MCP
|
| 4 |
description: Generate standard MCP configuration files for any compatible client
|
| 5 |
icon: brackets-curly
|
| 6 |
tag: NEW
|
|
|
|
| 1 |
---
|
| 2 |
title: MCP JSON Configuration 🤝 FastMCP
|
| 3 |
+
sidebarTitle: MCP.json
|
| 4 |
description: Generate standard MCP configuration files for any compatible client
|
| 5 |
icon: brackets-curly
|
| 6 |
tag: NEW
|
docs/integrations/openai.mdx
CHANGED
|
@@ -3,7 +3,6 @@ title: OpenAI API 🤝 FastMCP
|
|
| 3 |
sidebarTitle: OpenAI API
|
| 4 |
description: Call FastMCP servers from the OpenAI API
|
| 5 |
icon: message-code
|
| 6 |
-
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
|
|
| 3 |
sidebarTitle: OpenAI API
|
| 4 |
description: Call FastMCP servers from the OpenAI API
|
| 5 |
icon: message-code
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
docs/integrations/permit.mdx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: Permit.io Authorization 🤝 FastMCP
|
| 3 |
-
sidebarTitle: Permit.io
|
| 4 |
description: Add fine-grained authorization to your FastMCP servers with Permit.io
|
| 5 |
icon: shield-check
|
| 6 |
-
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
Add **policy-based authorization** to your FastMCP servers with one-line code addition with the **[Permit.io][permit-github] authorization middleware**.
|
|
|
|
| 1 |
---
|
| 2 |
title: Permit.io Authorization 🤝 FastMCP
|
| 3 |
+
sidebarTitle: Permit.io
|
| 4 |
description: Add fine-grained authorization to your FastMCP servers with Permit.io
|
| 5 |
icon: shield-check
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
Add **policy-based authorization** to your FastMCP servers with one-line code addition with the **[Permit.io][permit-github] authorization middleware**.
|
docs/python-sdk/fastmcp-cli-cli.mdx
CHANGED
|
@@ -36,7 +36,7 @@ Run an MCP server with the MCP Inspector for development.
|
|
| 36 |
### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L286" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
-
run(server_spec: str) -> None
|
| 40 |
```
|
| 41 |
|
| 42 |
|
|
@@ -55,7 +55,7 @@ fastmcp run server.py -- --config config.json --debug
|
|
| 55 |
- `server_spec`: Python file, object specification (file\:obj), MCPConfig file, or URL
|
| 56 |
|
| 57 |
|
| 58 |
-
### `inspect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#
|
| 59 |
|
| 60 |
```python
|
| 61 |
inspect(server_spec: str) -> None
|
|
|
|
| 36 |
### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L286" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
+
run(server_spec: str, *server_args: str) -> None
|
| 40 |
```
|
| 41 |
|
| 42 |
|
|
|
|
| 55 |
- `server_spec`: Python file, object specification (file\:obj), MCPConfig file, or URL
|
| 56 |
|
| 57 |
|
| 58 |
+
### `inspect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L439" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 59 |
|
| 60 |
```python
|
| 61 |
inspect(server_spec: str) -> None
|
docs/python-sdk/fastmcp-cli-run.mdx
CHANGED
|
@@ -10,7 +10,7 @@ FastMCP run command implementation with enhanced type hints.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `is_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
is_url(path: str) -> bool
|
|
@@ -20,7 +20,7 @@ is_url(path: str) -> bool
|
|
| 20 |
Check if a string is a URL.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `parse_file_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 24 |
|
| 25 |
```python
|
| 26 |
parse_file_path(server_spec: str) -> tuple[Path, str | None]
|
|
@@ -36,7 +36,7 @@ Parse a file path that may include a server object specification.
|
|
| 36 |
- Tuple of (file_path, server_object)
|
| 37 |
|
| 38 |
|
| 39 |
-
### `import_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 40 |
|
| 41 |
```python
|
| 42 |
import_server(file: Path, server_object: str | None = None) -> Any
|
|
@@ -53,7 +53,7 @@ Import a MCP server from a file.
|
|
| 53 |
- The server object
|
| 54 |
|
| 55 |
|
| 56 |
-
### `run_with_uv` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 57 |
|
| 58 |
```python
|
| 59 |
run_with_uv(server_spec: str, python_version: str | None = None, with_packages: list[str] | None = None, with_requirements: Path | None = None, project: Path | None = None, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, show_banner: bool = True) -> None
|
|
@@ -76,7 +76,7 @@ Run a MCP server using uv run subprocess.
|
|
| 76 |
- `show_banner`: Whether to show the server banner
|
| 77 |
|
| 78 |
|
| 79 |
-
### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 80 |
|
| 81 |
```python
|
| 82 |
create_client_server(url: str) -> Any
|
|
@@ -92,7 +92,7 @@ Create a FastMCP server from a client URL.
|
|
| 92 |
- A FastMCP server instance
|
| 93 |
|
| 94 |
|
| 95 |
-
### `create_mcp_config_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 96 |
|
| 97 |
```python
|
| 98 |
create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]
|
|
@@ -102,7 +102,7 @@ create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]
|
|
| 102 |
Create a FastMCP server from a MCPConfig.
|
| 103 |
|
| 104 |
|
| 105 |
-
### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 106 |
|
| 107 |
```python
|
| 108 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
@@ -120,7 +120,7 @@ Import a server with optional command line arguments.
|
|
| 120 |
- The imported server object
|
| 121 |
|
| 122 |
|
| 123 |
-
### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 124 |
|
| 125 |
```python
|
| 126 |
run_command(server_spec: str, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, server_args: list[str] | None = None, show_banner: bool = True, use_direct_import: bool = False) -> None
|
|
@@ -140,3 +140,9 @@ Run a MCP server or connect to a remote one.
|
|
| 140 |
- `show_banner`: Whether to show the server banner
|
| 141 |
- `use_direct_import`: Whether to use direct import instead of subprocess
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `is_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L24" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
is_url(path: str) -> bool
|
|
|
|
| 20 |
Check if a string is a URL.
|
| 21 |
|
| 22 |
|
| 23 |
+
### `parse_file_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L30" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
parse_file_path(server_spec: str) -> tuple[Path, str | None]
|
|
|
|
| 36 |
- Tuple of (file_path, server_object)
|
| 37 |
|
| 38 |
|
| 39 |
+
### `import_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L61" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
import_server(file: Path, server_object: str | None = None) -> Any
|
|
|
|
| 53 |
- The server object
|
| 54 |
|
| 55 |
|
| 56 |
+
### `run_with_uv` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L131" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 57 |
|
| 58 |
```python
|
| 59 |
run_with_uv(server_spec: str, python_version: str | None = None, with_packages: list[str] | None = None, with_requirements: Path | None = None, project: Path | None = None, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, show_banner: bool = True) -> None
|
|
|
|
| 76 |
- `show_banner`: Whether to show the server banner
|
| 77 |
|
| 78 |
|
| 79 |
+
### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L209" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 80 |
|
| 81 |
```python
|
| 82 |
create_client_server(url: str) -> Any
|
|
|
|
| 92 |
- A FastMCP server instance
|
| 93 |
|
| 94 |
|
| 95 |
+
### `create_mcp_config_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L229" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 96 |
|
| 97 |
```python
|
| 98 |
create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]
|
|
|
|
| 102 |
Create a FastMCP server from a MCPConfig.
|
| 103 |
|
| 104 |
|
| 105 |
+
### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L240" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 106 |
|
| 107 |
```python
|
| 108 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
|
|
| 120 |
- The imported server object
|
| 121 |
|
| 122 |
|
| 123 |
+
### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L264" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 124 |
|
| 125 |
```python
|
| 126 |
run_command(server_spec: str, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, server_args: list[str] | None = None, show_banner: bool = True, use_direct_import: bool = False) -> None
|
|
|
|
| 140 |
- `show_banner`: Whether to show the server banner
|
| 141 |
- `use_direct_import`: Whether to use direct import instead of subprocess
|
| 142 |
|
| 143 |
+
|
| 144 |
+
### `run_v1_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L329" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 145 |
+
|
| 146 |
+
```python
|
| 147 |
+
run_v1_server(server: FastMCP1x, host: str | None = None, port: int | None = None, transport: TransportType | None = None) -> None
|
| 148 |
+
```
|
docs/python-sdk/fastmcp-client-auth-oauth.mdx
CHANGED
|
@@ -7,30 +7,13 @@ sidebarTitle: oauth
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `default_cache_dir` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_cache_dir() -> Path
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `
|
| 17 |
-
|
| 18 |
-
```python
|
| 19 |
-
discover_oauth_metadata(server_base_url: str, httpx_kwargs: dict[str, Any] | None = None) -> OAuthMetadata | None
|
| 20 |
-
```
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
Discover OAuth metadata from the server using RFC 8414 well-known endpoint.
|
| 24 |
-
|
| 25 |
-
**Args:**
|
| 26 |
-
- `server_base_url`: Base URL of the OAuth server (e.g., "https\://example.com")
|
| 27 |
-
- `httpx_kwargs`: Additional kwargs for httpx client
|
| 28 |
-
|
| 29 |
-
**Returns:**
|
| 30 |
-
- OAuth metadata if found, None otherwise
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
### `check_if_auth_required` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L188" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
|
| 35 |
```python
|
| 36 |
check_if_auth_required(mcp_url: str, httpx_kwargs: dict[str, Any] | None = None) -> bool
|
|
@@ -43,32 +26,9 @@ Check if the MCP endpoint requires authentication by making a test request.
|
|
| 43 |
- True if auth appears to be required, False otherwise
|
| 44 |
|
| 45 |
|
| 46 |
-
### `OAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L218" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 47 |
-
|
| 48 |
-
```python
|
| 49 |
-
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) -> OAuthClientProvider
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
Create an OAuthClientProvider for an MCP server.
|
| 54 |
-
|
| 55 |
-
This is intended to be provided to the `auth` parameter of an
|
| 56 |
-
httpx.AsyncClient (or appropriate FastMCP client/transport instance)
|
| 57 |
-
|
| 58 |
-
**Args:**
|
| 59 |
-
- `mcp_url`: Full URL to the MCP endpoint (e.g. "http\://host/mcp/sse/")
|
| 60 |
-
- `scopes`: OAuth scopes to request. Can be a
|
| 61 |
-
- `client_name`: Name for this client during registration
|
| 62 |
-
- `token_storage_cache_dir`: Directory for FileTokenStorage
|
| 63 |
-
- `additional_client_metadata`: Extra fields for OAuthClientMetadata
|
| 64 |
-
|
| 65 |
-
**Returns:**
|
| 66 |
-
- OAuthClientProvider
|
| 67 |
-
|
| 68 |
-
|
| 69 |
## Classes
|
| 70 |
|
| 71 |
-
### `FileTokenStorage` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 72 |
|
| 73 |
|
| 74 |
File-based token storage implementation for OAuth credentials and tokens.
|
|
@@ -79,7 +39,7 @@ Each instance is tied to a specific server URL for proper token isolation.
|
|
| 79 |
|
| 80 |
**Methods:**
|
| 81 |
|
| 82 |
-
#### `get_base_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 83 |
|
| 84 |
```python
|
| 85 |
get_base_url(url: str) -> str
|
|
@@ -88,7 +48,7 @@ get_base_url(url: str) -> str
|
|
| 88 |
Extract the base URL (scheme + host) from a URL.
|
| 89 |
|
| 90 |
|
| 91 |
-
#### `get_cache_key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 92 |
|
| 93 |
```python
|
| 94 |
get_cache_key(self) -> str
|
|
@@ -97,7 +57,7 @@ get_cache_key(self) -> str
|
|
| 97 |
Generate a safe filesystem key from the server's base URL.
|
| 98 |
|
| 99 |
|
| 100 |
-
#### `get_tokens` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 101 |
|
| 102 |
```python
|
| 103 |
get_tokens(self) -> OAuthToken | None
|
|
@@ -106,7 +66,7 @@ get_tokens(self) -> OAuthToken | None
|
|
| 106 |
Load tokens from file storage.
|
| 107 |
|
| 108 |
|
| 109 |
-
#### `set_tokens` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 110 |
|
| 111 |
```python
|
| 112 |
set_tokens(self, tokens: OAuthToken) -> None
|
|
@@ -115,7 +75,7 @@ set_tokens(self, tokens: OAuthToken) -> None
|
|
| 115 |
Save tokens to file storage.
|
| 116 |
|
| 117 |
|
| 118 |
-
#### `get_client_info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 119 |
|
| 120 |
```python
|
| 121 |
get_client_info(self) -> OAuthClientInformationFull | None
|
|
@@ -124,7 +84,7 @@ get_client_info(self) -> OAuthClientInformationFull | None
|
|
| 124 |
Load client information from file storage.
|
| 125 |
|
| 126 |
|
| 127 |
-
#### `set_client_info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 128 |
|
| 129 |
```python
|
| 130 |
set_client_info(self, client_info: OAuthClientInformationFull) -> None
|
|
@@ -133,7 +93,7 @@ set_client_info(self, client_info: OAuthClientInformationFull) -> None
|
|
| 133 |
Save client information to file storage.
|
| 134 |
|
| 135 |
|
| 136 |
-
#### `clear` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 137 |
|
| 138 |
```python
|
| 139 |
clear(self) -> None
|
|
@@ -142,7 +102,7 @@ clear(self) -> None
|
|
| 142 |
Clear all cached data for this server.
|
| 143 |
|
| 144 |
|
| 145 |
-
#### `clear_all` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 146 |
|
| 147 |
```python
|
| 148 |
clear_all(cls, cache_dir: Path | None = None) -> None
|
|
@@ -150,3 +110,32 @@ clear_all(cls, cache_dir: Path | None = None) -> None
|
|
| 150 |
|
| 151 |
Clear all cached data for all servers.
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_cache_dir` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L34" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_cache_dir() -> Path
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `check_if_auth_required` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L152" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
```python
|
| 19 |
check_if_auth_required(mcp_url: str, httpx_kwargs: dict[str, Any] | None = None) -> bool
|
|
|
|
| 26 |
- True if auth appears to be required, False otherwise
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
## Classes
|
| 30 |
|
| 31 |
+
### `FileTokenStorage` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 32 |
|
| 33 |
|
| 34 |
File-based token storage implementation for OAuth credentials and tokens.
|
|
|
|
| 39 |
|
| 40 |
**Methods:**
|
| 41 |
|
| 42 |
+
#### `get_base_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L53" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 43 |
|
| 44 |
```python
|
| 45 |
get_base_url(url: str) -> str
|
|
|
|
| 48 |
Extract the base URL (scheme + host) from a URL.
|
| 49 |
|
| 50 |
|
| 51 |
+
#### `get_cache_key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L58" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 52 |
|
| 53 |
```python
|
| 54 |
get_cache_key(self) -> str
|
|
|
|
| 57 |
Generate a safe filesystem key from the server's base URL.
|
| 58 |
|
| 59 |
|
| 60 |
+
#### `get_tokens` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L73" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 61 |
|
| 62 |
```python
|
| 63 |
get_tokens(self) -> OAuthToken | None
|
|
|
|
| 66 |
Load tokens from file storage.
|
| 67 |
|
| 68 |
|
| 69 |
+
#### `set_tokens` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L90" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 70 |
|
| 71 |
```python
|
| 72 |
set_tokens(self, tokens: OAuthToken) -> None
|
|
|
|
| 75 |
Save tokens to file storage.
|
| 76 |
|
| 77 |
|
| 78 |
+
#### `get_client_info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L96" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 79 |
|
| 80 |
```python
|
| 81 |
get_client_info(self) -> OAuthClientInformationFull | None
|
|
|
|
| 84 |
Load client information from file storage.
|
| 85 |
|
| 86 |
|
| 87 |
+
#### `set_client_info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L124" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 88 |
|
| 89 |
```python
|
| 90 |
set_client_info(self, client_info: OAuthClientInformationFull) -> None
|
|
|
|
| 93 |
Save client information to file storage.
|
| 94 |
|
| 95 |
|
| 96 |
+
#### `clear` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L130" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 97 |
|
| 98 |
```python
|
| 99 |
clear(self) -> None
|
|
|
|
| 102 |
Clear all cached data for this server.
|
| 103 |
|
| 104 |
|
| 105 |
+
#### `clear_all` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L139" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 106 |
|
| 107 |
```python
|
| 108 |
clear_all(cls, cache_dir: Path | None = None) -> None
|
|
|
|
| 110 |
|
| 111 |
Clear all cached data for all servers.
|
| 112 |
|
| 113 |
+
|
| 114 |
+
### `OAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
OAuth client provider for MCP servers with browser-based authentication.
|
| 118 |
+
|
| 119 |
+
This class provides OAuth authentication for FastMCP clients by opening
|
| 120 |
+
a browser for user authorization and running a local callback server.
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
**Methods:**
|
| 124 |
+
|
| 125 |
+
#### `redirect_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L248" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 126 |
+
|
| 127 |
+
```python
|
| 128 |
+
redirect_handler(self, authorization_url: str) -> None
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Open browser for authorization.
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
#### `callback_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L253" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 135 |
+
|
| 136 |
+
```python
|
| 137 |
+
callback_handler(self) -> tuple[str, str | None]
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
Handle OAuth callback and return (auth_code, state).
|
| 141 |
+
|
docs/python-sdk/fastmcp-client-transports.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: transports
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `infer_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
infer_transport(transport: ClientTransport | FastMCP | FastMCP1Server | AnyUrl | Path | MCPConfig | dict[str, Any] | str) -> ClientTransport
|
|
@@ -57,13 +57,13 @@ transport = infer_transport(config)
|
|
| 57 |
|
| 58 |
## Classes
|
| 59 |
|
| 60 |
-
### `SessionKwargs` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 61 |
|
| 62 |
|
| 63 |
Keyword arguments for the MCP ClientSession constructor.
|
| 64 |
|
| 65 |
|
| 66 |
-
### `ClientTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 67 |
|
| 68 |
|
| 69 |
Abstract base class for different MCP client transport mechanisms.
|
|
@@ -74,7 +74,7 @@ to an MCP server, and providing a ClientSession within an async context.
|
|
| 74 |
|
| 75 |
**Methods:**
|
| 76 |
|
| 77 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 78 |
|
| 79 |
```python
|
| 80 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
|
@@ -93,7 +93,7 @@ within this context.
|
|
| 93 |
constructor (e.g., callbacks, timeouts).
|
| 94 |
|
| 95 |
|
| 96 |
-
#### `close` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 97 |
|
| 98 |
```python
|
| 99 |
close(self)
|
|
@@ -102,7 +102,7 @@ close(self)
|
|
| 102 |
Close the transport.
|
| 103 |
|
| 104 |
|
| 105 |
-
### `WSTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 106 |
|
| 107 |
|
| 108 |
Transport implementation that connects to an MCP server via WebSockets.
|
|
@@ -110,13 +110,13 @@ Transport implementation that connects to an MCP server via WebSockets.
|
|
| 110 |
|
| 111 |
**Methods:**
|
| 112 |
|
| 113 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 114 |
|
| 115 |
```python
|
| 116 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 117 |
```
|
| 118 |
|
| 119 |
-
### `SSETransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 120 |
|
| 121 |
|
| 122 |
Transport implementation that connects to an MCP server via Server-Sent Events.
|
|
@@ -124,13 +124,13 @@ Transport implementation that connects to an MCP server via Server-Sent Events.
|
|
| 124 |
|
| 125 |
**Methods:**
|
| 126 |
|
| 127 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 128 |
|
| 129 |
```python
|
| 130 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 131 |
```
|
| 132 |
|
| 133 |
-
### `StreamableHttpTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 134 |
|
| 135 |
|
| 136 |
Transport implementation that connects to an MCP server via Streamable HTTP Requests.
|
|
@@ -138,13 +138,13 @@ Transport implementation that connects to an MCP server via Streamable HTTP Requ
|
|
| 138 |
|
| 139 |
**Methods:**
|
| 140 |
|
| 141 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 142 |
|
| 143 |
```python
|
| 144 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 145 |
```
|
| 146 |
|
| 147 |
-
### `StdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 148 |
|
| 149 |
|
| 150 |
Base transport for connecting to an MCP server via subprocess with stdio.
|
|
@@ -155,61 +155,67 @@ transports like Python, Node, Uvx, etc.
|
|
| 155 |
|
| 156 |
**Methods:**
|
| 157 |
|
| 158 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 159 |
|
| 160 |
```python
|
| 161 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 162 |
```
|
| 163 |
|
| 164 |
-
#### `connect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 165 |
|
| 166 |
```python
|
| 167 |
connect(self, **session_kwargs: Unpack[SessionKwargs]) -> ClientSession | None
|
| 168 |
```
|
| 169 |
|
| 170 |
-
#### `disconnect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 171 |
|
| 172 |
```python
|
| 173 |
disconnect(self)
|
| 174 |
```
|
| 175 |
|
| 176 |
-
#### `close` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 177 |
|
| 178 |
```python
|
| 179 |
close(self)
|
| 180 |
```
|
| 181 |
|
| 182 |
-
### `PythonStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 183 |
|
| 184 |
|
| 185 |
Transport for running Python scripts.
|
| 186 |
|
| 187 |
|
| 188 |
-
### `FastMCPStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 189 |
|
| 190 |
|
| 191 |
Transport for running FastMCP servers using the FastMCP CLI.
|
| 192 |
|
| 193 |
|
| 194 |
-
### `NodeStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 195 |
|
| 196 |
|
| 197 |
Transport for running Node.js scripts.
|
| 198 |
|
| 199 |
|
| 200 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
|
| 203 |
Transport for running commands via the uvx tool.
|
| 204 |
|
| 205 |
|
| 206 |
-
### `NpxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 207 |
|
| 208 |
|
| 209 |
Transport for running commands via the npx tool.
|
| 210 |
|
| 211 |
|
| 212 |
-
### `FastMCPTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 213 |
|
| 214 |
|
| 215 |
In-memory transport for FastMCP servers.
|
|
@@ -222,13 +228,13 @@ tests or scenarios where client and server run in the same runtime.
|
|
| 222 |
|
| 223 |
**Methods:**
|
| 224 |
|
| 225 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 226 |
|
| 227 |
```python
|
| 228 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 229 |
```
|
| 230 |
|
| 231 |
-
### `MCPConfigTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 232 |
|
| 233 |
|
| 234 |
Transport for connecting to one or more MCP servers defined in an MCPConfig.
|
|
@@ -281,7 +287,7 @@ async with client:
|
|
| 281 |
|
| 282 |
**Methods:**
|
| 283 |
|
| 284 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 285 |
|
| 286 |
```python
|
| 287 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `infer_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L903" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
infer_transport(transport: ClientTransport | FastMCP | FastMCP1Server | AnyUrl | Path | MCPConfig | dict[str, Any] | str) -> ClientTransport
|
|
|
|
| 57 |
|
| 58 |
## Classes
|
| 59 |
|
| 60 |
+
### `SessionKwargs` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L58" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 61 |
|
| 62 |
|
| 63 |
Keyword arguments for the MCP ClientSession constructor.
|
| 64 |
|
| 65 |
|
| 66 |
+
### `ClientTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L70" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 67 |
|
| 68 |
|
| 69 |
Abstract base class for different MCP client transport mechanisms.
|
|
|
|
| 74 |
|
| 75 |
**Methods:**
|
| 76 |
|
| 77 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L81" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 78 |
|
| 79 |
```python
|
| 80 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
|
|
|
| 93 |
constructor (e.g., callbacks, timeouts).
|
| 94 |
|
| 95 |
|
| 96 |
+
#### `close` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L107" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 97 |
|
| 98 |
```python
|
| 99 |
close(self)
|
|
|
|
| 102 |
Close the transport.
|
| 103 |
|
| 104 |
|
| 105 |
+
### `WSTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L116" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 106 |
|
| 107 |
|
| 108 |
Transport implementation that connects to an MCP server via WebSockets.
|
|
|
|
| 110 |
|
| 111 |
**Methods:**
|
| 112 |
|
| 113 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 114 |
|
| 115 |
```python
|
| 116 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 117 |
```
|
| 118 |
|
| 119 |
+
### `SSETransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L155" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 120 |
|
| 121 |
|
| 122 |
Transport implementation that connects to an MCP server via Server-Sent Events.
|
|
|
|
| 124 |
|
| 125 |
**Methods:**
|
| 126 |
|
| 127 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L191" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
|
| 129 |
```python
|
| 130 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 131 |
```
|
| 132 |
|
| 133 |
+
### `StreamableHttpTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L227" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 134 |
|
| 135 |
|
| 136 |
Transport implementation that connects to an MCP server via Streamable HTTP Requests.
|
|
|
|
| 138 |
|
| 139 |
**Methods:**
|
| 140 |
|
| 141 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L263" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 142 |
|
| 143 |
```python
|
| 144 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 145 |
```
|
| 146 |
|
| 147 |
+
### `StdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L300" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 148 |
|
| 149 |
|
| 150 |
Base transport for connecting to an MCP server via subprocess with stdio.
|
|
|
|
| 155 |
|
| 156 |
**Methods:**
|
| 157 |
|
| 158 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L343" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 159 |
|
| 160 |
```python
|
| 161 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 162 |
```
|
| 163 |
|
| 164 |
+
#### `connect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L356" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 165 |
|
| 166 |
```python
|
| 167 |
connect(self, **session_kwargs: Unpack[SessionKwargs]) -> ClientSession | None
|
| 168 |
```
|
| 169 |
|
| 170 |
+
#### `disconnect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L407" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 171 |
|
| 172 |
```python
|
| 173 |
disconnect(self)
|
| 174 |
```
|
| 175 |
|
| 176 |
+
#### `close` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L422" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 177 |
|
| 178 |
```python
|
| 179 |
close(self)
|
| 180 |
```
|
| 181 |
|
| 182 |
+
### `PythonStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L431" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 183 |
|
| 184 |
|
| 185 |
Transport for running Python scripts.
|
| 186 |
|
| 187 |
|
| 188 |
+
### `FastMCPStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L477" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 189 |
|
| 190 |
|
| 191 |
Transport for running FastMCP servers using the FastMCP CLI.
|
| 192 |
|
| 193 |
|
| 194 |
+
### `NodeStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L504" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 195 |
|
| 196 |
|
| 197 |
Transport for running Node.js scripts.
|
| 198 |
|
| 199 |
|
| 200 |
+
### `UvStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L546" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
Transport for running commands via the uv tool.
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
### `UvxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L603" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 207 |
|
| 208 |
|
| 209 |
Transport for running commands via the uvx tool.
|
| 210 |
|
| 211 |
|
| 212 |
+
### `NpxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L667" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 213 |
|
| 214 |
|
| 215 |
Transport for running commands via the npx tool.
|
| 216 |
|
| 217 |
|
| 218 |
+
### `FastMCPTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L729" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 219 |
|
| 220 |
|
| 221 |
In-memory transport for FastMCP servers.
|
|
|
|
| 228 |
|
| 229 |
**Methods:**
|
| 230 |
|
| 231 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L748" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 232 |
|
| 233 |
```python
|
| 234 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 235 |
```
|
| 236 |
|
| 237 |
+
### `MCPConfigTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L783" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 238 |
|
| 239 |
|
| 240 |
Transport for connecting to one or more MCP servers defined in an MCPConfig.
|
|
|
|
| 287 |
|
| 288 |
**Methods:**
|
| 289 |
|
| 290 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L855" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 291 |
|
| 292 |
```python
|
| 293 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
docs/python-sdk/fastmcp-prompts-prompt.mdx
CHANGED
|
@@ -57,10 +57,10 @@ to_mcp_prompt(self, **overrides: Any) -> MCPPrompt
|
|
| 57 |
Convert the prompt to an MCP prompt.
|
| 58 |
|
| 59 |
|
| 60 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 61 |
|
| 62 |
```python
|
| 63 |
-
from_function(fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
| 64 |
```
|
| 65 |
|
| 66 |
Create a Prompt from a function.
|
|
@@ -72,7 +72,7 @@ The function can return:
|
|
| 72 |
- A sequence of any of the above
|
| 73 |
|
| 74 |
|
| 75 |
-
#### `render` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 76 |
|
| 77 |
```python
|
| 78 |
render(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]
|
|
@@ -81,7 +81,7 @@ render(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]
|
|
| 81 |
Render the prompt with arguments.
|
| 82 |
|
| 83 |
|
| 84 |
-
### `FunctionPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 85 |
|
| 86 |
|
| 87 |
A prompt that is a function.
|
|
@@ -89,10 +89,10 @@ A prompt that is a function.
|
|
| 89 |
|
| 90 |
**Methods:**
|
| 91 |
|
| 92 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 93 |
|
| 94 |
```python
|
| 95 |
-
from_function(cls, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
| 96 |
```
|
| 97 |
|
| 98 |
Create a Prompt from a function.
|
|
@@ -104,7 +104,7 @@ The function can return:
|
|
| 104 |
- A sequence of any of the above
|
| 105 |
|
| 106 |
|
| 107 |
-
#### `render` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 108 |
|
| 109 |
```python
|
| 110 |
render(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]
|
|
|
|
| 57 |
Convert the prompt to an MCP prompt.
|
| 58 |
|
| 59 |
|
| 60 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L113" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 61 |
|
| 62 |
```python
|
| 63 |
+
from_function(fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None, meta: dict[str, Any] | None = None) -> FunctionPrompt
|
| 64 |
```
|
| 65 |
|
| 66 |
Create a Prompt from a function.
|
|
|
|
| 72 |
- A sequence of any of the above
|
| 73 |
|
| 74 |
|
| 75 |
+
#### `render` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L141" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 76 |
|
| 77 |
```python
|
| 78 |
render(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]
|
|
|
|
| 81 |
Render the prompt with arguments.
|
| 82 |
|
| 83 |
|
| 84 |
+
### `FunctionPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L149" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 85 |
|
| 86 |
|
| 87 |
A prompt that is a function.
|
|
|
|
| 89 |
|
| 90 |
**Methods:**
|
| 91 |
|
| 92 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L155" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 93 |
|
| 94 |
```python
|
| 95 |
+
from_function(cls, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None, meta: dict[str, Any] | None = None) -> FunctionPrompt
|
| 96 |
```
|
| 97 |
|
| 98 |
Create a Prompt from a function.
|
|
|
|
| 104 |
- A sequence of any of the above
|
| 105 |
|
| 106 |
|
| 107 |
+
#### `render` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L315" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 108 |
|
| 109 |
```python
|
| 110 |
render(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]
|
docs/python-sdk/fastmcp-resources-resource.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Base classes and interfaces for FastMCP resources.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `Resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 14 |
|
| 15 |
|
| 16 |
Base class for all resources.
|
|
@@ -18,25 +18,25 @@ Base class for all resources.
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
-
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 22 |
|
| 23 |
```python
|
| 24 |
enable(self) -> None
|
| 25 |
```
|
| 26 |
|
| 27 |
-
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 28 |
|
| 29 |
```python
|
| 30 |
disable(self) -> None
|
| 31 |
```
|
| 32 |
|
| 33 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 34 |
|
| 35 |
```python
|
| 36 |
-
from_function(fn: Callable[..., Any], uri: str | AnyUrl, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
| 37 |
```
|
| 38 |
|
| 39 |
-
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 40 |
|
| 41 |
```python
|
| 42 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
@@ -45,7 +45,7 @@ set_default_mime_type(cls, mime_type: str | None) -> str
|
|
| 45 |
Set default MIME type if not provided.
|
| 46 |
|
| 47 |
|
| 48 |
-
#### `set_default_name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 49 |
|
| 50 |
```python
|
| 51 |
set_default_name(self) -> Self
|
|
@@ -54,7 +54,7 @@ set_default_name(self) -> Self
|
|
| 54 |
Set default name from URI if not provided.
|
| 55 |
|
| 56 |
|
| 57 |
-
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 58 |
|
| 59 |
```python
|
| 60 |
read(self) -> str | bytes
|
|
@@ -63,7 +63,7 @@ read(self) -> str | bytes
|
|
| 63 |
Read the resource content.
|
| 64 |
|
| 65 |
|
| 66 |
-
#### `to_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 67 |
|
| 68 |
```python
|
| 69 |
to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
@@ -72,7 +72,7 @@ to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
| 72 |
Convert the resource to an MCPResource.
|
| 73 |
|
| 74 |
|
| 75 |
-
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 76 |
|
| 77 |
```python
|
| 78 |
key(self) -> str
|
|
@@ -84,7 +84,7 @@ keys having a certain value, as the same tool loaded from different
|
|
| 84 |
hierarchies of servers may have different keys.
|
| 85 |
|
| 86 |
|
| 87 |
-
### `FunctionResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 88 |
|
| 89 |
|
| 90 |
A resource that defers data loading by wrapping a function.
|
|
@@ -101,16 +101,16 @@ The function can return:
|
|
| 101 |
|
| 102 |
**Methods:**
|
| 103 |
|
| 104 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 105 |
|
| 106 |
```python
|
| 107 |
-
from_function(cls, fn: Callable[..., Any], uri: str | AnyUrl, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
| 108 |
```
|
| 109 |
|
| 110 |
Create a FunctionResource from a function.
|
| 111 |
|
| 112 |
|
| 113 |
-
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 114 |
|
| 115 |
```python
|
| 116 |
read(self) -> str | bytes
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `Resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L33" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Base class for all resources.
|
|
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
+
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L52" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 22 |
|
| 23 |
```python
|
| 24 |
enable(self) -> None
|
| 25 |
```
|
| 26 |
|
| 27 |
+
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
|
| 29 |
```python
|
| 30 |
disable(self) -> None
|
| 31 |
```
|
| 32 |
|
| 33 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L69" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
|
| 35 |
```python
|
| 36 |
+
from_function(fn: Callable[..., Any], uri: str | AnyUrl, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None, annotations: Annotations | None = None, meta: dict[str, Any] | None = None) -> FunctionResource
|
| 37 |
```
|
| 38 |
|
| 39 |
+
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L96" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
|
|
| 45 |
Set default MIME type if not provided.
|
| 46 |
|
| 47 |
|
| 48 |
+
#### `set_default_name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L103" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
|
| 50 |
```python
|
| 51 |
set_default_name(self) -> Self
|
|
|
|
| 54 |
Set default name from URI if not provided.
|
| 55 |
|
| 56 |
|
| 57 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L114" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 58 |
|
| 59 |
```python
|
| 60 |
read(self) -> str | bytes
|
|
|
|
| 63 |
Read the resource content.
|
| 64 |
|
| 65 |
|
| 66 |
+
#### `to_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L118" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 67 |
|
| 68 |
```python
|
| 69 |
to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
|
|
| 72 |
Convert the resource to an MCPResource.
|
| 73 |
|
| 74 |
|
| 75 |
+
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 76 |
|
| 77 |
```python
|
| 78 |
key(self) -> str
|
|
|
|
| 84 |
hierarchies of servers may have different keys.
|
| 85 |
|
| 86 |
|
| 87 |
+
### `FunctionResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L150" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 88 |
|
| 89 |
|
| 90 |
A resource that defers data loading by wrapping a function.
|
|
|
|
| 101 |
|
| 102 |
**Methods:**
|
| 103 |
|
| 104 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L166" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 105 |
|
| 106 |
```python
|
| 107 |
+
from_function(cls, fn: Callable[..., Any], uri: str | AnyUrl, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None, annotations: Annotations | None = None, meta: dict[str, Any] | None = None) -> FunctionResource
|
| 108 |
```
|
| 109 |
|
| 110 |
Create a FunctionResource from a function.
|
| 111 |
|
| 112 |
|
| 113 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L195" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 114 |
|
| 115 |
```python
|
| 116 |
read(self) -> str | bytes
|
docs/python-sdk/fastmcp-resources-template.mdx
CHANGED
|
@@ -10,13 +10,13 @@ Resource template functionality.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `build_regex` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
build_regex(template: str) -> re.Pattern
|
| 17 |
```
|
| 18 |
|
| 19 |
-
### `match_uri_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 20 |
|
| 21 |
```python
|
| 22 |
match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None
|
|
@@ -24,7 +24,7 @@ match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None
|
|
| 24 |
|
| 25 |
## Classes
|
| 26 |
|
| 27 |
-
### `ResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 28 |
|
| 29 |
|
| 30 |
A template for dynamically creating resources.
|
|
@@ -32,25 +32,25 @@ A template for dynamically creating resources.
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
-
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 36 |
|
| 37 |
```python
|
| 38 |
enable(self) -> None
|
| 39 |
```
|
| 40 |
|
| 41 |
-
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 42 |
|
| 43 |
```python
|
| 44 |
disable(self) -> None
|
| 45 |
```
|
| 46 |
|
| 47 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 48 |
|
| 49 |
```python
|
| 50 |
-
from_function(fn: Callable[..., Any], uri_template: str, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
| 51 |
```
|
| 52 |
|
| 53 |
-
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 54 |
|
| 55 |
```python
|
| 56 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
@@ -59,7 +59,7 @@ set_default_mime_type(cls, mime_type: str | None) -> str
|
|
| 59 |
Set default MIME type if not provided.
|
| 60 |
|
| 61 |
|
| 62 |
-
#### `matches` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 63 |
|
| 64 |
```python
|
| 65 |
matches(self, uri: str) -> dict[str, Any] | None
|
|
@@ -68,7 +68,7 @@ matches(self, uri: str) -> dict[str, Any] | None
|
|
| 68 |
Check if URI matches template and extract parameters.
|
| 69 |
|
| 70 |
|
| 71 |
-
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 72 |
|
| 73 |
```python
|
| 74 |
read(self, arguments: dict[str, Any]) -> str | bytes
|
|
@@ -77,7 +77,7 @@ read(self, arguments: dict[str, Any]) -> str | bytes
|
|
| 77 |
Read the resource content.
|
| 78 |
|
| 79 |
|
| 80 |
-
#### `create_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 81 |
|
| 82 |
```python
|
| 83 |
create_resource(self, uri: str, params: dict[str, Any]) -> Resource
|
|
@@ -86,7 +86,7 @@ create_resource(self, uri: str, params: dict[str, Any]) -> Resource
|
|
| 86 |
Create a resource from the template with the given parameters.
|
| 87 |
|
| 88 |
|
| 89 |
-
#### `to_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 90 |
|
| 91 |
```python
|
| 92 |
to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
@@ -95,7 +95,7 @@ to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
| 95 |
Convert the resource template to an MCPResourceTemplate.
|
| 96 |
|
| 97 |
|
| 98 |
-
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 99 |
|
| 100 |
```python
|
| 101 |
from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
@@ -104,7 +104,7 @@ from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
| 104 |
Creates a FastMCP ResourceTemplate from a raw MCP ResourceTemplate object.
|
| 105 |
|
| 106 |
|
| 107 |
-
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 108 |
|
| 109 |
```python
|
| 110 |
key(self) -> str
|
|
@@ -116,7 +116,7 @@ keys having a certain value, as the same tool loaded from different
|
|
| 116 |
hierarchies of servers may have different keys.
|
| 117 |
|
| 118 |
|
| 119 |
-
### `FunctionResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 120 |
|
| 121 |
|
| 122 |
A template for dynamically creating resources.
|
|
@@ -124,7 +124,7 @@ A template for dynamically creating resources.
|
|
| 124 |
|
| 125 |
**Methods:**
|
| 126 |
|
| 127 |
-
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 128 |
|
| 129 |
```python
|
| 130 |
read(self, arguments: dict[str, Any]) -> str | bytes
|
|
@@ -133,10 +133,10 @@ read(self, arguments: dict[str, Any]) -> str | bytes
|
|
| 133 |
Read the resource content.
|
| 134 |
|
| 135 |
|
| 136 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 137 |
|
| 138 |
```python
|
| 139 |
-
from_function(cls, fn: Callable[..., Any], uri_template: str, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
| 140 |
```
|
| 141 |
|
| 142 |
Create a template from a function.
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `build_regex` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L29" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
build_regex(template: str) -> re.Pattern
|
| 17 |
```
|
| 18 |
|
| 19 |
+
### `match_uri_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L45" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
|
| 21 |
```python
|
| 22 |
match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None
|
|
|
|
| 24 |
|
| 25 |
## Classes
|
| 26 |
|
| 27 |
+
### `ResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L53" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
|
| 29 |
|
| 30 |
A template for dynamically creating resources.
|
|
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
+
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 36 |
|
| 37 |
```python
|
| 38 |
enable(self) -> None
|
| 39 |
```
|
| 40 |
|
| 41 |
+
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L80" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 42 |
|
| 43 |
```python
|
| 44 |
disable(self) -> None
|
| 45 |
```
|
| 46 |
|
| 47 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L89" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 48 |
|
| 49 |
```python
|
| 50 |
+
from_function(fn: Callable[..., Any], uri_template: str, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None, annotations: Annotations | None = None, meta: dict[str, Any] | None = None) -> FunctionResourceTemplate
|
| 51 |
```
|
| 52 |
|
| 53 |
+
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L116" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 54 |
|
| 55 |
```python
|
| 56 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
|
|
| 59 |
Set default MIME type if not provided.
|
| 60 |
|
| 61 |
|
| 62 |
+
#### `matches` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L122" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 63 |
|
| 64 |
```python
|
| 65 |
matches(self, uri: str) -> dict[str, Any] | None
|
|
|
|
| 68 |
Check if URI matches template and extract parameters.
|
| 69 |
|
| 70 |
|
| 71 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L126" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 72 |
|
| 73 |
```python
|
| 74 |
read(self, arguments: dict[str, Any]) -> str | bytes
|
|
|
|
| 77 |
Read the resource content.
|
| 78 |
|
| 79 |
|
| 80 |
+
#### `create_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L132" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 81 |
|
| 82 |
```python
|
| 83 |
create_resource(self, uri: str, params: dict[str, Any]) -> Resource
|
|
|
|
| 86 |
Create a resource from the template with the given parameters.
|
| 87 |
|
| 88 |
|
| 89 |
+
#### `to_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L150" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 90 |
|
| 91 |
```python
|
| 92 |
to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
|
|
| 95 |
Convert the resource template to an MCPResourceTemplate.
|
| 96 |
|
| 97 |
|
| 98 |
+
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L169" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 99 |
|
| 100 |
```python
|
| 101 |
from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
|
|
| 104 |
Creates a FastMCP ResourceTemplate from a raw MCP ResourceTemplate object.
|
| 105 |
|
| 106 |
|
| 107 |
+
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 108 |
|
| 109 |
```python
|
| 110 |
key(self) -> str
|
|
|
|
| 116 |
hierarchies of servers may have different keys.
|
| 117 |
|
| 118 |
|
| 119 |
+
### `FunctionResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L192" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 120 |
|
| 121 |
|
| 122 |
A template for dynamically creating resources.
|
|
|
|
| 124 |
|
| 125 |
**Methods:**
|
| 126 |
|
| 127 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L197" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
|
| 129 |
```python
|
| 130 |
read(self, arguments: dict[str, Any]) -> str | bytes
|
|
|
|
| 133 |
Read the resource content.
|
| 134 |
|
| 135 |
|
| 136 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L213" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 137 |
|
| 138 |
```python
|
| 139 |
+
from_function(cls, fn: Callable[..., Any], uri_template: str, name: str | None = None, title: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None, annotations: Annotations | None = None, meta: dict[str, Any] | None = None) -> FunctionResourceTemplate
|
| 140 |
```
|
| 141 |
|
| 142 |
Create a template from a function.
|
docs/python-sdk/fastmcp-server-auth-auth.mdx
CHANGED
|
@@ -7,11 +7,86 @@ sidebarTitle: auth
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
**Methods:**
|
| 13 |
|
| 14 |
-
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
```python
|
| 17 |
verify_token(self, token: str) -> AccessToken | None
|
|
@@ -28,3 +103,22 @@ to our existing load_access_token method.
|
|
| 28 |
**Returns:**
|
| 29 |
- AccessToken object if valid, None if invalid or expired
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `AuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L25" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Base class for all FastMCP authentication providers.
|
| 14 |
+
|
| 15 |
+
This class provides a unified interface for all authentication providers,
|
| 16 |
+
whether they are simple token verifiers or full OAuth authorization servers.
|
| 17 |
+
All providers must be able to verify tokens and can optionally provide
|
| 18 |
+
custom authentication routes.
|
| 19 |
+
|
| 20 |
|
| 21 |
**Methods:**
|
| 22 |
|
| 23 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
verify_token(self, token: str) -> AccessToken | None
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Verify a bearer token and return access info if valid.
|
| 30 |
+
|
| 31 |
+
All auth providers must implement token verification.
|
| 32 |
+
|
| 33 |
+
**Args:**
|
| 34 |
+
- `token`: The token string to validate
|
| 35 |
+
|
| 36 |
+
**Returns:**
|
| 37 |
+
- AccessToken object if valid, None if invalid or expired
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
#### `customize_auth_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L51" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
customize_auth_routes(self, routes: list[Route]) -> list[Route]
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
Customize authentication routes after standard creation.
|
| 47 |
+
|
| 48 |
+
This method allows providers to modify or add to the standard OAuth routes.
|
| 49 |
+
The default implementation returns the routes unchanged.
|
| 50 |
+
|
| 51 |
+
**Args:**
|
| 52 |
+
- `routes`: List of standard routes (may be empty for token-only providers)
|
| 53 |
+
|
| 54 |
+
**Returns:**
|
| 55 |
+
- List of routes (potentially modified or extended)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
### `TokenVerifier` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L66" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Base class for token verifiers (Resource Servers).
|
| 62 |
+
|
| 63 |
+
This class provides token verification capability without OAuth server functionality.
|
| 64 |
+
Token verifiers typically don't provide authentication routes by default.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
**Methods:**
|
| 68 |
+
|
| 69 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L97" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
verify_token(self, token: str) -> AccessToken | None
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Verify a bearer token and return access info if valid.
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
### `OAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L102" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
OAuth Authorization Server provider.
|
| 82 |
+
|
| 83 |
+
This class provides full OAuth server functionality including client registration,
|
| 84 |
+
authorization flows, token issuance, and token verification.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
**Methods:**
|
| 88 |
+
|
| 89 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L169" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 90 |
|
| 91 |
```python
|
| 92 |
verify_token(self, token: str) -> AccessToken | None
|
|
|
|
| 103 |
**Returns:**
|
| 104 |
- AccessToken object if valid, None if invalid or expired
|
| 105 |
|
| 106 |
+
|
| 107 |
+
#### `customize_auth_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L184" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
customize_auth_routes(self, routes: list[Route]) -> list[Route]
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
Customize OAuth authentication routes after standard creation.
|
| 114 |
+
|
| 115 |
+
This method allows providers to modify the standard OAuth routes
|
| 116 |
+
returned by create_auth_routes. The default implementation returns
|
| 117 |
+
the routes unchanged.
|
| 118 |
+
|
| 119 |
+
**Args:**
|
| 120 |
+
- `routes`: List of standard OAuth routes from create_auth_routes
|
| 121 |
+
|
| 122 |
+
**Returns:**
|
| 123 |
+
- List of routes (potentially modified)
|
| 124 |
+
|
docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx
CHANGED
|
@@ -5,148 +5,9 @@ sidebarTitle: bearer
|
|
| 5 |
|
| 6 |
# `fastmcp.server.auth.providers.bearer`
|
| 7 |
|
| 8 |
-
## Classes
|
| 9 |
|
| 10 |
-
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
JSON Web Key data structure.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
### `JWKSData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L44" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
JSON Web Key Set data structure.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
### `RSAKeyPair` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L51" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 23 |
-
|
| 24 |
-
**Methods:**
|
| 25 |
-
|
| 26 |
-
#### `generate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L56" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 27 |
-
|
| 28 |
-
```python
|
| 29 |
-
generate(cls) -> 'RSAKeyPair'
|
| 30 |
-
```
|
| 31 |
-
|
| 32 |
-
Generate an RSA key pair for testing.
|
| 33 |
-
|
| 34 |
-
**Returns:**
|
| 35 |
-
- (private_key_pem, public_key_pem)
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
#### `create_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L90" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 39 |
-
|
| 40 |
-
```python
|
| 41 |
-
create_token(self, subject: str = 'fastmcp-user', issuer: str = 'https://fastmcp.example.com', audience: str | list[str] | None = None, scopes: list[str] | None = None, expires_in_seconds: int = 3600, additional_claims: dict[str, Any] | None = None, kid: str | None = None) -> str
|
| 42 |
-
```
|
| 43 |
-
|
| 44 |
-
Generate a test JWT token for testing purposes.
|
| 45 |
-
|
| 46 |
-
**Args:**
|
| 47 |
-
- `private_key_pem`: RSA private key in PEM format
|
| 48 |
-
- `subject`: Subject claim (usually user ID)
|
| 49 |
-
- `issuer`: Issuer claim
|
| 50 |
-
- `audience`: Audience claim - can be a string or list of strings (optional)
|
| 51 |
-
- `scopes`: List of scopes to include
|
| 52 |
-
- `expires_in_seconds`: Token expiration time in seconds
|
| 53 |
-
- `additional_claims`: Any additional claims to include
|
| 54 |
-
- `kid`: Key ID for JWKS lookup (optional)
|
| 55 |
-
|
| 56 |
-
**Returns:**
|
| 57 |
-
- Signed JWT token string
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
### `BearerAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L152" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
Simple JWT Bearer Token validator for hosted MCP servers.
|
| 64 |
-
Uses RS256 asymmetric encryption by default but supports all JWA algorithms. Supports either static public key
|
| 65 |
-
or JWKS URI for key rotation.
|
| 66 |
-
|
| 67 |
-
Note that this provider DOES NOT permit client registration or revocation, or any OAuth flows.
|
| 68 |
-
It is intended to be used with a control plane that manages clients and tokens.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
**Methods:**
|
| 72 |
-
|
| 73 |
-
#### `load_access_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L313" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 74 |
-
|
| 75 |
-
```python
|
| 76 |
-
load_access_token(self, token: str) -> AccessToken | None
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
Validates the provided JWT bearer token.
|
| 80 |
-
|
| 81 |
-
**Args:**
|
| 82 |
-
- `token`: The JWT token string to validate
|
| 83 |
-
|
| 84 |
-
**Returns:**
|
| 85 |
-
- AccessToken object if valid, None if invalid or expired
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L419" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 89 |
-
|
| 90 |
-
```python
|
| 91 |
-
verify_token(self, token: str) -> AccessToken | None
|
| 92 |
-
```
|
| 93 |
-
|
| 94 |
-
Verify a bearer token and return access info if valid.
|
| 95 |
-
|
| 96 |
-
This method implements the TokenVerifier protocol by delegating
|
| 97 |
-
to our existing load_access_token method.
|
| 98 |
-
|
| 99 |
-
**Args:**
|
| 100 |
-
- `token`: The JWT token string to validate
|
| 101 |
-
|
| 102 |
-
**Returns:**
|
| 103 |
-
- AccessToken object if valid, None if invalid or expired
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
#### `get_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L435" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 107 |
-
|
| 108 |
-
```python
|
| 109 |
-
get_client(self, client_id: str) -> OAuthClientInformationFull | None
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
#### `register_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L438" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 113 |
-
|
| 114 |
-
```python
|
| 115 |
-
register_client(self, client_info: OAuthClientInformationFull) -> None
|
| 116 |
-
```
|
| 117 |
-
|
| 118 |
-
#### `authorize` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L441" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 119 |
-
|
| 120 |
-
```python
|
| 121 |
-
authorize(self, client: OAuthClientInformationFull, params: AuthorizationParams) -> str
|
| 122 |
-
```
|
| 123 |
-
|
| 124 |
-
#### `load_authorization_code` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L446" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 125 |
-
|
| 126 |
-
```python
|
| 127 |
-
load_authorization_code(self, client: OAuthClientInformationFull, authorization_code: str) -> AuthorizationCode | None
|
| 128 |
-
```
|
| 129 |
-
|
| 130 |
-
#### `exchange_authorization_code` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L451" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 131 |
-
|
| 132 |
-
```python
|
| 133 |
-
exchange_authorization_code(self, client: OAuthClientInformationFull, authorization_code: AuthorizationCode) -> OAuthToken
|
| 134 |
-
```
|
| 135 |
-
|
| 136 |
-
#### `load_refresh_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L456" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 137 |
-
|
| 138 |
-
```python
|
| 139 |
-
load_refresh_token(self, client: OAuthClientInformationFull, refresh_token: str) -> RefreshToken | None
|
| 140 |
-
```
|
| 141 |
-
|
| 142 |
-
#### `exchange_refresh_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L461" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 143 |
-
|
| 144 |
-
```python
|
| 145 |
-
exchange_refresh_token(self, client: OAuthClientInformationFull, refresh_token: RefreshToken, scopes: list[str]) -> OAuthToken
|
| 146 |
-
```
|
| 147 |
-
|
| 148 |
-
#### `revoke_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L469" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 149 |
-
|
| 150 |
-
```python
|
| 151 |
-
revoke_token(self, token: AccessToken | RefreshToken) -> None
|
| 152 |
-
```
|
|
|
|
| 5 |
|
| 6 |
# `fastmcp.server.auth.providers.bearer`
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
+
Backwards compatibility shim for BearerAuthProvider.
|
| 10 |
|
| 11 |
+
The BearerAuthProvider class has been moved to fastmcp.server.auth.providers.jwt.JWTVerifier
|
| 12 |
+
for better organization. This module provides a backwards-compatible import.
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx
CHANGED
|
@@ -16,19 +16,19 @@ It simulates the OAuth 2.1 flow locally without external calls.
|
|
| 16 |
|
| 17 |
**Methods:**
|
| 18 |
|
| 19 |
-
#### `get_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 20 |
|
| 21 |
```python
|
| 22 |
get_client(self, client_id: str) -> OAuthClientInformationFull | None
|
| 23 |
```
|
| 24 |
|
| 25 |
-
#### `register_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 26 |
|
| 27 |
```python
|
| 28 |
register_client(self, client_info: OAuthClientInformationFull) -> None
|
| 29 |
```
|
| 30 |
|
| 31 |
-
#### `authorize` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 32 |
|
| 33 |
```python
|
| 34 |
authorize(self, client: OAuthClientInformationFull, params: AuthorizationParams) -> str
|
|
@@ -38,37 +38,37 @@ Simulates user authorization and generates an authorization code.
|
|
| 38 |
Returns a redirect URI with the code and state.
|
| 39 |
|
| 40 |
|
| 41 |
-
#### `load_authorization_code` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 42 |
|
| 43 |
```python
|
| 44 |
load_authorization_code(self, client: OAuthClientInformationFull, authorization_code: str) -> AuthorizationCode | None
|
| 45 |
```
|
| 46 |
|
| 47 |
-
#### `exchange_authorization_code` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 48 |
|
| 49 |
```python
|
| 50 |
exchange_authorization_code(self, client: OAuthClientInformationFull, authorization_code: AuthorizationCode) -> OAuthToken
|
| 51 |
```
|
| 52 |
|
| 53 |
-
#### `load_refresh_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 54 |
|
| 55 |
```python
|
| 56 |
load_refresh_token(self, client: OAuthClientInformationFull, refresh_token: str) -> RefreshToken | None
|
| 57 |
```
|
| 58 |
|
| 59 |
-
#### `exchange_refresh_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 60 |
|
| 61 |
```python
|
| 62 |
exchange_refresh_token(self, client: OAuthClientInformationFull, refresh_token: RefreshToken, scopes: list[str]) -> OAuthToken
|
| 63 |
```
|
| 64 |
|
| 65 |
-
#### `load_access_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 66 |
|
| 67 |
```python
|
| 68 |
load_access_token(self, token: str) -> AccessToken | None
|
| 69 |
```
|
| 70 |
|
| 71 |
-
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 72 |
|
| 73 |
```python
|
| 74 |
verify_token(self, token: str) -> AccessToken | None
|
|
@@ -86,7 +86,7 @@ to our existing load_access_token method.
|
|
| 86 |
- AccessToken object if valid, None if invalid or expired
|
| 87 |
|
| 88 |
|
| 89 |
-
#### `revoke_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#
|
| 90 |
|
| 91 |
```python
|
| 92 |
revoke_token(self, token: AccessToken | RefreshToken) -> None
|
|
|
|
| 16 |
|
| 17 |
**Methods:**
|
| 18 |
|
| 19 |
+
#### `get_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L67" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
|
| 21 |
```python
|
| 22 |
get_client(self, client_id: str) -> OAuthClientInformationFull | None
|
| 23 |
```
|
| 24 |
|
| 25 |
+
#### `register_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L70" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 26 |
|
| 27 |
```python
|
| 28 |
register_client(self, client_info: OAuthClientInformationFull) -> None
|
| 29 |
```
|
| 30 |
|
| 31 |
+
#### `authorize` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L78" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 32 |
|
| 33 |
```python
|
| 34 |
authorize(self, client: OAuthClientInformationFull, params: AuthorizationParams) -> str
|
|
|
|
| 38 |
Returns a redirect URI with the code and state.
|
| 39 |
|
| 40 |
|
| 41 |
+
#### `load_authorization_code` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L131" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 42 |
|
| 43 |
```python
|
| 44 |
load_authorization_code(self, client: OAuthClientInformationFull, authorization_code: str) -> AuthorizationCode | None
|
| 45 |
```
|
| 46 |
|
| 47 |
+
#### `exchange_authorization_code` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L144" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 48 |
|
| 49 |
```python
|
| 50 |
exchange_authorization_code(self, client: OAuthClientInformationFull, authorization_code: AuthorizationCode) -> OAuthToken
|
| 51 |
```
|
| 52 |
|
| 53 |
+
#### `load_refresh_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L195" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 54 |
|
| 55 |
```python
|
| 56 |
load_refresh_token(self, client: OAuthClientInformationFull, refresh_token: str) -> RefreshToken | None
|
| 57 |
```
|
| 58 |
|
| 59 |
+
#### `exchange_refresh_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L210" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 60 |
|
| 61 |
```python
|
| 62 |
exchange_refresh_token(self, client: OAuthClientInformationFull, refresh_token: RefreshToken, scopes: list[str]) -> OAuthToken
|
| 63 |
```
|
| 64 |
|
| 65 |
+
#### `load_access_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L265" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 66 |
|
| 67 |
```python
|
| 68 |
load_access_token(self, token: str) -> AccessToken | None
|
| 69 |
```
|
| 70 |
|
| 71 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L276" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 72 |
|
| 73 |
```python
|
| 74 |
verify_token(self, token: str) -> AccessToken | None
|
|
|
|
| 86 |
- AccessToken object if valid, None if invalid or expired
|
| 87 |
|
| 88 |
|
| 89 |
+
#### `revoke_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L333" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 90 |
|
| 91 |
```python
|
| 92 |
revoke_token(self, token: AccessToken | RefreshToken) -> None
|
docs/python-sdk/fastmcp-server-auth-providers-jwt.mdx
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: jwt
|
| 3 |
+
sidebarTitle: jwt
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.providers.jwt`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
TokenVerifier implementations for FastMCP.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `JWKData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L27" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
JSON Web Key data structure.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
### `JWKSData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L40" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
JSON Web Key Set data structure.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
### `RSAKeyPair` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L47" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
RSA key pair for JWT testing.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
**Methods:**
|
| 32 |
+
|
| 33 |
+
#### `generate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
generate(cls) -> RSAKeyPair
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Generate an RSA key pair for testing.
|
| 40 |
+
|
| 41 |
+
**Returns:**
|
| 42 |
+
- Generated key pair
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#### `create_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L89" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
create_token(self, subject: str = 'fastmcp-user', issuer: str = 'https://fastmcp.example.com', audience: str | list[str] | None = None, scopes: list[str] | None = None, expires_in_seconds: int = 3600, additional_claims: dict[str, Any] | None = None, kid: str | None = None) -> str
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Generate a test JWT token for testing purposes.
|
| 52 |
+
|
| 53 |
+
**Args:**
|
| 54 |
+
- `subject`: Subject claim (usually user ID)
|
| 55 |
+
- `issuer`: Issuer claim
|
| 56 |
+
- `audience`: Audience claim - can be a string or list of strings (optional)
|
| 57 |
+
- `scopes`: List of scopes to include
|
| 58 |
+
- `expires_in_seconds`: Token expiration time in seconds
|
| 59 |
+
- `additional_claims`: Any additional claims to include
|
| 60 |
+
- `kid`: Key ID to include in header
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
### `JWTVerifierSettings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L144" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Settings for JWT token verification.
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
### `JWTVerifier` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L163" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
JWT token verifier using public key or JWKS.
|
| 73 |
+
|
| 74 |
+
This verifier validates JWT tokens signed by an external issuer. It's ideal for
|
| 75 |
+
scenarios where you have a centralized identity provider (like Auth0, Okta, or
|
| 76 |
+
your own OAuth server) that issues JWTs, and your FastMCP server acts as a
|
| 77 |
+
resource server validating those tokens.
|
| 78 |
+
|
| 79 |
+
Use this when:
|
| 80 |
+
- You have JWT tokens issued by an external service
|
| 81 |
+
- You want asymmetric key verification (public/private key pairs)
|
| 82 |
+
- You need JWKS support for automatic key rotation
|
| 83 |
+
- Your tokens contain standard OAuth scopes and claims
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
**Methods:**
|
| 87 |
+
|
| 88 |
+
#### `load_access_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L359" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
load_access_token(self, token: str) -> AccessToken | None
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
Validates the provided JWT bearer token.
|
| 95 |
+
|
| 96 |
+
**Args:**
|
| 97 |
+
- `token`: The JWT token string to validate
|
| 98 |
+
|
| 99 |
+
**Returns:**
|
| 100 |
+
- AccessToken object if valid, None if invalid or expired
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L460" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
verify_token(self, token: str) -> AccessToken | None
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
Verify a bearer token and return access info if valid.
|
| 110 |
+
|
| 111 |
+
This method implements the TokenVerifier protocol by delegating
|
| 112 |
+
to our existing load_access_token method.
|
| 113 |
+
|
| 114 |
+
**Args:**
|
| 115 |
+
- `token`: The JWT token string to validate
|
| 116 |
+
|
| 117 |
+
**Returns:**
|
| 118 |
+
- AccessToken object if valid, None if invalid or expired
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
### `StaticTokenVerifier` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L476" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
Simple static token verifier for testing and development.
|
| 125 |
+
|
| 126 |
+
This verifier validates tokens against a predefined dictionary of valid token
|
| 127 |
+
strings and their associated claims. When a token string matches a key in the
|
| 128 |
+
dictionary, the verifier returns the corresponding claims as if the token was
|
| 129 |
+
validated by a real authorization server.
|
| 130 |
+
|
| 131 |
+
Use this when:
|
| 132 |
+
- You're developing or testing locally without a real OAuth server
|
| 133 |
+
- You need predictable tokens for automated testing
|
| 134 |
+
- You want to simulate different users/scopes without complex setup
|
| 135 |
+
- You're prototyping and need simple API key-style authentication
|
| 136 |
+
|
| 137 |
+
WARNING: Never use this in production - tokens are stored in plain text!
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
**Methods:**
|
| 141 |
+
|
| 142 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L510" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 143 |
+
|
| 144 |
+
```python
|
| 145 |
+
verify_token(self, token: str) -> AccessToken | None
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
Verify token against static token dictionary.
|
| 149 |
+
|
docs/python-sdk/fastmcp-server-auth-providers-workos.mdx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: workos
|
| 3 |
+
sidebarTitle: workos
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.providers.workos`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `AuthKitProviderSettings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/workos.py#L21" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
### `AuthKitProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/workos.py#L34" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
WorkOS AuthKit metadata provider for DCR (Dynamic Client Registration).
|
| 16 |
+
|
| 17 |
+
This provider implements WorkOS AuthKit integration using metadata forwarding
|
| 18 |
+
instead of OAuth proxying. This is the recommended approach for WorkOS DCR
|
| 19 |
+
as it allows WorkOS to handle the OAuth flow directly while FastMCP acts
|
| 20 |
+
as a resource server.
|
| 21 |
+
|
| 22 |
+
IMPORTANT SETUP REQUIREMENTS:
|
| 23 |
+
|
| 24 |
+
1. Enable Dynamic Client Registration in WorkOS Dashboard:
|
| 25 |
+
- Go to Applications → Configuration
|
| 26 |
+
- Toggle "Dynamic Client Registration" to enabled
|
| 27 |
+
|
| 28 |
+
2. Configure your FastMCP server URL as a callback:
|
| 29 |
+
- Add your server URL to the Redirects tab in WorkOS dashboard
|
| 30 |
+
- Example: https://your-fastmcp-server.com/oauth2/callback
|
| 31 |
+
|
| 32 |
+
For detailed setup instructions, see:
|
| 33 |
+
https://workos.com/docs/authkit/mcp/integrating/token-verification
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
**Methods:**
|
| 37 |
+
|
| 38 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/workos.py#L114" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
verify_token(self, token: str) -> AccessToken | None
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Verify a WorkOS token using the configured token verifier.
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
#### `customize_auth_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/workos.py#L118" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
customize_auth_routes(self, routes: list[BaseRoute]) -> list[BaseRoute]
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
Add AuthKit metadata endpoints.
|
| 54 |
+
|
| 55 |
+
This adds:
|
| 56 |
+
- /.well-known/oauth-authorization-server (forwards AuthKit metadata)
|
| 57 |
+
- /.well-known/oauth-protected-resource (returns FastMCP resource info)
|
| 58 |
+
|
docs/python-sdk/fastmcp-server-auth-registry.mdx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: registry
|
| 3 |
+
sidebarTitle: registry
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.registry`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Provider registry for FastMCP auth providers.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `register_provider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/registry.py#L19" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
register_provider(name: str) -> Callable[[type[T]], type[T]]
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Decorator to register an auth provider with a given name.
|
| 21 |
+
|
| 22 |
+
**Args:**
|
| 23 |
+
- `name`: The name to register the provider under (e.g., 'AUTHKIT')
|
| 24 |
+
|
| 25 |
+
**Returns:**
|
| 26 |
+
- The decorated class
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
### `get_registered_provider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/registry.py#L41" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
get_registered_provider(name: str) -> type[AuthProvider]
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Get a registered provider by name.
|
| 37 |
+
|
| 38 |
+
**Args:**
|
| 39 |
+
- `name`: The provider name (case-insensitive)
|
| 40 |
+
|
| 41 |
+
**Returns:**
|
| 42 |
+
- The provider class if found, None otherwise
|
| 43 |
+
|
docs/python-sdk/fastmcp-server-context.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: context
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `set_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
set_context(context: Context) -> Generator[Context, None, None]
|
|
@@ -15,7 +15,16 @@ set_context(context: Context) -> Generator[Context, None, None]
|
|
| 15 |
|
| 16 |
## Classes
|
| 17 |
|
| 18 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
Context object providing access to MCP capabilities.
|
|
@@ -63,10 +72,10 @@ The context is optional - tools that don't need it can omit the parameter.
|
|
| 63 |
|
| 64 |
**Methods:**
|
| 65 |
|
| 66 |
-
#### `request_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 67 |
|
| 68 |
```python
|
| 69 |
-
request_context(self) -> RequestContext
|
| 70 |
```
|
| 71 |
|
| 72 |
Access to the underlying request context.
|
|
@@ -74,7 +83,7 @@ Access to the underlying request context.
|
|
| 74 |
If called outside of a request context, this will raise a ValueError.
|
| 75 |
|
| 76 |
|
| 77 |
-
#### `report_progress` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 78 |
|
| 79 |
```python
|
| 80 |
report_progress(self, progress: float, total: float | None = None, message: str | None = None) -> None
|
|
@@ -87,7 +96,7 @@ Report progress for the current operation.
|
|
| 87 |
- `total`: Optional total value e.g. 100
|
| 88 |
|
| 89 |
|
| 90 |
-
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 91 |
|
| 92 |
```python
|
| 93 |
read_resource(self, uri: str | AnyUrl) -> list[ReadResourceContents]
|
|
@@ -102,10 +111,10 @@ Read a resource by URI.
|
|
| 102 |
- The resource content as either text or bytes
|
| 103 |
|
| 104 |
|
| 105 |
-
#### `log` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 106 |
|
| 107 |
```python
|
| 108 |
-
log(self, message: str, level: LoggingLevel | None = None, logger_name: str | None = None) -> None
|
| 109 |
```
|
| 110 |
|
| 111 |
Send a log message to the client.
|
|
@@ -115,9 +124,10 @@ Send a log message to the client.
|
|
| 115 |
- `level`: Optional log level. One of "debug", "info", "notice", "warning", "error", "critical",
|
| 116 |
"alert", or "emergency". Default is "info".
|
| 117 |
- `logger_name`: Optional logger name
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
-
#### `client_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 121 |
|
| 122 |
```python
|
| 123 |
client_id(self) -> str | None
|
|
@@ -126,7 +136,7 @@ client_id(self) -> str | None
|
|
| 126 |
Get the client ID if available.
|
| 127 |
|
| 128 |
|
| 129 |
-
#### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 130 |
|
| 131 |
```python
|
| 132 |
request_id(self) -> str
|
|
@@ -135,24 +145,24 @@ request_id(self) -> str
|
|
| 135 |
Get the unique ID for this request.
|
| 136 |
|
| 137 |
|
| 138 |
-
#### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 139 |
|
| 140 |
```python
|
| 141 |
-
session_id(self) -> str
|
| 142 |
```
|
| 143 |
|
| 144 |
-
Get the MCP session ID for
|
| 145 |
|
| 146 |
Returns the session ID that can be used as a key for session-based
|
| 147 |
data storage (e.g., Redis) to share data between tool calls within
|
| 148 |
the same client session.
|
| 149 |
|
| 150 |
**Returns:**
|
| 151 |
-
- The session ID for
|
| 152 |
-
- for
|
| 153 |
|
| 154 |
|
| 155 |
-
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 156 |
|
| 157 |
```python
|
| 158 |
session(self) -> ServerSession
|
|
@@ -161,43 +171,43 @@ session(self) -> ServerSession
|
|
| 161 |
Access to the underlying session for advanced usage.
|
| 162 |
|
| 163 |
|
| 164 |
-
#### `debug` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 165 |
|
| 166 |
```python
|
| 167 |
-
debug(self, message: str, logger_name: str | None = None) -> None
|
| 168 |
```
|
| 169 |
|
| 170 |
Send a debug log message.
|
| 171 |
|
| 172 |
|
| 173 |
-
#### `info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 174 |
|
| 175 |
```python
|
| 176 |
-
info(self, message: str, logger_name: str | None = None) -> None
|
| 177 |
```
|
| 178 |
|
| 179 |
Send an info log message.
|
| 180 |
|
| 181 |
|
| 182 |
-
#### `warning` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 183 |
|
| 184 |
```python
|
| 185 |
-
warning(self, message: str, logger_name: str | None = None) -> None
|
| 186 |
```
|
| 187 |
|
| 188 |
Send a warning log message.
|
| 189 |
|
| 190 |
|
| 191 |
-
#### `error` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 192 |
|
| 193 |
```python
|
| 194 |
-
error(self, message: str, logger_name: str | None = None) -> None
|
| 195 |
```
|
| 196 |
|
| 197 |
Send an error log message.
|
| 198 |
|
| 199 |
|
| 200 |
-
#### `list_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 201 |
|
| 202 |
```python
|
| 203 |
list_roots(self) -> list[Root]
|
|
@@ -206,7 +216,7 @@ list_roots(self) -> list[Root]
|
|
| 206 |
List the roots available to the server, as indicated by the client.
|
| 207 |
|
| 208 |
|
| 209 |
-
#### `send_tool_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 210 |
|
| 211 |
```python
|
| 212 |
send_tool_list_changed(self) -> None
|
|
@@ -215,7 +225,7 @@ send_tool_list_changed(self) -> None
|
|
| 215 |
Send a tool list changed notification to the client.
|
| 216 |
|
| 217 |
|
| 218 |
-
#### `send_resource_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 219 |
|
| 220 |
```python
|
| 221 |
send_resource_list_changed(self) -> None
|
|
@@ -224,7 +234,7 @@ send_resource_list_changed(self) -> None
|
|
| 224 |
Send a resource list changed notification to the client.
|
| 225 |
|
| 226 |
|
| 227 |
-
#### `send_prompt_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 228 |
|
| 229 |
```python
|
| 230 |
send_prompt_list_changed(self) -> None
|
|
@@ -233,7 +243,7 @@ send_prompt_list_changed(self) -> None
|
|
| 233 |
Send a prompt list changed notification to the client.
|
| 234 |
|
| 235 |
|
| 236 |
-
#### `sample` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 237 |
|
| 238 |
```python
|
| 239 |
sample(self, messages: str | list[str | SamplingMessage], system_prompt: str | None = None, include_context: IncludeContext | None = None, temperature: float | None = None, max_tokens: int | None = None, model_preferences: ModelPreferences | str | list[str] | None = None) -> ContentBlock
|
|
@@ -246,25 +256,25 @@ completion from the client. The client must be appropriately configured,
|
|
| 246 |
or the request will error.
|
| 247 |
|
| 248 |
|
| 249 |
-
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 250 |
|
| 251 |
```python
|
| 252 |
elicit(self, message: str, response_type: None) -> AcceptedElicitation[dict[str, Any]] | DeclinedElicitation | CancelledElicitation
|
| 253 |
```
|
| 254 |
|
| 255 |
-
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 256 |
|
| 257 |
```python
|
| 258 |
elicit(self, message: str, response_type: type[T]) -> AcceptedElicitation[T] | DeclinedElicitation | CancelledElicitation
|
| 259 |
```
|
| 260 |
|
| 261 |
-
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 262 |
|
| 263 |
```python
|
| 264 |
elicit(self, message: str, response_type: list[str]) -> AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
| 265 |
```
|
| 266 |
|
| 267 |
-
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 268 |
|
| 269 |
```python
|
| 270 |
elicit(self, message: str, response_type: type[T] | list[str] | None = None) -> AcceptedElicitation[T] | AcceptedElicitation[dict[str, Any]] | AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
|
@@ -293,7 +303,7 @@ type or dataclass or BaseModel. If it is a primitive type, an
|
|
| 293 |
object schema with a single "value" field will be generated.
|
| 294 |
|
| 295 |
|
| 296 |
-
#### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 297 |
|
| 298 |
```python
|
| 299 |
get_http_request(self) -> Request
|
|
@@ -302,7 +312,7 @@ get_http_request(self) -> Request
|
|
| 302 |
Get the active starlette request.
|
| 303 |
|
| 304 |
|
| 305 |
-
#### `set_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 306 |
|
| 307 |
```python
|
| 308 |
set_state(self, key: str, value: Any) -> None
|
|
@@ -311,7 +321,7 @@ set_state(self, key: str, value: Any) -> None
|
|
| 311 |
Set a value in the context state.
|
| 312 |
|
| 313 |
|
| 314 |
-
#### `get_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 315 |
|
| 316 |
```python
|
| 317 |
get_state(self, key: str) -> Any
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `set_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L63" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
set_context(context: Context) -> Generator[Context, None, None]
|
|
|
|
| 15 |
|
| 16 |
## Classes
|
| 17 |
|
| 18 |
+
### `LogData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L51" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Data object for passing log arguments to client-side handlers.
|
| 22 |
+
|
| 23 |
+
This provides an interface to match the Python standard library logging,
|
| 24 |
+
for compatibility with structured logging.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
### `Context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
|
| 29 |
|
| 30 |
Context object providing access to MCP capabilities.
|
|
|
|
| 72 |
|
| 73 |
**Methods:**
|
| 74 |
|
| 75 |
+
#### `request_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L145" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 76 |
|
| 77 |
```python
|
| 78 |
+
request_context(self) -> RequestContext[ServerSession, Any, Request]
|
| 79 |
```
|
| 80 |
|
| 81 |
Access to the underlying request context.
|
|
|
|
| 83 |
If called outside of a request context, this will raise a ValueError.
|
| 84 |
|
| 85 |
|
| 86 |
+
#### `report_progress` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L155" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 87 |
|
| 88 |
```python
|
| 89 |
report_progress(self, progress: float, total: float | None = None, message: str | None = None) -> None
|
|
|
|
| 96 |
- `total`: Optional total value e.g. 100
|
| 97 |
|
| 98 |
|
| 99 |
+
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 100 |
|
| 101 |
```python
|
| 102 |
read_resource(self, uri: str | AnyUrl) -> list[ReadResourceContents]
|
|
|
|
| 111 |
- The resource content as either text or bytes
|
| 112 |
|
| 113 |
|
| 114 |
+
#### `log` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L194" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 115 |
|
| 116 |
```python
|
| 117 |
+
log(self, message: str, level: LoggingLevel | None = None, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
|
| 118 |
```
|
| 119 |
|
| 120 |
Send a log message to the client.
|
|
|
|
| 124 |
- `level`: Optional log level. One of "debug", "info", "notice", "warning", "error", "critical",
|
| 125 |
"alert", or "emergency". Default is "info".
|
| 126 |
- `logger_name`: Optional logger name
|
| 127 |
+
- `extra`: Optional mapping for additional arguments
|
| 128 |
|
| 129 |
|
| 130 |
+
#### `client_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L221" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 131 |
|
| 132 |
```python
|
| 133 |
client_id(self) -> str | None
|
|
|
|
| 136 |
Get the client ID if available.
|
| 137 |
|
| 138 |
|
| 139 |
+
#### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L230" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 140 |
|
| 141 |
```python
|
| 142 |
request_id(self) -> str
|
|
|
|
| 145 |
Get the unique ID for this request.
|
| 146 |
|
| 147 |
|
| 148 |
+
#### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L235" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 149 |
|
| 150 |
```python
|
| 151 |
+
session_id(self) -> str
|
| 152 |
```
|
| 153 |
|
| 154 |
+
Get the MCP session ID for ALL transports.
|
| 155 |
|
| 156 |
Returns the session ID that can be used as a key for session-based
|
| 157 |
data storage (e.g., Redis) to share data between tool calls within
|
| 158 |
the same client session.
|
| 159 |
|
| 160 |
**Returns:**
|
| 161 |
+
- The session ID for StreamableHTTP transports, or a generated ID
|
| 162 |
+
- for other transports.
|
| 163 |
|
| 164 |
|
| 165 |
+
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L279" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 166 |
|
| 167 |
```python
|
| 168 |
session(self) -> ServerSession
|
|
|
|
| 171 |
Access to the underlying session for advanced usage.
|
| 172 |
|
| 173 |
|
| 174 |
+
#### `debug` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L284" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 175 |
|
| 176 |
```python
|
| 177 |
+
debug(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
|
| 178 |
```
|
| 179 |
|
| 180 |
Send a debug log message.
|
| 181 |
|
| 182 |
|
| 183 |
+
#### `info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L295" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 184 |
|
| 185 |
```python
|
| 186 |
+
info(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
|
| 187 |
```
|
| 188 |
|
| 189 |
Send an info log message.
|
| 190 |
|
| 191 |
|
| 192 |
+
#### `warning` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L306" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 193 |
|
| 194 |
```python
|
| 195 |
+
warning(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
|
| 196 |
```
|
| 197 |
|
| 198 |
Send a warning log message.
|
| 199 |
|
| 200 |
|
| 201 |
+
#### `error` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L317" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 202 |
|
| 203 |
```python
|
| 204 |
+
error(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
|
| 205 |
```
|
| 206 |
|
| 207 |
Send an error log message.
|
| 208 |
|
| 209 |
|
| 210 |
+
#### `list_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L328" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 211 |
|
| 212 |
```python
|
| 213 |
list_roots(self) -> list[Root]
|
|
|
|
| 216 |
List the roots available to the server, as indicated by the client.
|
| 217 |
|
| 218 |
|
| 219 |
+
#### `send_tool_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L333" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 220 |
|
| 221 |
```python
|
| 222 |
send_tool_list_changed(self) -> None
|
|
|
|
| 225 |
Send a tool list changed notification to the client.
|
| 226 |
|
| 227 |
|
| 228 |
+
#### `send_resource_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L337" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 229 |
|
| 230 |
```python
|
| 231 |
send_resource_list_changed(self) -> None
|
|
|
|
| 234 |
Send a resource list changed notification to the client.
|
| 235 |
|
| 236 |
|
| 237 |
+
#### `send_prompt_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L341" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 238 |
|
| 239 |
```python
|
| 240 |
send_prompt_list_changed(self) -> None
|
|
|
|
| 243 |
Send a prompt list changed notification to the client.
|
| 244 |
|
| 245 |
|
| 246 |
+
#### `sample` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L345" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 247 |
|
| 248 |
```python
|
| 249 |
sample(self, messages: str | list[str | SamplingMessage], system_prompt: str | None = None, include_context: IncludeContext | None = None, temperature: float | None = None, max_tokens: int | None = None, model_preferences: ModelPreferences | str | list[str] | None = None) -> ContentBlock
|
|
|
|
| 256 |
or the request will error.
|
| 257 |
|
| 258 |
|
| 259 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L392" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 260 |
|
| 261 |
```python
|
| 262 |
elicit(self, message: str, response_type: None) -> AcceptedElicitation[dict[str, Any]] | DeclinedElicitation | CancelledElicitation
|
| 263 |
```
|
| 264 |
|
| 265 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L404" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 266 |
|
| 267 |
```python
|
| 268 |
elicit(self, message: str, response_type: type[T]) -> AcceptedElicitation[T] | DeclinedElicitation | CancelledElicitation
|
| 269 |
```
|
| 270 |
|
| 271 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L414" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 272 |
|
| 273 |
```python
|
| 274 |
elicit(self, message: str, response_type: list[str]) -> AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
| 275 |
```
|
| 276 |
|
| 277 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L423" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 278 |
|
| 279 |
```python
|
| 280 |
elicit(self, message: str, response_type: type[T] | list[str] | None = None) -> AcceptedElicitation[T] | AcceptedElicitation[dict[str, Any]] | AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
|
|
|
| 303 |
object schema with a single "value" field will be generated.
|
| 304 |
|
| 305 |
|
| 306 |
+
#### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L516" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 307 |
|
| 308 |
```python
|
| 309 |
get_http_request(self) -> Request
|
|
|
|
| 312 |
Get the active starlette request.
|
| 313 |
|
| 314 |
|
| 315 |
+
#### `set_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L531" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 316 |
|
| 317 |
```python
|
| 318 |
set_state(self, key: str, value: Any) -> None
|
|
|
|
| 321 |
Set a value in the context state.
|
| 322 |
|
| 323 |
|
| 324 |
+
#### `get_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L535" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 325 |
|
| 326 |
```python
|
| 327 |
get_state(self, key: str) -> Any
|
docs/python-sdk/fastmcp-server-dependencies.mdx
CHANGED
|
@@ -19,7 +19,7 @@ get_context() -> Context
|
|
| 19 |
get_http_request() -> Request
|
| 20 |
```
|
| 21 |
|
| 22 |
-
### `get_http_headers` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#
|
| 23 |
|
| 24 |
```python
|
| 25 |
get_http_headers(include_all: bool = False) -> dict[str, str]
|
|
|
|
| 19 |
get_http_request() -> Request
|
| 20 |
```
|
| 21 |
|
| 22 |
+
### `get_http_headers` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L53" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 23 |
|
| 24 |
```python
|
| 25 |
get_http_headers(include_all: bool = False) -> dict[str, str]
|
docs/python-sdk/fastmcp-server-http.mdx
CHANGED
|
@@ -7,29 +7,29 @@ sidebarTitle: http
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `set_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
set_http_request(request: Request) -> Generator[Request, None, None]
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `setup_auth_middleware_and_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 17 |
|
| 18 |
```python
|
| 19 |
-
setup_auth_middleware_and_routes(auth:
|
| 20 |
```
|
| 21 |
|
| 22 |
|
| 23 |
Set up authentication middleware and routes if auth is enabled.
|
| 24 |
|
| 25 |
**Args:**
|
| 26 |
-
- `auth`:
|
| 27 |
|
| 28 |
**Returns:**
|
| 29 |
- Tuple of (middleware, auth_routes, required_scopes)
|
| 30 |
|
| 31 |
|
| 32 |
-
### `create_base_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 33 |
|
| 34 |
```python
|
| 35 |
create_base_app(routes: list[BaseRoute], middleware: list[Middleware], debug: bool = False, lifespan: Callable | None = None) -> StarletteWithLifespan
|
|
@@ -48,10 +48,10 @@ Create a base Starlette app with common middleware and routes.
|
|
| 48 |
- A Starlette application
|
| 49 |
|
| 50 |
|
| 51 |
-
### `create_sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 52 |
|
| 53 |
```python
|
| 54 |
-
create_sse_app(server: FastMCP[LifespanResultT], message_path: str, sse_path: str, auth:
|
| 55 |
```
|
| 56 |
|
| 57 |
|
|
@@ -61,7 +61,7 @@ Return an instance of the SSE server app.
|
|
| 61 |
- `server`: The FastMCP server instance
|
| 62 |
- `message_path`: Path for SSE messages
|
| 63 |
- `sse_path`: Path for SSE connections
|
| 64 |
-
- `auth`: Optional
|
| 65 |
- `debug`: Whether to enable debug mode
|
| 66 |
- `routes`: Optional list of custom routes
|
| 67 |
- `middleware`: Optional list of middleware
|
|
@@ -70,10 +70,10 @@ Returns:
|
|
| 70 |
A Starlette application with RequestContextMiddleware
|
| 71 |
|
| 72 |
|
| 73 |
-
### `create_streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 74 |
|
| 75 |
```python
|
| 76 |
-
create_streamable_http_app(server: FastMCP[LifespanResultT], streamable_http_path: str, event_store: EventStore | None = None, auth:
|
| 77 |
```
|
| 78 |
|
| 79 |
|
|
@@ -83,7 +83,7 @@ Return an instance of the StreamableHTTP server app.
|
|
| 83 |
- `server`: The FastMCP server instance
|
| 84 |
- `streamable_http_path`: Path for StreamableHTTP connections
|
| 85 |
- `event_store`: Optional event store for session management
|
| 86 |
-
- `auth`: Optional
|
| 87 |
- `json_response`: Whether to use JSON response format
|
| 88 |
- `stateless_http`: Whether to use stateless mode (new transport per request)
|
| 89 |
- `debug`: Whether to enable debug mode
|
|
@@ -96,17 +96,17 @@ Return an instance of the StreamableHTTP server app.
|
|
| 96 |
|
| 97 |
## Classes
|
| 98 |
|
| 99 |
-
### `StarletteWithLifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 100 |
|
| 101 |
**Methods:**
|
| 102 |
|
| 103 |
-
#### `lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 104 |
|
| 105 |
```python
|
| 106 |
lifespan(self) -> Lifespan
|
| 107 |
```
|
| 108 |
|
| 109 |
-
### `RequestContextMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#
|
| 110 |
|
| 111 |
|
| 112 |
Middleware that stores each request in a ContextVar
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `set_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L50" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
set_http_request(request: Request) -> Generator[Request, None, None]
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `setup_auth_middleware_and_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L74" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
+
setup_auth_middleware_and_routes(auth: AuthProvider) -> tuple[list[Middleware], list[Route], list[str]]
|
| 20 |
```
|
| 21 |
|
| 22 |
|
| 23 |
Set up authentication middleware and routes if auth is enabled.
|
| 24 |
|
| 25 |
**Args:**
|
| 26 |
+
- `auth`: An AuthProvider for authentication (TokenVerifier or OAuthProvider)
|
| 27 |
|
| 28 |
**Returns:**
|
| 29 |
- Tuple of (middleware, auth_routes, required_scopes)
|
| 30 |
|
| 31 |
|
| 32 |
+
### `create_base_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L119" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 33 |
|
| 34 |
```python
|
| 35 |
create_base_app(routes: list[BaseRoute], middleware: list[Middleware], debug: bool = False, lifespan: Callable | None = None) -> StarletteWithLifespan
|
|
|
|
| 48 |
- A Starlette application
|
| 49 |
|
| 50 |
|
| 51 |
+
### `create_sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L147" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 52 |
|
| 53 |
```python
|
| 54 |
+
create_sse_app(server: FastMCP[LifespanResultT], message_path: str, sse_path: str, auth: AuthProvider | None = None, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
| 55 |
```
|
| 56 |
|
| 57 |
|
|
|
|
| 61 |
- `server`: The FastMCP server instance
|
| 62 |
- `message_path`: Path for SSE messages
|
| 63 |
- `sse_path`: Path for SSE connections
|
| 64 |
+
- `auth`: Optional authentication provider (AuthProvider)
|
| 65 |
- `debug`: Whether to enable debug mode
|
| 66 |
- `routes`: Optional list of custom routes
|
| 67 |
- `middleware`: Optional list of middleware
|
|
|
|
| 70 |
A Starlette application with RequestContextMiddleware
|
| 71 |
|
| 72 |
|
| 73 |
+
### `create_streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L263" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 74 |
|
| 75 |
```python
|
| 76 |
+
create_streamable_http_app(server: FastMCP[LifespanResultT], streamable_http_path: str, event_store: EventStore | None = None, auth: AuthProvider | None = None, json_response: bool = False, stateless_http: bool = False, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
| 77 |
```
|
| 78 |
|
| 79 |
|
|
|
|
| 83 |
- `server`: The FastMCP server instance
|
| 84 |
- `streamable_http_path`: Path for StreamableHTTP connections
|
| 85 |
- `event_store`: Optional event store for session management
|
| 86 |
+
- `auth`: Optional authentication provider (AuthProvider)
|
| 87 |
- `json_response`: Whether to use JSON response format
|
| 88 |
- `stateless_http`: Whether to use stateless mode (new transport per request)
|
| 89 |
- `debug`: Whether to enable debug mode
|
|
|
|
| 96 |
|
| 97 |
## Classes
|
| 98 |
|
| 99 |
+
### `StarletteWithLifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L43" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 100 |
|
| 101 |
**Methods:**
|
| 102 |
|
| 103 |
+
#### `lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L45" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 104 |
|
| 105 |
```python
|
| 106 |
lifespan(self) -> Lifespan
|
| 107 |
```
|
| 108 |
|
| 109 |
+
### `RequestContextMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L58" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 110 |
|
| 111 |
|
| 112 |
Middleware that stores each request in a ContextVar
|
docs/python-sdk/fastmcp-server-middleware-middleware.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: middleware
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `make_middleware_wrapper` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
make_middleware_wrapper(middleware: Middleware, call_next: CallNext[T, R]) -> CallNext[T, R]
|
|
@@ -23,9 +23,7 @@ passed to other functions that expect a call_next function.
|
|
| 23 |
|
| 24 |
### `CallNext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L42" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 25 |
|
| 26 |
-
### `
|
| 27 |
-
|
| 28 |
-
### `MiddlewareContext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L67" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 29 |
|
| 30 |
|
| 31 |
Unified context for all middleware operations.
|
|
@@ -33,13 +31,13 @@ Unified context for all middleware operations.
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
-
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
copy(self, **kwargs: Any) -> MiddlewareContext[T]
|
| 40 |
```
|
| 41 |
|
| 42 |
-
### `Middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 43 |
|
| 44 |
|
| 45 |
Base class for FastMCP middleware with dispatching hooks.
|
|
@@ -47,61 +45,61 @@ Base class for FastMCP middleware with dispatching hooks.
|
|
| 47 |
|
| 48 |
**Methods:**
|
| 49 |
|
| 50 |
-
#### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 51 |
|
| 52 |
```python
|
| 53 |
on_message(self, context: MiddlewareContext[Any], call_next: CallNext[Any, Any]) -> Any
|
| 54 |
```
|
| 55 |
|
| 56 |
-
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 57 |
|
| 58 |
```python
|
| 59 |
on_request(self, context: MiddlewareContext[mt.Request], call_next: CallNext[mt.Request, Any]) -> Any
|
| 60 |
```
|
| 61 |
|
| 62 |
-
#### `on_notification` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 63 |
|
| 64 |
```python
|
| 65 |
on_notification(self, context: MiddlewareContext[mt.Notification], call_next: CallNext[mt.Notification, Any]) -> Any
|
| 66 |
```
|
| 67 |
|
| 68 |
-
#### `on_call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 69 |
|
| 70 |
```python
|
| 71 |
-
on_call_tool(self, context: MiddlewareContext[mt.CallToolRequestParams], call_next: CallNext[mt.CallToolRequestParams,
|
| 72 |
```
|
| 73 |
|
| 74 |
-
#### `on_read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 75 |
|
| 76 |
```python
|
| 77 |
on_read_resource(self, context: MiddlewareContext[mt.ReadResourceRequestParams], call_next: CallNext[mt.ReadResourceRequestParams, mt.ReadResourceResult]) -> mt.ReadResourceResult
|
| 78 |
```
|
| 79 |
|
| 80 |
-
#### `on_get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 81 |
|
| 82 |
```python
|
| 83 |
on_get_prompt(self, context: MiddlewareContext[mt.GetPromptRequestParams], call_next: CallNext[mt.GetPromptRequestParams, mt.GetPromptResult]) -> mt.GetPromptResult
|
| 84 |
```
|
| 85 |
|
| 86 |
-
#### `on_list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 87 |
|
| 88 |
```python
|
| 89 |
on_list_tools(self, context: MiddlewareContext[mt.ListToolsRequest], call_next: CallNext[mt.ListToolsRequest, list[Tool]]) -> list[Tool]
|
| 90 |
```
|
| 91 |
|
| 92 |
-
#### `on_list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 93 |
|
| 94 |
```python
|
| 95 |
on_list_resources(self, context: MiddlewareContext[mt.ListResourcesRequest], call_next: CallNext[mt.ListResourcesRequest, list[Resource]]) -> list[Resource]
|
| 96 |
```
|
| 97 |
|
| 98 |
-
#### `on_list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 99 |
|
| 100 |
```python
|
| 101 |
on_list_resource_templates(self, context: MiddlewareContext[mt.ListResourceTemplatesRequest], call_next: CallNext[mt.ListResourceTemplatesRequest, list[ResourceTemplate]]) -> list[ResourceTemplate]
|
| 102 |
```
|
| 103 |
|
| 104 |
-
#### `on_list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 105 |
|
| 106 |
```python
|
| 107 |
on_list_prompts(self, context: MiddlewareContext[mt.ListPromptsRequest], call_next: CallNext[mt.ListPromptsRequest, list[Prompt]]) -> list[Prompt]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `make_middleware_wrapper` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L66" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
make_middleware_wrapper(middleware: Middleware, call_next: CallNext[T, R]) -> CallNext[T, R]
|
|
|
|
| 23 |
|
| 24 |
### `CallNext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L42" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 25 |
|
| 26 |
+
### `MiddlewareContext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L47" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
Unified context for all middleware operations.
|
|
|
|
| 31 |
|
| 32 |
**Methods:**
|
| 33 |
|
| 34 |
+
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L62" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 35 |
|
| 36 |
```python
|
| 37 |
copy(self, **kwargs: Any) -> MiddlewareContext[T]
|
| 38 |
```
|
| 39 |
|
| 40 |
+
### `Middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L79" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 41 |
|
| 42 |
|
| 43 |
Base class for FastMCP middleware with dispatching hooks.
|
|
|
|
| 45 |
|
| 46 |
**Methods:**
|
| 47 |
|
| 48 |
+
#### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L126" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
|
| 50 |
```python
|
| 51 |
on_message(self, context: MiddlewareContext[Any], call_next: CallNext[Any, Any]) -> Any
|
| 52 |
```
|
| 53 |
|
| 54 |
+
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L133" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 55 |
|
| 56 |
```python
|
| 57 |
on_request(self, context: MiddlewareContext[mt.Request], call_next: CallNext[mt.Request, Any]) -> Any
|
| 58 |
```
|
| 59 |
|
| 60 |
+
#### `on_notification` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 61 |
|
| 62 |
```python
|
| 63 |
on_notification(self, context: MiddlewareContext[mt.Notification], call_next: CallNext[mt.Notification, Any]) -> Any
|
| 64 |
```
|
| 65 |
|
| 66 |
+
#### `on_call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L147" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 67 |
|
| 68 |
```python
|
| 69 |
+
on_call_tool(self, context: MiddlewareContext[mt.CallToolRequestParams], call_next: CallNext[mt.CallToolRequestParams, ToolResult]) -> ToolResult
|
| 70 |
```
|
| 71 |
|
| 72 |
+
#### `on_read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L154" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 73 |
|
| 74 |
```python
|
| 75 |
on_read_resource(self, context: MiddlewareContext[mt.ReadResourceRequestParams], call_next: CallNext[mt.ReadResourceRequestParams, mt.ReadResourceResult]) -> mt.ReadResourceResult
|
| 76 |
```
|
| 77 |
|
| 78 |
+
#### `on_get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L161" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 79 |
|
| 80 |
```python
|
| 81 |
on_get_prompt(self, context: MiddlewareContext[mt.GetPromptRequestParams], call_next: CallNext[mt.GetPromptRequestParams, mt.GetPromptResult]) -> mt.GetPromptResult
|
| 82 |
```
|
| 83 |
|
| 84 |
+
#### `on_list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L168" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 85 |
|
| 86 |
```python
|
| 87 |
on_list_tools(self, context: MiddlewareContext[mt.ListToolsRequest], call_next: CallNext[mt.ListToolsRequest, list[Tool]]) -> list[Tool]
|
| 88 |
```
|
| 89 |
|
| 90 |
+
#### `on_list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L175" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 91 |
|
| 92 |
```python
|
| 93 |
on_list_resources(self, context: MiddlewareContext[mt.ListResourcesRequest], call_next: CallNext[mt.ListResourcesRequest, list[Resource]]) -> list[Resource]
|
| 94 |
```
|
| 95 |
|
| 96 |
+
#### `on_list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 97 |
|
| 98 |
```python
|
| 99 |
on_list_resource_templates(self, context: MiddlewareContext[mt.ListResourceTemplatesRequest], call_next: CallNext[mt.ListResourceTemplatesRequest, list[ResourceTemplate]]) -> list[ResourceTemplate]
|
| 100 |
```
|
| 101 |
|
| 102 |
+
#### `on_list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L189" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 103 |
|
| 104 |
```python
|
| 105 |
on_list_prompts(self, context: MiddlewareContext[mt.ListPromptsRequest], call_next: CallNext[mt.ListPromptsRequest, list[Prompt]]) -> list[Prompt]
|
docs/python-sdk/fastmcp-server-proxy.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: proxy
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `default_proxy_roots_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_proxy_roots_handler(context: RequestContext[ClientSession, LifespanContextT]) -> RootsList
|
|
@@ -19,7 +19,7 @@ A handler that forwards the list roots request from the remote server to the pro
|
|
| 19 |
|
| 20 |
## Classes
|
| 21 |
|
| 22 |
-
### `ProxyToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 23 |
|
| 24 |
|
| 25 |
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
|
@@ -27,7 +27,7 @@ A ToolManager that sources its tools from a remote client in addition to local a
|
|
| 27 |
|
| 28 |
**Methods:**
|
| 29 |
|
| 30 |
-
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 31 |
|
| 32 |
```python
|
| 33 |
get_tools(self) -> dict[str, Tool]
|
|
@@ -36,7 +36,7 @@ get_tools(self) -> dict[str, Tool]
|
|
| 36 |
Gets the unfiltered tool inventory including local, mounted, and proxy tools.
|
| 37 |
|
| 38 |
|
| 39 |
-
#### `list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 40 |
|
| 41 |
```python
|
| 42 |
list_tools(self) -> list[Tool]
|
|
@@ -45,7 +45,7 @@ list_tools(self) -> list[Tool]
|
|
| 45 |
Gets the filtered list of tools including local, mounted, and proxy tools.
|
| 46 |
|
| 47 |
|
| 48 |
-
#### `call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 49 |
|
| 50 |
```python
|
| 51 |
call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -54,7 +54,7 @@ call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
|
| 54 |
Calls a tool, trying local/mounted first, then proxy if not found.
|
| 55 |
|
| 56 |
|
| 57 |
-
### `ProxyResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 58 |
|
| 59 |
|
| 60 |
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
|
@@ -62,7 +62,7 @@ A ResourceManager that sources its resources from a remote client in addition to
|
|
| 62 |
|
| 63 |
**Methods:**
|
| 64 |
|
| 65 |
-
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 66 |
|
| 67 |
```python
|
| 68 |
get_resources(self) -> dict[str, Resource]
|
|
@@ -71,7 +71,7 @@ get_resources(self) -> dict[str, Resource]
|
|
| 71 |
Gets the unfiltered resource inventory including local, mounted, and proxy resources.
|
| 72 |
|
| 73 |
|
| 74 |
-
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 75 |
|
| 76 |
```python
|
| 77 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
@@ -80,7 +80,7 @@ get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
| 80 |
Gets the unfiltered template inventory including local, mounted, and proxy templates.
|
| 81 |
|
| 82 |
|
| 83 |
-
#### `list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 84 |
|
| 85 |
```python
|
| 86 |
list_resources(self) -> list[Resource]
|
|
@@ -89,7 +89,7 @@ list_resources(self) -> list[Resource]
|
|
| 89 |
Gets the filtered list of resources including local, mounted, and proxy resources.
|
| 90 |
|
| 91 |
|
| 92 |
-
#### `list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 93 |
|
| 94 |
```python
|
| 95 |
list_resource_templates(self) -> list[ResourceTemplate]
|
|
@@ -98,7 +98,7 @@ list_resource_templates(self) -> list[ResourceTemplate]
|
|
| 98 |
Gets the filtered list of templates including local, mounted, and proxy templates.
|
| 99 |
|
| 100 |
|
| 101 |
-
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 102 |
|
| 103 |
```python
|
| 104 |
read_resource(self, uri: AnyUrl | str) -> str | bytes
|
|
@@ -107,7 +107,7 @@ read_resource(self, uri: AnyUrl | str) -> str | bytes
|
|
| 107 |
Reads a resource, trying local/mounted first, then proxy if not found.
|
| 108 |
|
| 109 |
|
| 110 |
-
### `ProxyPromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 111 |
|
| 112 |
|
| 113 |
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
|
@@ -115,7 +115,7 @@ A PromptManager that sources its prompts from a remote client in addition to loc
|
|
| 115 |
|
| 116 |
**Methods:**
|
| 117 |
|
| 118 |
-
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 119 |
|
| 120 |
```python
|
| 121 |
get_prompts(self) -> dict[str, Prompt]
|
|
@@ -124,7 +124,7 @@ get_prompts(self) -> dict[str, Prompt]
|
|
| 124 |
Gets the unfiltered prompt inventory including local, mounted, and proxy prompts.
|
| 125 |
|
| 126 |
|
| 127 |
-
#### `list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 128 |
|
| 129 |
```python
|
| 130 |
list_prompts(self) -> list[Prompt]
|
|
@@ -133,7 +133,7 @@ list_prompts(self) -> list[Prompt]
|
|
| 133 |
Gets the filtered list of prompts including local, mounted, and proxy prompts.
|
| 134 |
|
| 135 |
|
| 136 |
-
#### `render_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 137 |
|
| 138 |
```python
|
| 139 |
render_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> GetPromptResult
|
|
@@ -142,7 +142,7 @@ render_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> GetPr
|
|
| 142 |
Renders a prompt, trying local/mounted first, then proxy if not found.
|
| 143 |
|
| 144 |
|
| 145 |
-
### `ProxyTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 146 |
|
| 147 |
|
| 148 |
A Tool that represents and executes a tool on a remote server.
|
|
@@ -150,7 +150,7 @@ A Tool that represents and executes a tool on a remote server.
|
|
| 150 |
|
| 151 |
**Methods:**
|
| 152 |
|
| 153 |
-
#### `from_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 154 |
|
| 155 |
```python
|
| 156 |
from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
@@ -159,7 +159,7 @@ from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
| 159 |
Factory method to create a ProxyTool from a raw MCP tool schema.
|
| 160 |
|
| 161 |
|
| 162 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 163 |
|
| 164 |
```python
|
| 165 |
run(self, arguments: dict[str, Any], context: Context | None = None) -> ToolResult
|
|
@@ -168,7 +168,7 @@ run(self, arguments: dict[str, Any], context: Context | None = None) -> ToolResu
|
|
| 168 |
Executes the tool by making a call through the client.
|
| 169 |
|
| 170 |
|
| 171 |
-
### `ProxyResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 172 |
|
| 173 |
|
| 174 |
A Resource that represents and reads a resource from a remote server.
|
|
@@ -176,7 +176,7 @@ A Resource that represents and reads a resource from a remote server.
|
|
| 176 |
|
| 177 |
**Methods:**
|
| 178 |
|
| 179 |
-
#### `from_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 180 |
|
| 181 |
```python
|
| 182 |
from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> ProxyResource
|
|
@@ -185,7 +185,7 @@ from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> Prox
|
|
| 185 |
Factory method to create a ProxyResource from a raw MCP resource schema.
|
| 186 |
|
| 187 |
|
| 188 |
-
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 189 |
|
| 190 |
```python
|
| 191 |
read(self) -> str | bytes
|
|
@@ -194,7 +194,7 @@ read(self) -> str | bytes
|
|
| 194 |
Read the resource content from the remote server.
|
| 195 |
|
| 196 |
|
| 197 |
-
### `ProxyTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 198 |
|
| 199 |
|
| 200 |
A ResourceTemplate that represents and creates resources from a remote server template.
|
|
@@ -202,7 +202,7 @@ A ResourceTemplate that represents and creates resources from a remote server te
|
|
| 202 |
|
| 203 |
**Methods:**
|
| 204 |
|
| 205 |
-
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 206 |
|
| 207 |
```python
|
| 208 |
from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate) -> ProxyTemplate
|
|
@@ -211,7 +211,7 @@ from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate)
|
|
| 211 |
Factory method to create a ProxyTemplate from a raw MCP template schema.
|
| 212 |
|
| 213 |
|
| 214 |
-
#### `create_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 215 |
|
| 216 |
```python
|
| 217 |
create_resource(self, uri: str, params: dict[str, Any], context: Context | None = None) -> ProxyResource
|
|
@@ -220,7 +220,7 @@ create_resource(self, uri: str, params: dict[str, Any], context: Context | None
|
|
| 220 |
Create a resource from the template by calling the remote server.
|
| 221 |
|
| 222 |
|
| 223 |
-
### `ProxyPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 224 |
|
| 225 |
|
| 226 |
A Prompt that represents and renders a prompt from a remote server.
|
|
@@ -228,7 +228,7 @@ A Prompt that represents and renders a prompt from a remote server.
|
|
| 228 |
|
| 229 |
**Methods:**
|
| 230 |
|
| 231 |
-
#### `from_mcp_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 232 |
|
| 233 |
```python
|
| 234 |
from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPrompt
|
|
@@ -237,7 +237,7 @@ from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPromp
|
|
| 237 |
Factory method to create a ProxyPrompt from a raw MCP prompt schema.
|
| 238 |
|
| 239 |
|
| 240 |
-
#### `render` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 241 |
|
| 242 |
```python
|
| 243 |
render(self, arguments: dict[str, Any]) -> list[PromptMessage]
|
|
@@ -246,14 +246,14 @@ render(self, arguments: dict[str, Any]) -> list[PromptMessage]
|
|
| 246 |
Render the prompt by making a call through the client.
|
| 247 |
|
| 248 |
|
| 249 |
-
### `FastMCPProxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 250 |
|
| 251 |
|
| 252 |
A FastMCP server that acts as a proxy to a remote MCP-compliant server.
|
| 253 |
It uses specialized managers that fulfill requests via a client factory.
|
| 254 |
|
| 255 |
|
| 256 |
-
### `ProxyClient` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 257 |
|
| 258 |
|
| 259 |
A proxy client that forwards advanced interactions between a remote MCP server and the proxy's connected clients.
|
|
@@ -262,7 +262,7 @@ Supports forwarding roots, sampling, elicitation, logging, and progress.
|
|
| 262 |
|
| 263 |
**Methods:**
|
| 264 |
|
| 265 |
-
#### `default_sampling_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 266 |
|
| 267 |
```python
|
| 268 |
default_sampling_handler(cls, messages: list[mcp.types.SamplingMessage], params: mcp.types.CreateMessageRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> mcp.types.CreateMessageResult
|
|
@@ -271,7 +271,7 @@ default_sampling_handler(cls, messages: list[mcp.types.SamplingMessage], params:
|
|
| 271 |
A handler that forwards the sampling request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 272 |
|
| 273 |
|
| 274 |
-
#### `default_elicitation_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 275 |
|
| 276 |
```python
|
| 277 |
default_elicitation_handler(cls, message: str, response_type: type, params: mcp.types.ElicitRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> ElicitResult
|
|
@@ -280,7 +280,7 @@ default_elicitation_handler(cls, message: str, response_type: type, params: mcp.
|
|
| 280 |
A handler that forwards the elicitation request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 281 |
|
| 282 |
|
| 283 |
-
#### `default_log_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 284 |
|
| 285 |
```python
|
| 286 |
default_log_handler(cls, message: LogMessage) -> None
|
|
@@ -289,7 +289,7 @@ default_log_handler(cls, message: LogMessage) -> None
|
|
| 289 |
A handler that forwards the log notification from the remote server to the proxy's connected clients.
|
| 290 |
|
| 291 |
|
| 292 |
-
#### `default_progress_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 293 |
|
| 294 |
```python
|
| 295 |
default_progress_handler(cls, progress: float, total: float | None, message: str | None) -> None
|
|
@@ -298,7 +298,7 @@ default_progress_handler(cls, progress: float, total: float | None, message: str
|
|
| 298 |
A handler that forwards the progress notification from the remote server to the proxy's connected clients.
|
| 299 |
|
| 300 |
|
| 301 |
-
### `StatefulProxyClient` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 302 |
|
| 303 |
|
| 304 |
A proxy client that provides a stateful client factory for the proxy server.
|
|
@@ -312,7 +312,16 @@ Note that it is essential to ensure that the proxy server itself is also statefu
|
|
| 312 |
|
| 313 |
**Methods:**
|
| 314 |
|
| 315 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
```python
|
| 318 |
new_stateful(self) -> Client[ClientTransportT]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_proxy_roots_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L503" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_proxy_roots_handler(context: RequestContext[ClientSession, LifespanContextT]) -> RootsList
|
|
|
|
| 19 |
|
| 20 |
## Classes
|
| 21 |
|
| 22 |
+
### `ProxyToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L52" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 23 |
|
| 24 |
|
| 25 |
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
|
|
|
| 27 |
|
| 28 |
**Methods:**
|
| 29 |
|
| 30 |
+
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L59" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 31 |
|
| 32 |
```python
|
| 33 |
get_tools(self) -> dict[str, Tool]
|
|
|
|
| 36 |
Gets the unfiltered tool inventory including local, mounted, and proxy tools.
|
| 37 |
|
| 38 |
|
| 39 |
+
#### `list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L85" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
list_tools(self) -> list[Tool]
|
|
|
|
| 45 |
Gets the filtered list of tools including local, mounted, and proxy tools.
|
| 46 |
|
| 47 |
|
| 48 |
+
#### `call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L90" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
|
| 50 |
```python
|
| 51 |
call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 54 |
Calls a tool, trying local/mounted first, then proxy if not found.
|
| 55 |
|
| 56 |
|
| 57 |
+
### `ProxyResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L106" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 58 |
|
| 59 |
|
| 60 |
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
|
|
|
| 62 |
|
| 63 |
**Methods:**
|
| 64 |
|
| 65 |
+
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L113" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 66 |
|
| 67 |
```python
|
| 68 |
get_resources(self) -> dict[str, Resource]
|
|
|
|
| 71 |
Gets the unfiltered resource inventory including local, mounted, and proxy resources.
|
| 72 |
|
| 73 |
|
| 74 |
+
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L136" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 75 |
|
| 76 |
```python
|
| 77 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
|
|
| 80 |
Gets the unfiltered template inventory including local, mounted, and proxy templates.
|
| 81 |
|
| 82 |
|
| 83 |
+
#### `list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L159" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 84 |
|
| 85 |
```python
|
| 86 |
list_resources(self) -> list[Resource]
|
|
|
|
| 89 |
Gets the filtered list of resources including local, mounted, and proxy resources.
|
| 90 |
|
| 91 |
|
| 92 |
+
#### `list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L164" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 93 |
|
| 94 |
```python
|
| 95 |
list_resource_templates(self) -> list[ResourceTemplate]
|
|
|
|
| 98 |
Gets the filtered list of templates including local, mounted, and proxy templates.
|
| 99 |
|
| 100 |
|
| 101 |
+
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L169" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 102 |
|
| 103 |
```python
|
| 104 |
read_resource(self, uri: AnyUrl | str) -> str | bytes
|
|
|
|
| 107 |
Reads a resource, trying local/mounted first, then proxy if not found.
|
| 108 |
|
| 109 |
|
| 110 |
+
### `ProxyPromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L187" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 111 |
|
| 112 |
|
| 113 |
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
|
|
|
| 115 |
|
| 116 |
**Methods:**
|
| 117 |
|
| 118 |
+
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L194" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 119 |
|
| 120 |
```python
|
| 121 |
get_prompts(self) -> dict[str, Prompt]
|
|
|
|
| 124 |
Gets the unfiltered prompt inventory including local, mounted, and proxy prompts.
|
| 125 |
|
| 126 |
|
| 127 |
+
#### `list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L217" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
|
| 129 |
```python
|
| 130 |
list_prompts(self) -> list[Prompt]
|
|
|
|
| 133 |
Gets the filtered list of prompts including local, mounted, and proxy prompts.
|
| 134 |
|
| 135 |
|
| 136 |
+
#### `render_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L222" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 137 |
|
| 138 |
```python
|
| 139 |
render_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> GetPromptResult
|
|
|
|
| 142 |
Renders a prompt, trying local/mounted first, then proxy if not found.
|
| 143 |
|
| 144 |
|
| 145 |
+
### `ProxyTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L239" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 146 |
|
| 147 |
|
| 148 |
A Tool that represents and executes a tool on a remote server.
|
|
|
|
| 150 |
|
| 151 |
**Methods:**
|
| 152 |
|
| 153 |
+
#### `from_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L249" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 154 |
|
| 155 |
```python
|
| 156 |
from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
|
|
| 159 |
Factory method to create a ProxyTool from a raw MCP tool schema.
|
| 160 |
|
| 161 |
|
| 162 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L263" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 163 |
|
| 164 |
```python
|
| 165 |
run(self, arguments: dict[str, Any], context: Context | None = None) -> ToolResult
|
|
|
|
| 168 |
Executes the tool by making a call through the client.
|
| 169 |
|
| 170 |
|
| 171 |
+
### `ProxyResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L282" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 172 |
|
| 173 |
|
| 174 |
A Resource that represents and reads a resource from a remote server.
|
|
|
|
| 176 |
|
| 177 |
**Methods:**
|
| 178 |
|
| 179 |
+
#### `from_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L302" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 180 |
|
| 181 |
```python
|
| 182 |
from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> ProxyResource
|
|
|
|
| 185 |
Factory method to create a ProxyResource from a raw MCP resource schema.
|
| 186 |
|
| 187 |
|
| 188 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L320" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 189 |
|
| 190 |
```python
|
| 191 |
read(self) -> str | bytes
|
|
|
|
| 194 |
Read the resource content from the remote server.
|
| 195 |
|
| 196 |
|
| 197 |
+
### `ProxyTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L335" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 198 |
|
| 199 |
|
| 200 |
A ResourceTemplate that represents and creates resources from a remote server template.
|
|
|
|
| 202 |
|
| 203 |
**Methods:**
|
| 204 |
|
| 205 |
+
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L345" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 206 |
|
| 207 |
```python
|
| 208 |
from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate) -> ProxyTemplate
|
|
|
|
| 211 |
Factory method to create a ProxyTemplate from a raw MCP template schema.
|
| 212 |
|
| 213 |
|
| 214 |
+
#### `create_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L361" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 215 |
|
| 216 |
```python
|
| 217 |
create_resource(self, uri: str, params: dict[str, Any], context: Context | None = None) -> ProxyResource
|
|
|
|
| 220 |
Create a resource from the template by calling the remote server.
|
| 221 |
|
| 222 |
|
| 223 |
+
### `ProxyPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L396" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 224 |
|
| 225 |
|
| 226 |
A Prompt that represents and renders a prompt from a remote server.
|
|
|
|
| 228 |
|
| 229 |
**Methods:**
|
| 230 |
|
| 231 |
+
#### `from_mcp_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L408" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 232 |
|
| 233 |
```python
|
| 234 |
from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPrompt
|
|
|
|
| 237 |
Factory method to create a ProxyPrompt from a raw MCP prompt schema.
|
| 238 |
|
| 239 |
|
| 240 |
+
#### `render` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L430" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 241 |
|
| 242 |
```python
|
| 243 |
render(self, arguments: dict[str, Any]) -> list[PromptMessage]
|
|
|
|
| 246 |
Render the prompt by making a call through the client.
|
| 247 |
|
| 248 |
|
| 249 |
+
### `FastMCPProxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L437" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 250 |
|
| 251 |
|
| 252 |
A FastMCP server that acts as a proxy to a remote MCP-compliant server.
|
| 253 |
It uses specialized managers that fulfill requests via a client factory.
|
| 254 |
|
| 255 |
|
| 256 |
+
### `ProxyClient` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L513" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 257 |
|
| 258 |
|
| 259 |
A proxy client that forwards advanced interactions between a remote MCP server and the proxy's connected clients.
|
|
|
|
| 262 |
|
| 263 |
**Methods:**
|
| 264 |
|
| 265 |
+
#### `default_sampling_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L544" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 266 |
|
| 267 |
```python
|
| 268 |
default_sampling_handler(cls, messages: list[mcp.types.SamplingMessage], params: mcp.types.CreateMessageRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> mcp.types.CreateMessageResult
|
|
|
|
| 271 |
A handler that forwards the sampling request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 272 |
|
| 273 |
|
| 274 |
+
#### `default_elicitation_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L570" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 275 |
|
| 276 |
```python
|
| 277 |
default_elicitation_handler(cls, message: str, response_type: type, params: mcp.types.ElicitRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> ElicitResult
|
|
|
|
| 280 |
A handler that forwards the elicitation request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 281 |
|
| 282 |
|
| 283 |
+
#### `default_log_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L589" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 284 |
|
| 285 |
```python
|
| 286 |
default_log_handler(cls, message: LogMessage) -> None
|
|
|
|
| 289 |
A handler that forwards the log notification from the remote server to the proxy's connected clients.
|
| 290 |
|
| 291 |
|
| 292 |
+
#### `default_progress_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L599" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 293 |
|
| 294 |
```python
|
| 295 |
default_progress_handler(cls, progress: float, total: float | None, message: str | None) -> None
|
|
|
|
| 298 |
A handler that forwards the progress notification from the remote server to the proxy's connected clients.
|
| 299 |
|
| 300 |
|
| 301 |
+
### `StatefulProxyClient` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L612" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 302 |
|
| 303 |
|
| 304 |
A proxy client that provides a stateful client factory for the proxy server.
|
|
|
|
| 312 |
|
| 313 |
**Methods:**
|
| 314 |
|
| 315 |
+
#### `clear` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L634" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 316 |
+
|
| 317 |
+
```python
|
| 318 |
+
clear(self)
|
| 319 |
+
```
|
| 320 |
+
|
| 321 |
+
Clear all cached clients and force disconnect them.
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
#### `new_stateful` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L642" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 325 |
|
| 326 |
```python
|
| 327 |
new_stateful(self) -> Client[ClientTransportT]
|
docs/python-sdk/fastmcp-server-server.mdx
CHANGED
|
@@ -10,7 +10,7 @@ FastMCP - A more ergonomic interface for MCP servers.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `default_lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]
|
|
@@ -26,7 +26,7 @@ Default lifespan context manager that does nothing.
|
|
| 26 |
- An empty context object
|
| 27 |
|
| 28 |
|
| 29 |
-
### `add_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 30 |
|
| 31 |
```python
|
| 32 |
add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -64,7 +64,7 @@ add_resource_prefix("resource:///absolute/path", "prefix")
|
|
| 64 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 65 |
|
| 66 |
|
| 67 |
-
### `remove_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 68 |
|
| 69 |
```python
|
| 70 |
remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -103,7 +103,7 @@ remove_resource_prefix("resource://prefix//absolute/path", "prefix")
|
|
| 103 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 104 |
|
| 105 |
|
| 106 |
-
### `has_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 107 |
|
| 108 |
```python
|
| 109 |
has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> bool
|
|
@@ -143,29 +143,29 @@ False
|
|
| 143 |
|
| 144 |
## Classes
|
| 145 |
|
| 146 |
-
### `FastMCP` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 147 |
|
| 148 |
**Methods:**
|
| 149 |
|
| 150 |
-
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 151 |
|
| 152 |
```python
|
| 153 |
settings(self) -> Settings
|
| 154 |
```
|
| 155 |
|
| 156 |
-
#### `name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 157 |
|
| 158 |
```python
|
| 159 |
name(self) -> str
|
| 160 |
```
|
| 161 |
|
| 162 |
-
#### `instructions` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 163 |
|
| 164 |
```python
|
| 165 |
instructions(self) -> str | None
|
| 166 |
```
|
| 167 |
|
| 168 |
-
#### `run_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 169 |
|
| 170 |
```python
|
| 171 |
run_async(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
@@ -177,7 +177,7 @@ Run the FastMCP server asynchronously.
|
|
| 177 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 178 |
|
| 179 |
|
| 180 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 181 |
|
| 182 |
```python
|
| 183 |
run(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
@@ -189,13 +189,13 @@ Run the FastMCP server. Note this is a synchronous function.
|
|
| 189 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 190 |
|
| 191 |
|
| 192 |
-
#### `add_middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 193 |
|
| 194 |
```python
|
| 195 |
add_middleware(self, middleware: Middleware) -> None
|
| 196 |
```
|
| 197 |
|
| 198 |
-
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 199 |
|
| 200 |
```python
|
| 201 |
get_tools(self) -> dict[str, Tool]
|
|
@@ -204,13 +204,13 @@ get_tools(self) -> dict[str, Tool]
|
|
| 204 |
Get all registered tools, indexed by registered key.
|
| 205 |
|
| 206 |
|
| 207 |
-
#### `get_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 208 |
|
| 209 |
```python
|
| 210 |
get_tool(self, key: str) -> Tool
|
| 211 |
```
|
| 212 |
|
| 213 |
-
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 214 |
|
| 215 |
```python
|
| 216 |
get_resources(self) -> dict[str, Resource]
|
|
@@ -219,13 +219,13 @@ get_resources(self) -> dict[str, Resource]
|
|
| 219 |
Get all registered resources, indexed by registered key.
|
| 220 |
|
| 221 |
|
| 222 |
-
#### `get_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 223 |
|
| 224 |
```python
|
| 225 |
get_resource(self, key: str) -> Resource
|
| 226 |
```
|
| 227 |
|
| 228 |
-
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 229 |
|
| 230 |
```python
|
| 231 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
@@ -234,7 +234,7 @@ get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
| 234 |
Get all registered resource templates, indexed by registered key.
|
| 235 |
|
| 236 |
|
| 237 |
-
#### `get_resource_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 238 |
|
| 239 |
```python
|
| 240 |
get_resource_template(self, key: str) -> ResourceTemplate
|
|
@@ -243,7 +243,7 @@ get_resource_template(self, key: str) -> ResourceTemplate
|
|
| 243 |
Get a registered resource template by key.
|
| 244 |
|
| 245 |
|
| 246 |
-
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 247 |
|
| 248 |
```python
|
| 249 |
get_prompts(self) -> dict[str, Prompt]
|
|
@@ -252,13 +252,13 @@ get_prompts(self) -> dict[str, Prompt]
|
|
| 252 |
List all available prompts.
|
| 253 |
|
| 254 |
|
| 255 |
-
#### `get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 256 |
|
| 257 |
```python
|
| 258 |
get_prompt(self, key: str) -> Prompt
|
| 259 |
```
|
| 260 |
|
| 261 |
-
#### `custom_route` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 262 |
|
| 263 |
```python
|
| 264 |
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True) -> Callable[[Callable[[Request], Awaitable[Response]]], Callable[[Request], Awaitable[Response]]]
|
|
@@ -279,7 +279,7 @@ Starlette's reverse URL lookup feature)
|
|
| 279 |
- `include_in_schema`: Whether to include in OpenAPI schema, defaults to True
|
| 280 |
|
| 281 |
|
| 282 |
-
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 283 |
|
| 284 |
```python
|
| 285 |
add_tool(self, tool: Tool) -> Tool
|
|
@@ -297,7 +297,7 @@ with the Context type annotation. See the @tool decorator for examples.
|
|
| 297 |
- The tool instance that was added to the server.
|
| 298 |
|
| 299 |
|
| 300 |
-
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 301 |
|
| 302 |
```python
|
| 303 |
remove_tool(self, name: str) -> None
|
|
@@ -312,7 +312,7 @@ Remove a tool from the server.
|
|
| 312 |
- `NotFoundError`: If the tool is not found
|
| 313 |
|
| 314 |
|
| 315 |
-
#### `add_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 316 |
|
| 317 |
```python
|
| 318 |
add_tool_transformation(self, tool_name: str, transformation: ToolTransformConfig) -> None
|
|
@@ -321,7 +321,7 @@ add_tool_transformation(self, tool_name: str, transformation: ToolTransformConfi
|
|
| 321 |
Add a tool transformation.
|
| 322 |
|
| 323 |
|
| 324 |
-
#### `remove_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 325 |
|
| 326 |
```python
|
| 327 |
remove_tool_transformation(self, tool_name: str) -> None
|
|
@@ -330,19 +330,19 @@ remove_tool_transformation(self, tool_name: str) -> None
|
|
| 330 |
Remove a tool transformation.
|
| 331 |
|
| 332 |
|
| 333 |
-
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 334 |
|
| 335 |
```python
|
| 336 |
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 337 |
```
|
| 338 |
|
| 339 |
-
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 340 |
|
| 341 |
```python
|
| 342 |
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 343 |
```
|
| 344 |
|
| 345 |
-
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 346 |
|
| 347 |
```python
|
| 348 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
@@ -369,6 +369,7 @@ This decorator supports multiple calling patterns:
|
|
| 369 |
- `output_schema`: Optional JSON schema for the tool's output
|
| 370 |
- `annotations`: Optional annotations about the tool's behavior
|
| 371 |
- `exclude_args`: Optional list of argument names to exclude from the tool schema
|
|
|
|
| 372 |
- `enabled`: Optional boolean to enable or disable the tool
|
| 373 |
|
| 374 |
**Examples:**
|
|
@@ -397,7 +398,7 @@ server.tool(my_function, name="custom_name")
|
|
| 397 |
```
|
| 398 |
|
| 399 |
|
| 400 |
-
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 401 |
|
| 402 |
```python
|
| 403 |
add_resource(self, resource: Resource) -> Resource
|
|
@@ -412,7 +413,7 @@ Add a resource to the server.
|
|
| 412 |
- The resource instance that was added to the server.
|
| 413 |
|
| 414 |
|
| 415 |
-
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 416 |
|
| 417 |
```python
|
| 418 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
|
@@ -427,7 +428,7 @@ Add a resource template to the server.
|
|
| 427 |
- The template instance that was added to the server.
|
| 428 |
|
| 429 |
|
| 430 |
-
#### `add_resource_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 431 |
|
| 432 |
```python
|
| 433 |
add_resource_fn(self, fn: AnyFunction, uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> None
|
|
@@ -447,7 +448,7 @@ has parameters, it will be registered as a template resource.
|
|
| 447 |
- `tags`: Optional set of tags for categorizing the resource
|
| 448 |
|
| 449 |
|
| 450 |
-
#### `resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 451 |
|
| 452 |
```python
|
| 453 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
@@ -475,6 +476,8 @@ has parameters, it will be registered as a template resource.
|
|
| 475 |
- `mime_type`: Optional MIME type for the resource
|
| 476 |
- `tags`: Optional set of tags for categorizing the resource
|
| 477 |
- `enabled`: Optional boolean to enable or disable the resource
|
|
|
|
|
|
|
| 478 |
|
| 479 |
**Examples:**
|
| 480 |
|
|
@@ -505,7 +508,7 @@ async def get_weather(city: str) -> str:
|
|
| 505 |
```
|
| 506 |
|
| 507 |
|
| 508 |
-
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 509 |
|
| 510 |
```python
|
| 511 |
add_prompt(self, prompt: Prompt) -> Prompt
|
|
@@ -520,19 +523,19 @@ Add a prompt to the server.
|
|
| 520 |
- The prompt instance that was added to the server.
|
| 521 |
|
| 522 |
|
| 523 |
-
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 524 |
|
| 525 |
```python
|
| 526 |
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 527 |
```
|
| 528 |
|
| 529 |
-
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 530 |
|
| 531 |
```python
|
| 532 |
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 533 |
```
|
| 534 |
|
| 535 |
-
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 536 |
|
| 537 |
```python
|
| 538 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
@@ -557,6 +560,7 @@ Decorator to register a prompt.
|
|
| 557 |
description: Optional description of what the prompt does
|
| 558 |
tags: Optional set of tags for categorizing the prompt
|
| 559 |
enabled: Optional boolean to enable or disable the prompt
|
|
|
|
| 560 |
|
| 561 |
Examples:
|
| 562 |
|
|
@@ -609,7 +613,7 @@ Decorator to register a prompt.
|
|
| 609 |
```
|
| 610 |
|
| 611 |
|
| 612 |
-
#### `run_stdio_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 613 |
|
| 614 |
```python
|
| 615 |
run_stdio_async(self, show_banner: bool = True) -> None
|
|
@@ -618,7 +622,7 @@ run_stdio_async(self, show_banner: bool = True) -> None
|
|
| 618 |
Run the server using stdio transport.
|
| 619 |
|
| 620 |
|
| 621 |
-
#### `run_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 622 |
|
| 623 |
```python
|
| 624 |
run_http_async(self, show_banner: bool = True, transport: Literal['http', 'streamable-http', 'sse'] = 'http', host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None, middleware: list[ASGIMiddleware] | None = None, stateless_http: bool | None = None) -> None
|
|
@@ -637,7 +641,7 @@ Run the server using HTTP transport.
|
|
| 637 |
- `stateless_http`: Whether to use stateless HTTP (defaults to settings.stateless_http)
|
| 638 |
|
| 639 |
|
| 640 |
-
#### `run_sse_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 641 |
|
| 642 |
```python
|
| 643 |
run_sse_async(self, host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None) -> None
|
|
@@ -646,7 +650,7 @@ run_sse_async(self, host: str | None = None, port: int | None = None, log_level:
|
|
| 646 |
Run the server using SSE transport.
|
| 647 |
|
| 648 |
|
| 649 |
-
#### `sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 650 |
|
| 651 |
```python
|
| 652 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -660,7 +664,7 @@ Create a Starlette app for the SSE server.
|
|
| 660 |
- `middleware`: A list of middleware to apply to the app
|
| 661 |
|
| 662 |
|
| 663 |
-
#### `streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 664 |
|
| 665 |
```python
|
| 666 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -673,7 +677,7 @@ Create a Starlette app for the StreamableHTTP server.
|
|
| 673 |
- `middleware`: A list of middleware to apply to the app
|
| 674 |
|
| 675 |
|
| 676 |
-
#### `http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 677 |
|
| 678 |
```python
|
| 679 |
http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None, json_response: bool | None = None, stateless_http: bool | None = None, transport: Literal['http', 'streamable-http', 'sse'] = 'http') -> StarletteWithLifespan
|
|
@@ -690,13 +694,13 @@ Create a Starlette app using the specified HTTP transport.
|
|
| 690 |
- A Starlette application configured with the specified transport
|
| 691 |
|
| 692 |
|
| 693 |
-
#### `run_streamable_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 694 |
|
| 695 |
```python
|
| 696 |
run_streamable_http_async(self, host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None) -> None
|
| 697 |
```
|
| 698 |
|
| 699 |
-
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 700 |
|
| 701 |
```python
|
| 702 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
@@ -750,7 +754,7 @@ automatically determined based on whether the server has a custom lifespan
|
|
| 750 |
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 751 |
|
| 752 |
|
| 753 |
-
#### `import_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 754 |
|
| 755 |
```python
|
| 756 |
import_server(self, server: FastMCP[LifespanResultT], prefix: str | None = None, tool_separator: str | None = None, resource_separator: str | None = None, prompt_separator: str | None = None) -> None
|
|
@@ -791,7 +795,7 @@ applied using the protocol\://prefix/path format
|
|
| 791 |
- `prompt_separator`: Deprecated. Separator for prompt names.
|
| 792 |
|
| 793 |
|
| 794 |
-
#### `from_openapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 795 |
|
| 796 |
```python
|
| 797 |
from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route_maps: list[RouteMap] | list[RouteMapNew] | None = None, route_map_fn: OpenAPIRouteMapFn | OpenAPIRouteMapFnNew | None = None, mcp_component_fn: OpenAPIComponentFn | OpenAPIComponentFnNew | None = None, mcp_names: dict[str, str] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI | FastMCPOpenAPINew
|
|
@@ -800,7 +804,7 @@ from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route
|
|
| 800 |
Create a FastMCP server from an OpenAPI specification.
|
| 801 |
|
| 802 |
|
| 803 |
-
#### `from_fastapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 804 |
|
| 805 |
```python
|
| 806 |
from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap] | list[RouteMapNew] | None = None, route_map_fn: OpenAPIRouteMapFn | OpenAPIRouteMapFnNew | None = None, mcp_component_fn: OpenAPIComponentFn | OpenAPIComponentFnNew | None = None, mcp_names: dict[str, str] | None = None, httpx_client_kwargs: dict[str, Any] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI | FastMCPOpenAPINew
|
|
@@ -809,7 +813,7 @@ from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap]
|
|
| 809 |
Create a FastMCP server from a FastAPI application.
|
| 810 |
|
| 811 |
|
| 812 |
-
#### `as_proxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 813 |
|
| 814 |
```python
|
| 815 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
@@ -823,7 +827,7 @@ instance or any value accepted as the `transport` argument of
|
|
| 823 |
`fastmcp.client.Client` constructor.
|
| 824 |
|
| 825 |
|
| 826 |
-
#### `from_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 827 |
|
| 828 |
```python
|
| 829 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
@@ -832,4 +836,4 @@ from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPPr
|
|
| 832 |
Create a FastMCP proxy server from a FastMCP client.
|
| 833 |
|
| 834 |
|
| 835 |
-
### `MountedServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `default_lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L96" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]
|
|
|
|
| 26 |
- An empty context object
|
| 27 |
|
| 28 |
|
| 29 |
+
### `add_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2155" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 30 |
|
| 31 |
```python
|
| 32 |
add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
|
|
| 64 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 65 |
|
| 66 |
|
| 67 |
+
### `remove_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2215" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 68 |
|
| 69 |
```python
|
| 70 |
remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
|
|
| 103 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 104 |
|
| 105 |
|
| 106 |
+
### `has_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2282" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 107 |
|
| 108 |
```python
|
| 109 |
has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> bool
|
|
|
|
| 143 |
|
| 144 |
## Classes
|
| 145 |
|
| 146 |
+
### `FastMCP` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 147 |
|
| 148 |
**Methods:**
|
| 149 |
|
| 150 |
+
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L289" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 151 |
|
| 152 |
```python
|
| 153 |
settings(self) -> Settings
|
| 154 |
```
|
| 155 |
|
| 156 |
+
#### `name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L300" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 157 |
|
| 158 |
```python
|
| 159 |
name(self) -> str
|
| 160 |
```
|
| 161 |
|
| 162 |
+
#### `instructions` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L304" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 163 |
|
| 164 |
```python
|
| 165 |
instructions(self) -> str | None
|
| 166 |
```
|
| 167 |
|
| 168 |
+
#### `run_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L307" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 169 |
|
| 170 |
```python
|
| 171 |
run_async(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
|
|
| 177 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 178 |
|
| 179 |
|
| 180 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L337" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 181 |
|
| 182 |
```python
|
| 183 |
run(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
|
|
| 189 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 190 |
|
| 191 |
|
| 192 |
+
#### `add_middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L379" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 193 |
|
| 194 |
```python
|
| 195 |
add_middleware(self, middleware: Middleware) -> None
|
| 196 |
```
|
| 197 |
|
| 198 |
+
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L382" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 199 |
|
| 200 |
```python
|
| 201 |
get_tools(self) -> dict[str, Tool]
|
|
|
|
| 204 |
Get all registered tools, indexed by registered key.
|
| 205 |
|
| 206 |
|
| 207 |
+
#### `get_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L386" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 208 |
|
| 209 |
```python
|
| 210 |
get_tool(self, key: str) -> Tool
|
| 211 |
```
|
| 212 |
|
| 213 |
+
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L392" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 214 |
|
| 215 |
```python
|
| 216 |
get_resources(self) -> dict[str, Resource]
|
|
|
|
| 219 |
Get all registered resources, indexed by registered key.
|
| 220 |
|
| 221 |
|
| 222 |
+
#### `get_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L396" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 223 |
|
| 224 |
```python
|
| 225 |
get_resource(self, key: str) -> Resource
|
| 226 |
```
|
| 227 |
|
| 228 |
+
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L402" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 229 |
|
| 230 |
```python
|
| 231 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
|
|
| 234 |
Get all registered resource templates, indexed by registered key.
|
| 235 |
|
| 236 |
|
| 237 |
+
#### `get_resource_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L406" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 238 |
|
| 239 |
```python
|
| 240 |
get_resource_template(self, key: str) -> ResourceTemplate
|
|
|
|
| 243 |
Get a registered resource template by key.
|
| 244 |
|
| 245 |
|
| 246 |
+
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L413" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 247 |
|
| 248 |
```python
|
| 249 |
get_prompts(self) -> dict[str, Prompt]
|
|
|
|
| 252 |
List all available prompts.
|
| 253 |
|
| 254 |
|
| 255 |
+
#### `get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L419" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 256 |
|
| 257 |
```python
|
| 258 |
get_prompt(self, key: str) -> Prompt
|
| 259 |
```
|
| 260 |
|
| 261 |
+
#### `custom_route` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L425" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 262 |
|
| 263 |
```python
|
| 264 |
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True) -> Callable[[Callable[[Request], Awaitable[Response]]], Callable[[Request], Awaitable[Response]]]
|
|
|
|
| 279 |
- `include_in_schema`: Whether to include in OpenAPI schema, defaults to True
|
| 280 |
|
| 281 |
|
| 282 |
+
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L805" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 283 |
|
| 284 |
```python
|
| 285 |
add_tool(self, tool: Tool) -> Tool
|
|
|
|
| 297 |
- The tool instance that was added to the server.
|
| 298 |
|
| 299 |
|
| 300 |
+
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L830" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 301 |
|
| 302 |
```python
|
| 303 |
remove_tool(self, name: str) -> None
|
|
|
|
| 312 |
- `NotFoundError`: If the tool is not found
|
| 313 |
|
| 314 |
|
| 315 |
+
#### `add_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L850" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 316 |
|
| 317 |
```python
|
| 318 |
add_tool_transformation(self, tool_name: str, transformation: ToolTransformConfig) -> None
|
|
|
|
| 321 |
Add a tool transformation.
|
| 322 |
|
| 323 |
|
| 324 |
+
#### `remove_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L856" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 325 |
|
| 326 |
```python
|
| 327 |
remove_tool_transformation(self, tool_name: str) -> None
|
|
|
|
| 330 |
Remove a tool transformation.
|
| 331 |
|
| 332 |
|
| 333 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L861" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 334 |
|
| 335 |
```python
|
| 336 |
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 337 |
```
|
| 338 |
|
| 339 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L877" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 340 |
|
| 341 |
```python
|
| 342 |
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 343 |
```
|
| 344 |
|
| 345 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L892" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 346 |
|
| 347 |
```python
|
| 348 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
|
|
| 369 |
- `output_schema`: Optional JSON schema for the tool's output
|
| 370 |
- `annotations`: Optional annotations about the tool's behavior
|
| 371 |
- `exclude_args`: Optional list of argument names to exclude from the tool schema
|
| 372 |
+
- `meta`: Optional meta information about the tool
|
| 373 |
- `enabled`: Optional boolean to enable or disable the tool
|
| 374 |
|
| 375 |
**Examples:**
|
|
|
|
| 398 |
```
|
| 399 |
|
| 400 |
|
| 401 |
+
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1023" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 402 |
|
| 403 |
```python
|
| 404 |
add_resource(self, resource: Resource) -> Resource
|
|
|
|
| 413 |
- The resource instance that was added to the server.
|
| 414 |
|
| 415 |
|
| 416 |
+
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1045" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 417 |
|
| 418 |
```python
|
| 419 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
|
|
|
| 428 |
- The template instance that was added to the server.
|
| 429 |
|
| 430 |
|
| 431 |
+
#### `add_resource_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1067" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 432 |
|
| 433 |
```python
|
| 434 |
add_resource_fn(self, fn: AnyFunction, uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> None
|
|
|
|
| 448 |
- `tags`: Optional set of tags for categorizing the resource
|
| 449 |
|
| 450 |
|
| 451 |
+
#### `resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1105" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 452 |
|
| 453 |
```python
|
| 454 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
|
|
| 476 |
- `mime_type`: Optional MIME type for the resource
|
| 477 |
- `tags`: Optional set of tags for categorizing the resource
|
| 478 |
- `enabled`: Optional boolean to enable or disable the resource
|
| 479 |
+
- `annotations`: Optional annotations about the resource's behavior
|
| 480 |
+
- `meta`: Optional meta information about the resource
|
| 481 |
|
| 482 |
**Examples:**
|
| 483 |
|
|
|
|
| 508 |
```
|
| 509 |
|
| 510 |
|
| 511 |
+
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1242" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 512 |
|
| 513 |
```python
|
| 514 |
add_prompt(self, prompt: Prompt) -> Prompt
|
|
|
|
| 523 |
- The prompt instance that was added to the server.
|
| 524 |
|
| 525 |
|
| 526 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1265" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 527 |
|
| 528 |
```python
|
| 529 |
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 530 |
```
|
| 531 |
|
| 532 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1278" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 533 |
|
| 534 |
```python
|
| 535 |
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 536 |
```
|
| 537 |
|
| 538 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1290" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 539 |
|
| 540 |
```python
|
| 541 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
|
|
| 560 |
description: Optional description of what the prompt does
|
| 561 |
tags: Optional set of tags for categorizing the prompt
|
| 562 |
enabled: Optional boolean to enable or disable the prompt
|
| 563 |
+
meta: Optional meta information about the prompt
|
| 564 |
|
| 565 |
Examples:
|
| 566 |
|
|
|
|
| 613 |
```
|
| 614 |
|
| 615 |
|
| 616 |
+
#### `run_stdio_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1431" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 617 |
|
| 618 |
```python
|
| 619 |
run_stdio_async(self, show_banner: bool = True) -> None
|
|
|
|
| 622 |
Run the server using stdio transport.
|
| 623 |
|
| 624 |
|
| 625 |
+
#### `run_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1451" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 626 |
|
| 627 |
```python
|
| 628 |
run_http_async(self, show_banner: bool = True, transport: Literal['http', 'streamable-http', 'sse'] = 'http', host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None, middleware: list[ASGIMiddleware] | None = None, stateless_http: bool | None = None) -> None
|
|
|
|
| 641 |
- `stateless_http`: Whether to use stateless HTTP (defaults to settings.stateless_http)
|
| 642 |
|
| 643 |
|
| 644 |
+
#### `run_sse_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1525" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 645 |
|
| 646 |
```python
|
| 647 |
run_sse_async(self, host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None) -> None
|
|
|
|
| 650 |
Run the server using SSE transport.
|
| 651 |
|
| 652 |
|
| 653 |
+
#### `sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1553" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 654 |
|
| 655 |
```python
|
| 656 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 664 |
- `middleware`: A list of middleware to apply to the app
|
| 665 |
|
| 666 |
|
| 667 |
+
#### `streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1584" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 668 |
|
| 669 |
```python
|
| 670 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 677 |
- `middleware`: A list of middleware to apply to the app
|
| 678 |
|
| 679 |
|
| 680 |
+
#### `http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1605" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 681 |
|
| 682 |
```python
|
| 683 |
http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None, json_response: bool | None = None, stateless_http: bool | None = None, transport: Literal['http', 'streamable-http', 'sse'] = 'http') -> StarletteWithLifespan
|
|
|
|
| 694 |
- A Starlette application configured with the specified transport
|
| 695 |
|
| 696 |
|
| 697 |
+
#### `run_streamable_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1654" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 698 |
|
| 699 |
```python
|
| 700 |
run_streamable_http_async(self, host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None) -> None
|
| 701 |
```
|
| 702 |
|
| 703 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1679" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 704 |
|
| 705 |
```python
|
| 706 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
|
|
| 754 |
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 755 |
|
| 756 |
|
| 757 |
+
#### `import_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1800" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 758 |
|
| 759 |
```python
|
| 760 |
import_server(self, server: FastMCP[LifespanResultT], prefix: str | None = None, tool_separator: str | None = None, resource_separator: str | None = None, prompt_separator: str | None = None) -> None
|
|
|
|
| 795 |
- `prompt_separator`: Deprecated. Separator for prompt names.
|
| 796 |
|
| 797 |
|
| 798 |
+
#### `from_openapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1923" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 799 |
|
| 800 |
```python
|
| 801 |
from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route_maps: list[RouteMap] | list[RouteMapNew] | None = None, route_map_fn: OpenAPIRouteMapFn | OpenAPIRouteMapFnNew | None = None, mcp_component_fn: OpenAPIComponentFn | OpenAPIComponentFnNew | None = None, mcp_names: dict[str, str] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI | FastMCPOpenAPINew
|
|
|
|
| 804 |
Create a FastMCP server from an OpenAPI specification.
|
| 805 |
|
| 806 |
|
| 807 |
+
#### `from_fastapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1972" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 808 |
|
| 809 |
```python
|
| 810 |
from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap] | list[RouteMapNew] | None = None, route_map_fn: OpenAPIRouteMapFn | OpenAPIRouteMapFnNew | None = None, mcp_component_fn: OpenAPIComponentFn | OpenAPIComponentFnNew | None = None, mcp_names: dict[str, str] | None = None, httpx_client_kwargs: dict[str, Any] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI | FastMCPOpenAPINew
|
|
|
|
| 813 |
Create a FastMCP server from a FastAPI application.
|
| 814 |
|
| 815 |
|
| 816 |
+
#### `as_proxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2035" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 817 |
|
| 818 |
```python
|
| 819 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
|
|
| 827 |
`fastmcp.client.Client` constructor.
|
| 828 |
|
| 829 |
|
| 830 |
+
#### `from_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2096" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 831 |
|
| 832 |
```python
|
| 833 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
|
|
| 836 |
Create a FastMCP proxy server from a FastMCP client.
|
| 837 |
|
| 838 |
|
| 839 |
+
### `MountedServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2149" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
docs/python-sdk/fastmcp-tools-tool.mdx
CHANGED
|
@@ -51,16 +51,16 @@ disable(self) -> None
|
|
| 51 |
to_mcp_tool(self, **overrides: Any) -> MCPTool
|
| 52 |
```
|
| 53 |
|
| 54 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 55 |
|
| 56 |
```python
|
| 57 |
-
from_function(fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | None | NotSetT | Literal[False] = NotSet, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 58 |
```
|
| 59 |
|
| 60 |
Create a Tool from a function.
|
| 61 |
|
| 62 |
|
| 63 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 64 |
|
| 65 |
```python
|
| 66 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -75,26 +75,26 @@ implemented by subclasses.
|
|
| 75 |
(list of ContentBlocks, dict of structured output).
|
| 76 |
|
| 77 |
|
| 78 |
-
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 79 |
|
| 80 |
```python
|
| 81 |
-
from_tool(cls, tool: Tool, transform_fn: Callable[..., Any] | None = None, name: str | None = None, title: str | None | NotSetT = NotSet, transform_args: dict[str, ArgTransform] | None = None, description: str | None | NotSetT = NotSet, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, output_schema: dict[str, Any] | None | Literal[False] = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
| 82 |
```
|
| 83 |
|
| 84 |
-
### `FunctionTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 85 |
|
| 86 |
**Methods:**
|
| 87 |
|
| 88 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 89 |
|
| 90 |
```python
|
| 91 |
-
from_function(cls, fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | None | NotSetT | Literal[False] = NotSet, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 92 |
```
|
| 93 |
|
| 94 |
Create a Tool from a function.
|
| 95 |
|
| 96 |
|
| 97 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 98 |
|
| 99 |
```python
|
| 100 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -103,11 +103,11 @@ run(self, arguments: dict[str, Any]) -> ToolResult
|
|
| 103 |
Run the tool with arguments.
|
| 104 |
|
| 105 |
|
| 106 |
-
### `ParsedFunction` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 107 |
|
| 108 |
**Methods:**
|
| 109 |
|
| 110 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 111 |
|
| 112 |
```python
|
| 113 |
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True, wrap_non_object_output_schema: bool = True) -> ParsedFunction
|
|
|
|
| 51 |
to_mcp_tool(self, **overrides: Any) -> MCPTool
|
| 52 |
```
|
| 53 |
|
| 54 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L158" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 55 |
|
| 56 |
```python
|
| 57 |
+
from_function(fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | None | NotSetT | Literal[False] = NotSet, serializer: Callable[[Any], str] | None = None, meta: dict[str, Any] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 58 |
```
|
| 59 |
|
| 60 |
Create a Tool from a function.
|
| 61 |
|
| 62 |
|
| 63 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L186" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
|
| 65 |
```python
|
| 66 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 75 |
(list of ContentBlocks, dict of structured output).
|
| 76 |
|
| 77 |
|
| 78 |
+
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L199" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 79 |
|
| 80 |
```python
|
| 81 |
+
from_tool(cls, tool: Tool, transform_fn: Callable[..., Any] | None = None, name: str | None = None, title: str | None | NotSetT = NotSet, transform_args: dict[str, ArgTransform] | None = None, description: str | None | NotSetT = NotSet, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, output_schema: dict[str, Any] | None | Literal[False] = None, serializer: Callable[[Any], str] | None = None, meta: dict[str, Any] | None | NotSetT = NotSet, enabled: bool | None = None) -> TransformedTool
|
| 82 |
```
|
| 83 |
|
| 84 |
+
### `FunctionTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L232" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 85 |
|
| 86 |
**Methods:**
|
| 87 |
|
| 88 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L236" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 89 |
|
| 90 |
```python
|
| 91 |
+
from_function(cls, fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | None | NotSetT | Literal[False] = NotSet, serializer: Callable[[Any], str] | None = None, meta: dict[str, Any] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 92 |
```
|
| 93 |
|
| 94 |
Create a Tool from a function.
|
| 95 |
|
| 96 |
|
| 97 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L284" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 98 |
|
| 99 |
```python
|
| 100 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 103 |
Run the tool with arguments.
|
| 104 |
|
| 105 |
|
| 106 |
+
### `ParsedFunction` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L330" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 107 |
|
| 108 |
**Methods:**
|
| 109 |
|
| 110 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L338" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 111 |
|
| 112 |
```python
|
| 113 |
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True, wrap_non_object_output_schema: bool = True) -> ParsedFunction
|
docs/python-sdk/fastmcp-tools-tool_transform.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: tool_transform
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `forward` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
forward(**kwargs) -> ToolResult
|
|
@@ -36,7 +36,7 @@ tool has args `a` and `b`, and an `transform_args` was provided that maps `x` to
|
|
| 36 |
- `TypeError`: If provided arguments don't match the transformed schema.
|
| 37 |
|
| 38 |
|
| 39 |
-
### `forward_raw` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 40 |
|
| 41 |
```python
|
| 42 |
forward_raw(**kwargs) -> ToolResult
|
|
@@ -62,7 +62,7 @@ y=2)` will call the parent tool with `x=1` and `y=2`.
|
|
| 62 |
- `RuntimeError`: If called outside a transformed tool context.
|
| 63 |
|
| 64 |
|
| 65 |
-
### `apply_transformations_to_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 66 |
|
| 67 |
```python
|
| 68 |
apply_transformations_to_tools(tools: dict[str, Tool], transformations: dict[str, ToolTransformConfig]) -> dict[str, Tool]
|
|
@@ -75,7 +75,7 @@ are left unchanged.
|
|
| 75 |
|
| 76 |
## Classes
|
| 77 |
|
| 78 |
-
### `ArgTransform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 79 |
|
| 80 |
|
| 81 |
Configuration for transforming a parent tool's argument.
|
|
@@ -137,7 +137,7 @@ ArgTransform(name="new_name", description="New desc", default=None, type=int)
|
|
| 137 |
```
|
| 138 |
|
| 139 |
|
| 140 |
-
### `ArgTransformConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 141 |
|
| 142 |
|
| 143 |
A model for requesting a single argument transform.
|
|
@@ -145,7 +145,7 @@ A model for requesting a single argument transform.
|
|
| 145 |
|
| 146 |
**Methods:**
|
| 147 |
|
| 148 |
-
#### `to_arg_transform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 149 |
|
| 150 |
```python
|
| 151 |
to_arg_transform(self) -> ArgTransform
|
|
@@ -154,7 +154,7 @@ to_arg_transform(self) -> ArgTransform
|
|
| 154 |
Convert the argument transform to a FastMCP argument transform.
|
| 155 |
|
| 156 |
|
| 157 |
-
### `TransformedTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 158 |
|
| 159 |
|
| 160 |
A tool that is transformed from another tool.
|
|
@@ -171,7 +171,7 @@ inherited from the parent tool but can be overridden or disabled.
|
|
| 171 |
|
| 172 |
**Methods:**
|
| 173 |
|
| 174 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 175 |
|
| 176 |
```python
|
| 177 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -190,10 +190,10 @@ functions.
|
|
| 190 |
- ToolResult object containing content and optional structured output.
|
| 191 |
|
| 192 |
|
| 193 |
-
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 194 |
|
| 195 |
```python
|
| 196 |
-
from_tool(cls, tool: Tool, name: str | None = None, title: str | None | NotSetT = NotSet, description: str | None | NotSetT = NotSet, tags: set[str] | None = None, transform_fn: Callable[..., Any] | None = None, transform_args: dict[str, ArgTransform] | None = None, annotations: ToolAnnotations | None = None, output_schema: dict[str, Any] | None | Literal[False] = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
| 197 |
```
|
| 198 |
|
| 199 |
Create a transformed tool from a parent tool.
|
|
@@ -218,6 +218,10 @@ Only specified arguments are transformed, others pass through unchanged\:
|
|
| 218 |
- dict\: Use custom output schema
|
| 219 |
- False\: Disable output schema and structured outputs
|
| 220 |
- `serializer`: New serializer. Defaults to parent's serializer.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
**Returns:**
|
| 223 |
- TransformedTool with the specified transformations.
|
|
@@ -268,7 +272,7 @@ async def custom_output(**kwargs) -> ToolResult:
|
|
| 268 |
```
|
| 269 |
|
| 270 |
|
| 271 |
-
### `ToolTransformConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 272 |
|
| 273 |
|
| 274 |
Provides a way to transform a tool.
|
|
@@ -276,7 +280,7 @@ Provides a way to transform a tool.
|
|
| 276 |
|
| 277 |
**Methods:**
|
| 278 |
|
| 279 |
-
#### `apply` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 280 |
|
| 281 |
```python
|
| 282 |
apply(self, tool: Tool) -> TransformedTool
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `forward` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L34" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
forward(**kwargs) -> ToolResult
|
|
|
|
| 36 |
- `TypeError`: If provided arguments don't match the transformed schema.
|
| 37 |
|
| 38 |
|
| 39 |
+
### `forward_raw` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L64" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
forward_raw(**kwargs) -> ToolResult
|
|
|
|
| 62 |
- `RuntimeError`: If called outside a transformed tool context.
|
| 63 |
|
| 64 |
|
| 65 |
+
### `apply_transformations_to_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L890" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 66 |
|
| 67 |
```python
|
| 68 |
apply_transformations_to_tools(tools: dict[str, Tool], transformations: dict[str, ToolTransformConfig]) -> dict[str, Tool]
|
|
|
|
| 75 |
|
| 76 |
## Classes
|
| 77 |
|
| 78 |
+
### `ArgTransform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L91" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 79 |
|
| 80 |
|
| 81 |
Configuration for transforming a parent tool's argument.
|
|
|
|
| 137 |
```
|
| 138 |
|
| 139 |
|
| 140 |
+
### `ArgTransformConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L205" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 141 |
|
| 142 |
|
| 143 |
A model for requesting a single argument transform.
|
|
|
|
| 145 |
|
| 146 |
**Methods:**
|
| 147 |
|
| 148 |
+
#### `to_arg_transform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L223" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 149 |
|
| 150 |
```python
|
| 151 |
to_arg_transform(self) -> ArgTransform
|
|
|
|
| 154 |
Convert the argument transform to a FastMCP argument transform.
|
| 155 |
|
| 156 |
|
| 157 |
+
### `TransformedTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L229" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 158 |
|
| 159 |
|
| 160 |
A tool that is transformed from another tool.
|
|
|
|
| 171 |
|
| 172 |
**Methods:**
|
| 173 |
|
| 174 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L256" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 175 |
|
| 176 |
```python
|
| 177 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 190 |
- ToolResult object containing content and optional structured output.
|
| 191 |
|
| 192 |
|
| 193 |
+
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L357" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 194 |
|
| 195 |
```python
|
| 196 |
+
from_tool(cls, tool: Tool, name: str | None = None, title: str | None | NotSetT = NotSet, description: str | None | NotSetT = NotSet, tags: set[str] | None = None, transform_fn: Callable[..., Any] | None = None, transform_args: dict[str, ArgTransform] | None = None, annotations: ToolAnnotations | None = None, output_schema: dict[str, Any] | None | Literal[False] = None, serializer: Callable[[Any], str] | None = None, meta: dict[str, Any] | None | NotSetT = NotSet, enabled: bool | None = None) -> TransformedTool
|
| 197 |
```
|
| 198 |
|
| 199 |
Create a transformed tool from a parent tool.
|
|
|
|
| 218 |
- dict\: Use custom output schema
|
| 219 |
- False\: Disable output schema and structured outputs
|
| 220 |
- `serializer`: New serializer. Defaults to parent's serializer.
|
| 221 |
+
- `meta`: Control meta information\:
|
| 222 |
+
- NotSet (default)\: Inherit from parent tool
|
| 223 |
+
- dict\: Use custom meta information
|
| 224 |
+
- None\: Remove meta information
|
| 225 |
|
| 226 |
**Returns:**
|
| 227 |
- TransformedTool with the specified transformations.
|
|
|
|
| 272 |
```
|
| 273 |
|
| 274 |
|
| 275 |
+
### `ToolTransformConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L844" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 276 |
|
| 277 |
|
| 278 |
Provides a way to transform a tool.
|
|
|
|
| 280 |
|
| 281 |
**Methods:**
|
| 282 |
|
| 283 |
+
#### `apply` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L876" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 284 |
|
| 285 |
```python
|
| 286 |
apply(self, tool: Tool) -> TransformedTool
|
docs/python-sdk/fastmcp-utilities-components.mdx
CHANGED
|
@@ -7,7 +7,9 @@ sidebarTitle: components
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
Base class for FastMCP tools, prompts, resources, and resource templates.
|
|
@@ -15,7 +17,7 @@ Base class for FastMCP tools, prompts, resources, and resource templates.
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
-
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 19 |
|
| 20 |
```python
|
| 21 |
key(self) -> str
|
|
@@ -27,13 +29,25 @@ keys having a certain value, as the same tool loaded from different
|
|
| 27 |
hierarchies of servers may have different keys.
|
| 28 |
|
| 29 |
|
| 30 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
```python
|
| 33 |
with_key(self, key: str) -> Self
|
| 34 |
```
|
| 35 |
|
| 36 |
-
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
enable(self) -> None
|
|
@@ -42,7 +56,7 @@ enable(self) -> None
|
|
| 42 |
Enable the component.
|
| 43 |
|
| 44 |
|
| 45 |
-
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 46 |
|
| 47 |
```python
|
| 48 |
disable(self) -> None
|
|
@@ -51,7 +65,7 @@ disable(self) -> None
|
|
| 51 |
Disable the component.
|
| 52 |
|
| 53 |
|
| 54 |
-
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 55 |
|
| 56 |
```python
|
| 57 |
copy(self) -> Self
|
|
@@ -60,7 +74,7 @@ copy(self) -> Self
|
|
| 60 |
Create a copy of the component.
|
| 61 |
|
| 62 |
|
| 63 |
-
### `MirroredComponent` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 64 |
|
| 65 |
|
| 66 |
Base class for components that are mirrored from a remote server.
|
|
@@ -71,7 +85,7 @@ to create a local version you can modify.
|
|
| 71 |
|
| 72 |
**Methods:**
|
| 73 |
|
| 74 |
-
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 75 |
|
| 76 |
```python
|
| 77 |
enable(self) -> None
|
|
@@ -80,7 +94,7 @@ enable(self) -> None
|
|
| 80 |
Enable the component.
|
| 81 |
|
| 82 |
|
| 83 |
-
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 84 |
|
| 85 |
```python
|
| 86 |
disable(self) -> None
|
|
@@ -89,7 +103,7 @@ disable(self) -> None
|
|
| 89 |
Disable the component.
|
| 90 |
|
| 91 |
|
| 92 |
-
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#
|
| 93 |
|
| 94 |
```python
|
| 95 |
copy(self) -> Self
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `FastMCPMeta` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L15" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
### `FastMCPComponent` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L28" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 13 |
|
| 14 |
|
| 15 |
Base class for FastMCP tools, prompts, resources, and resource templates.
|
|
|
|
| 17 |
|
| 18 |
**Methods:**
|
| 19 |
|
| 20 |
+
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L61" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 21 |
|
| 22 |
```python
|
| 23 |
key(self) -> str
|
|
|
|
| 29 |
hierarchies of servers may have different keys.
|
| 30 |
|
| 31 |
|
| 32 |
+
#### `get_meta` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L70" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
get_meta(self, include_fastmcp_meta: bool | None = None) -> dict[str, Any] | None
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
Get the meta information about the component.
|
| 39 |
+
|
| 40 |
+
If include_fastmcp_meta is True, a `_fastmcp` key will be added to the
|
| 41 |
+
meta, containing a `tags` field with the tags of the component.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
#### `with_key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L94" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 45 |
|
| 46 |
```python
|
| 47 |
with_key(self, key: str) -> Self
|
| 48 |
```
|
| 49 |
|
| 50 |
+
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L106" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 51 |
|
| 52 |
```python
|
| 53 |
enable(self) -> None
|
|
|
|
| 56 |
Enable the component.
|
| 57 |
|
| 58 |
|
| 59 |
+
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 60 |
|
| 61 |
```python
|
| 62 |
disable(self) -> None
|
|
|
|
| 65 |
Disable the component.
|
| 66 |
|
| 67 |
|
| 68 |
+
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L114" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 69 |
|
| 70 |
```python
|
| 71 |
copy(self) -> Self
|
|
|
|
| 74 |
Create a copy of the component.
|
| 75 |
|
| 76 |
|
| 77 |
+
### `MirroredComponent` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L119" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 78 |
|
| 79 |
|
| 80 |
Base class for components that are mirrored from a remote server.
|
|
|
|
| 85 |
|
| 86 |
**Methods:**
|
| 87 |
|
| 88 |
+
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L132" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 89 |
|
| 90 |
```python
|
| 91 |
enable(self) -> None
|
|
|
|
| 94 |
Enable the component.
|
| 95 |
|
| 96 |
|
| 97 |
+
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L141" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 98 |
|
| 99 |
```python
|
| 100 |
disable(self) -> None
|
|
|
|
| 103 |
Disable the component.
|
| 104 |
|
| 105 |
|
| 106 |
+
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L150" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 107 |
|
| 108 |
```python
|
| 109 |
copy(self) -> Self
|
docs/python-sdk/fastmcp-utilities-mcp_config.mdx
CHANGED
|
@@ -7,20 +7,20 @@ sidebarTitle: mcp_config
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `composite_server_from_mcp_config` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
-
composite_server_from_mcp_config(config: MCPConfig, name_as_prefix: bool = True) -> FastMCP
|
| 14 |
```
|
| 15 |
|
| 16 |
|
| 17 |
A utility function to create a composite server from an MCPConfig.
|
| 18 |
|
| 19 |
|
| 20 |
-
### `mount_mcp_config_into_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#
|
| 21 |
|
| 22 |
```python
|
| 23 |
-
mount_mcp_config_into_server(config: MCPConfig, server: FastMCP, name_as_prefix: bool = True) -> None
|
| 24 |
```
|
| 25 |
|
| 26 |
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `composite_server_from_mcp_config` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L7" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
+
composite_server_from_mcp_config(config: MCPConfig, name_as_prefix: bool = True) -> FastMCP[None]
|
| 14 |
```
|
| 15 |
|
| 16 |
|
| 17 |
A utility function to create a composite server from an MCPConfig.
|
| 18 |
|
| 19 |
|
| 20 |
+
### `mount_mcp_config_into_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L18" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 21 |
|
| 22 |
```python
|
| 23 |
+
mount_mcp_config_into_server(config: MCPConfig, server: FastMCP[Any], name_as_prefix: bool = True) -> None
|
| 24 |
```
|
| 25 |
|
| 26 |
|
docs/python-sdk/fastmcp-utilities-openapi.mdx
CHANGED
|
@@ -47,7 +47,7 @@ For example: `{"id": "123", "type": "user"}` becomes `param[id]=123¶m[type]=
|
|
| 47 |
- Dictionary with bracketed parameter names as keys
|
| 48 |
|
| 49 |
|
| 50 |
-
### `parse_openapi_to_http_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 51 |
|
| 52 |
```python
|
| 53 |
parse_openapi_to_http_routes(openapi_dict: dict[str, Any]) -> list[HTTPRoute]
|
|
@@ -60,7 +60,7 @@ using the openapi-pydantic library.
|
|
| 60 |
Supports both OpenAPI 3.0.x and 3.1.x versions.
|
| 61 |
|
| 62 |
|
| 63 |
-
### `clean_schema_for_display` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 64 |
|
| 65 |
```python
|
| 66 |
clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
@@ -70,7 +70,7 @@ clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
| 70 |
Clean up a schema dictionary for display by removing internal/complex fields.
|
| 71 |
|
| 72 |
|
| 73 |
-
### `generate_example_from_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 74 |
|
| 75 |
```python
|
| 76 |
generate_example_from_schema(schema: JsonSchema | None) -> Any
|
|
@@ -81,7 +81,7 @@ Generate a simple example value from a JSON schema dictionary.
|
|
| 81 |
Very basic implementation focusing on types.
|
| 82 |
|
| 83 |
|
| 84 |
-
### `format_json_for_description` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 85 |
|
| 86 |
```python
|
| 87 |
format_json_for_description(data: Any, indent: int = 2) -> str
|
|
@@ -91,7 +91,7 @@ format_json_for_description(data: Any, indent: int = 2) -> str
|
|
| 91 |
Formats Python data as a JSON string block for markdown.
|
| 92 |
|
| 93 |
|
| 94 |
-
### `format_description_with_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 95 |
|
| 96 |
```python
|
| 97 |
format_description_with_responses(base_description: str, responses: dict[str, Any], parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
|
|
@@ -114,10 +114,10 @@ including its description, whether it is required, and its content schema.
|
|
| 114 |
- and the request body.
|
| 115 |
|
| 116 |
|
| 117 |
-
### `extract_output_schema_from_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 118 |
|
| 119 |
```python
|
| 120 |
-
extract_output_schema_from_responses(responses: dict[str, ResponseInfo], schema_definitions: dict[str, Any] | None = None) -> dict[str, Any] | None
|
| 121 |
```
|
| 122 |
|
| 123 |
|
|
@@ -130,6 +130,7 @@ object type, it wraps it to comply with MCP requirements.
|
|
| 130 |
**Args:**
|
| 131 |
- `responses`: Dictionary of ResponseInfo objects keyed by status code
|
| 132 |
- `schema_definitions`: Optional schema definitions to include in the output schema
|
|
|
|
| 133 |
|
| 134 |
**Returns:**
|
| 135 |
- MCP-compliant output schema with potential wrapping, or None if no suitable schema found
|
|
@@ -161,7 +162,7 @@ Represents response information in our IR.
|
|
| 161 |
Intermediate Representation for a single OpenAPI operation.
|
| 162 |
|
| 163 |
|
| 164 |
-
### `OpenAPIParser` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 165 |
|
| 166 |
|
| 167 |
Unified parser for OpenAPI schemas with generic type parameters to handle both 3.0 and 3.1.
|
|
@@ -169,7 +170,7 @@ Unified parser for OpenAPI schemas with generic type parameters to handle both 3
|
|
| 169 |
|
| 170 |
**Methods:**
|
| 171 |
|
| 172 |
-
#### `parse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 173 |
|
| 174 |
```python
|
| 175 |
parse(self) -> list[HTTPRoute]
|
|
|
|
| 47 |
- Dictionary with bracketed parameter names as keys
|
| 48 |
|
| 49 |
|
| 50 |
+
### `parse_openapi_to_http_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L205" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 51 |
|
| 52 |
```python
|
| 53 |
parse_openapi_to_http_routes(openapi_dict: dict[str, Any]) -> list[HTTPRoute]
|
|
|
|
| 60 |
Supports both OpenAPI 3.0.x and 3.1.x versions.
|
| 61 |
|
| 62 |
|
| 63 |
+
### `clean_schema_for_display` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L745" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
|
| 65 |
```python
|
| 66 |
clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
|
|
| 70 |
Clean up a schema dictionary for display by removing internal/complex fields.
|
| 71 |
|
| 72 |
|
| 73 |
+
### `generate_example_from_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L805" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 74 |
|
| 75 |
```python
|
| 76 |
generate_example_from_schema(schema: JsonSchema | None) -> Any
|
|
|
|
| 81 |
Very basic implementation focusing on types.
|
| 82 |
|
| 83 |
|
| 84 |
+
### `format_json_for_description` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L888" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 85 |
|
| 86 |
```python
|
| 87 |
format_json_for_description(data: Any, indent: int = 2) -> str
|
|
|
|
| 91 |
Formats Python data as a JSON string block for markdown.
|
| 92 |
|
| 93 |
|
| 94 |
+
### `format_description_with_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L897" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 95 |
|
| 96 |
```python
|
| 97 |
format_description_with_responses(base_description: str, responses: dict[str, Any], parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
|
|
|
|
| 114 |
- and the request body.
|
| 115 |
|
| 116 |
|
| 117 |
+
### `extract_output_schema_from_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L1423" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 118 |
|
| 119 |
```python
|
| 120 |
+
extract_output_schema_from_responses(responses: dict[str, ResponseInfo], schema_definitions: dict[str, Any] | None = None, openapi_version: str | None = None) -> dict[str, Any] | None
|
| 121 |
```
|
| 122 |
|
| 123 |
|
|
|
|
| 130 |
**Args:**
|
| 131 |
- `responses`: Dictionary of ResponseInfo objects keyed by status code
|
| 132 |
- `schema_definitions`: Optional schema definitions to include in the output schema
|
| 133 |
+
- `openapi_version`: OpenAPI version string, used to optimize nullable field handling
|
| 134 |
|
| 135 |
**Returns:**
|
| 136 |
- MCP-compliant output schema with potential wrapping, or None if no suitable schema found
|
|
|
|
| 162 |
Intermediate Representation for a single OpenAPI operation.
|
| 163 |
|
| 164 |
|
| 165 |
+
### `OpenAPIParser` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L259" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 166 |
|
| 167 |
|
| 168 |
Unified parser for OpenAPI schemas with generic type parameters to handle both 3.0 and 3.1.
|
|
|
|
| 170 |
|
| 171 |
**Methods:**
|
| 172 |
|
| 173 |
+
#### `parse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L623" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 174 |
|
| 175 |
```python
|
| 176 |
parse(self) -> list[HTTPRoute]
|
docs/python-sdk/fastmcp-utilities-tests.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: tests
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `temporary_settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
temporary_settings(**kwargs: Any)
|
|
@@ -20,7 +20,7 @@ Temporarily override FastMCP setting values.
|
|
| 20 |
- `**kwargs`: The settings to override, including nested settings.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `run_server_in_process` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#
|
| 24 |
|
| 25 |
```python
|
| 26 |
run_server_in_process(server_fn: Callable[..., None], *args, **kwargs) -> Generator[str, None, None]
|
|
@@ -41,7 +41,7 @@ not pickleable, so we need a function that creates and runs one.
|
|
| 41 |
- The server URL.
|
| 42 |
|
| 43 |
|
| 44 |
-
### `caplog_for_fastmcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#
|
| 45 |
|
| 46 |
```python
|
| 47 |
caplog_for_fastmcp(caplog)
|
|
@@ -50,3 +50,34 @@ caplog_for_fastmcp(caplog)
|
|
| 50 |
|
| 51 |
Context manager to capture logs from FastMCP loggers even when propagation is disabled.
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `temporary_settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L25" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
temporary_settings(**kwargs: Any)
|
|
|
|
| 20 |
- `**kwargs`: The settings to override, including nested settings.
|
| 21 |
|
| 22 |
|
| 23 |
+
### `run_server_in_process` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L75" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
run_server_in_process(server_fn: Callable[..., None], *args, **kwargs) -> Generator[str, None, None]
|
|
|
|
| 41 |
- The server URL.
|
| 42 |
|
| 43 |
|
| 44 |
+
### `caplog_for_fastmcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L136" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 45 |
|
| 46 |
```python
|
| 47 |
caplog_for_fastmcp(caplog)
|
|
|
|
| 50 |
|
| 51 |
Context manager to capture logs from FastMCP loggers even when propagation is disabled.
|
| 52 |
|
| 53 |
+
|
| 54 |
+
## Classes
|
| 55 |
+
|
| 56 |
+
### `HeadlessOAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L147" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
OAuth provider that bypasses browser interaction for testing.
|
| 60 |
+
|
| 61 |
+
This simulates the complete OAuth flow programmatically by making HTTP requests
|
| 62 |
+
instead of opening a browser and running a callback server. Useful for automated testing.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
**Methods:**
|
| 66 |
+
|
| 67 |
+
#### `redirect_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L160" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
redirect_handler(self, authorization_url: str) -> None
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
Make HTTP request to authorization URL and store response for callback handler.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
#### `callback_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L166" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
callback_handler(self) -> tuple[str, str | None]
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Parse stored response and return (auth_code, state).
|
| 83 |
+
|
docs/python-sdk/fastmcp-utilities-types.mdx
CHANGED
|
@@ -23,7 +23,7 @@ However, this isn't feasible for user-generated functions. Instead, we use a
|
|
| 23 |
cache to minimize the cost of creating them as much as possible.
|
| 24 |
|
| 25 |
|
| 26 |
-
### `issubclass_safe` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 27 |
|
| 28 |
```python
|
| 29 |
issubclass_safe(cls: type, base: type) -> bool
|
|
@@ -33,7 +33,7 @@ issubclass_safe(cls: type, base: type) -> bool
|
|
| 33 |
Check if cls is a subclass of base, even if cls is a type variable.
|
| 34 |
|
| 35 |
|
| 36 |
-
### `is_class_member_of_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
is_class_member_of_type(cls: type, base: type) -> bool
|
|
@@ -46,7 +46,7 @@ Base can be a type, a UnionType, or an Annotated type. Generic types are not
|
|
| 46 |
considered members (e.g. T is not a member of list\[T]).
|
| 47 |
|
| 48 |
|
| 49 |
-
### `find_kwarg_by_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 50 |
|
| 51 |
```python
|
| 52 |
find_kwarg_by_type(fn: Callable, kwarg_type: type) -> str | None
|
|
@@ -58,7 +58,7 @@ Find the name of the kwarg that is of type kwarg_type.
|
|
| 58 |
Includes union types that contain the kwarg_type, as well as Annotated types.
|
| 59 |
|
| 60 |
|
| 61 |
-
### `replace_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 62 |
|
| 63 |
```python
|
| 64 |
replace_type(type_, type_map: dict[type, type])
|
|
@@ -93,7 +93,7 @@ list[list[str]]
|
|
| 93 |
Base model for FastMCP models.
|
| 94 |
|
| 95 |
|
| 96 |
-
### `Image` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 97 |
|
| 98 |
|
| 99 |
Helper class for returning images from tools.
|
|
@@ -101,7 +101,7 @@ Helper class for returning images from tools.
|
|
| 101 |
|
| 102 |
**Methods:**
|
| 103 |
|
| 104 |
-
#### `to_image_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 105 |
|
| 106 |
```python
|
| 107 |
to_image_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.ImageContent
|
|
@@ -110,7 +110,7 @@ to_image_content(self, mime_type: str | None = None, annotations: Annotations |
|
|
| 110 |
Convert to MCP ImageContent.
|
| 111 |
|
| 112 |
|
| 113 |
-
### `Audio` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 114 |
|
| 115 |
|
| 116 |
Helper class for returning audio from tools.
|
|
@@ -118,13 +118,13 @@ Helper class for returning audio from tools.
|
|
| 118 |
|
| 119 |
**Methods:**
|
| 120 |
|
| 121 |
-
#### `to_audio_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 122 |
|
| 123 |
```python
|
| 124 |
to_audio_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.AudioContent
|
| 125 |
```
|
| 126 |
|
| 127 |
-
### `File` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 128 |
|
| 129 |
|
| 130 |
Helper class for returning audio from tools.
|
|
@@ -132,7 +132,7 @@ Helper class for returning audio from tools.
|
|
| 132 |
|
| 133 |
**Methods:**
|
| 134 |
|
| 135 |
-
#### `to_resource_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 136 |
|
| 137 |
```python
|
| 138 |
to_resource_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.EmbeddedResource
|
|
|
|
| 23 |
cache to minimize the cost of creating them as much as possible.
|
| 24 |
|
| 25 |
|
| 26 |
+
### `issubclass_safe` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L109" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 27 |
|
| 28 |
```python
|
| 29 |
issubclass_safe(cls: type, base: type) -> bool
|
|
|
|
| 33 |
Check if cls is a subclass of base, even if cls is a type variable.
|
| 34 |
|
| 35 |
|
| 36 |
+
### `is_class_member_of_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L119" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
is_class_member_of_type(cls: type, base: type) -> bool
|
|
|
|
| 46 |
considered members (e.g. T is not a member of list\[T]).
|
| 47 |
|
| 48 |
|
| 49 |
+
### `find_kwarg_by_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L141" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 50 |
|
| 51 |
```python
|
| 52 |
find_kwarg_by_type(fn: Callable, kwarg_type: type) -> str | None
|
|
|
|
| 58 |
Includes union types that contain the kwarg_type, as well as Annotated types.
|
| 59 |
|
| 60 |
|
| 61 |
+
### `replace_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L370" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 62 |
|
| 63 |
```python
|
| 64 |
replace_type(type_, type_map: dict[type, type])
|
|
|
|
| 93 |
Base model for FastMCP models.
|
| 94 |
|
| 95 |
|
| 96 |
+
### `Image` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L167" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 97 |
|
| 98 |
|
| 99 |
Helper class for returning images from tools.
|
|
|
|
| 101 |
|
| 102 |
**Methods:**
|
| 103 |
|
| 104 |
+
#### `to_image_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L204" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 105 |
|
| 106 |
```python
|
| 107 |
to_image_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.ImageContent
|
|
|
|
| 110 |
Convert to MCP ImageContent.
|
| 111 |
|
| 112 |
|
| 113 |
+
### `Audio` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L226" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 114 |
|
| 115 |
|
| 116 |
Helper class for returning audio from tools.
|
|
|
|
| 118 |
|
| 119 |
**Methods:**
|
| 120 |
|
| 121 |
+
#### `to_audio_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L263" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 122 |
|
| 123 |
```python
|
| 124 |
to_audio_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.AudioContent
|
| 125 |
```
|
| 126 |
|
| 127 |
+
### `File` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L284" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
|
| 129 |
|
| 130 |
Helper class for returning audio from tools.
|
|
|
|
| 132 |
|
| 133 |
**Methods:**
|
| 134 |
|
| 135 |
+
#### `to_resource_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L323" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 136 |
|
| 137 |
```python
|
| 138 |
to_resource_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.EmbeddedResource
|
docs/servers/auth/authentication.mdx
CHANGED
|
@@ -3,6 +3,7 @@ title: Authentication
|
|
| 3 |
sidebarTitle: Overview
|
| 4 |
description: Secure your FastMCP server with flexible authentication patterns, from simple API keys to full OAuth 2.1 integration with external identity providers.
|
| 5 |
icon: user-shield
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
@@ -67,9 +68,9 @@ Token verification is the conceptually simplest approach to authentication, wher
|
|
| 67 |
- Ensuring tokens are securely transmitted to your server
|
| 68 |
- Managing token lifecycle in your issuing system
|
| 69 |
|
| 70 |
-
### Remote
|
| 71 |
|
| 72 |
-
This is the **recommended pattern for most FastMCP users** and follows the 2025-6-18 MCP protocol update. Your FastMCP server acts as a **Resource Server** and integrates with an external, trusted **Authorization Server** like WorkOS, Auth0, or Okta. You can learn more about this pattern in the [remote
|
| 73 |
|
| 74 |
**Use this when:**
|
| 75 |
- You want to integrate with external identity providers
|
|
@@ -126,7 +127,7 @@ jwt_verifier = JWTVerifier(...)
|
|
| 126 |
mcp = FastMCP(name="My Server", auth=jwt_verifier)
|
| 127 |
```
|
| 128 |
|
| 129 |
-
```python Remote
|
| 130 |
from fastmcp import FastMCP
|
| 131 |
from fastmcp.server.auth.providers.workos import AuthKitProvider
|
| 132 |
|
|
|
|
| 3 |
sidebarTitle: Overview
|
| 4 |
description: Secure your FastMCP server with flexible authentication patterns, from simple API keys to full OAuth 2.1 integration with external identity providers.
|
| 5 |
icon: user-shield
|
| 6 |
+
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
|
|
| 68 |
- Ensuring tokens are securely transmitted to your server
|
| 69 |
- Managing token lifecycle in your issuing system
|
| 70 |
|
| 71 |
+
### Remote OAuth
|
| 72 |
|
| 73 |
+
This is the **recommended pattern for most FastMCP users** and follows the 2025-6-18 MCP protocol update. Your FastMCP server acts as a **Resource Server** and integrates with an external, trusted **Authorization Server** like WorkOS, Auth0, or Okta. You can learn more about this pattern in the [remote OAuth documentation](/servers/auth/remote-oauth).
|
| 74 |
|
| 75 |
**Use this when:**
|
| 76 |
- You want to integrate with external identity providers
|
|
|
|
| 127 |
mcp = FastMCP(name="My Server", auth=jwt_verifier)
|
| 128 |
```
|
| 129 |
|
| 130 |
+
```python Remote OAuth
|
| 131 |
from fastmcp import FastMCP
|
| 132 |
from fastmcp.server.auth.providers.workos import AuthKitProvider
|
| 133 |
|
docs/servers/auth/full-oauth-server.mdx
CHANGED
|
@@ -3,6 +3,7 @@ title: Full OAuth Server
|
|
| 3 |
sidebarTitle: Full OAuth Server
|
| 4 |
description: Build a self-contained authentication system where your FastMCP server manages users, issues tokens, and validates them.
|
| 5 |
icon: users-between-lines
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
@@ -12,7 +13,7 @@ import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
| 12 |
<Warning>
|
| 13 |
**This is an extremely advanced pattern.** Building a secure, production-ready OAuth 2.1 server is a complex undertaking that requires deep expertise in authentication protocols, cryptography, and security best practices.
|
| 14 |
|
| 15 |
-
This pattern exists primarily to support the MCP protocol specification's requirements. **Most users should strongly prefer the [Remote
|
| 16 |
</Warning>
|
| 17 |
|
| 18 |
In the **Full OAuth Server** pattern, your FastMCP server acts as both the **Authorization Server (AS)** and the **Resource Server (RS)**. It becomes responsible for the entire authentication lifecycle:
|
|
|
|
| 3 |
sidebarTitle: Full OAuth Server
|
| 4 |
description: Build a self-contained authentication system where your FastMCP server manages users, issues tokens, and validates them.
|
| 5 |
icon: users-between-lines
|
| 6 |
+
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
|
|
| 13 |
<Warning>
|
| 14 |
**This is an extremely advanced pattern.** Building a secure, production-ready OAuth 2.1 server is a complex undertaking that requires deep expertise in authentication protocols, cryptography, and security best practices.
|
| 15 |
|
| 16 |
+
This pattern exists primarily to support the MCP protocol specification's requirements. **Most users should strongly prefer the [Remote OAuth pattern](/servers/auth/remote-oauth)** to integrate with a dedicated identity provider like WorkOS, Auth0, or Okta.
|
| 17 |
</Warning>
|
| 18 |
|
| 19 |
In the **Full OAuth Server** pattern, your FastMCP server acts as both the **Authorization Server (AS)** and the **Resource Server (RS)**. It becomes responsible for the entire authentication lifecycle:
|
docs/servers/auth/{remote-authentication.mdx → remote-oauth.mdx}
RENAMED
|
@@ -1,15 +1,16 @@
|
|
| 1 |
---
|
| 2 |
-
title: Remote
|
| 3 |
-
sidebarTitle: Remote
|
| 4 |
description: Integrate with external identity providers like WorkOS, Auth0, or Okta by trusting them to handle user authentication.
|
| 5 |
icon: camera-cctv
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
| 9 |
|
| 10 |
<VersionBadge version="2.11.0" />
|
| 11 |
|
| 12 |
-
**Remote
|
| 13 |
|
| 14 |
This approach lets you leverage robust, feature-rich identity platforms for user management, multi-factor authentication, and social logins, while your FastMCP server focuses on its core job: providing tools and resources.
|
| 15 |
|
|
@@ -119,7 +120,7 @@ mcp = FastMCP(name="My Secure Server", auth=MyIdPAuthProvider())
|
|
| 119 |
|
| 120 |
## Example: WorkOS AuthKit Provider
|
| 121 |
|
| 122 |
-
FastMCP provides a built-in provider for **WorkOS AuthKit** that handles this entire pattern for you. It's a perfect example of the remote
|
| 123 |
|
| 124 |
**Prerequisites:**
|
| 125 |
1. A WorkOS account with an AuthKit project.
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Remote OAuth
|
| 3 |
+
sidebarTitle: Remote OAuth
|
| 4 |
description: Integrate with external identity providers like WorkOS, Auth0, or Okta by trusting them to handle user authentication.
|
| 5 |
icon: camera-cctv
|
| 6 |
+
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
| 10 |
|
| 11 |
<VersionBadge version="2.11.0" />
|
| 12 |
|
| 13 |
+
**Remote OAuth** is the recommended pattern for securing most production applications. In this model, your FastMCP server acts as a **Resource Server (RS)** and integrates with an external, trusted **Authorization Server (AS)**, such as WorkOS, Auth0, or a corporate SSO system.
|
| 14 |
|
| 15 |
This approach lets you leverage robust, feature-rich identity platforms for user management, multi-factor authentication, and social logins, while your FastMCP server focuses on its core job: providing tools and resources.
|
| 16 |
|
|
|
|
| 120 |
|
| 121 |
## Example: WorkOS AuthKit Provider
|
| 122 |
|
| 123 |
+
FastMCP provides a built-in provider for **WorkOS AuthKit** that handles this entire pattern for you. It's a perfect example of the remote OAuth pattern in action.
|
| 124 |
|
| 125 |
**Prerequisites:**
|
| 126 |
1. A WorkOS account with an AuthKit project.
|
docs/servers/auth/token-verification.mdx
CHANGED
|
@@ -3,6 +3,7 @@ title: Token Verification
|
|
| 3 |
sidebarTitle: Token Verification
|
| 4 |
description: Protect your server by validating bearer tokens.
|
| 5 |
icon: key
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
|
|
| 3 |
sidebarTitle: Token Verification
|
| 4 |
description: Protect your server by validating bearer tokens.
|
| 5 |
icon: key
|
| 6 |
+
tag: NEW
|
| 7 |
---
|
| 8 |
|
| 9 |
import { VersionBadge } from "/snippets/version-badge.mdx"
|