Spaces:
Running
Running
zzstoatzz commited on
Commit ·
a2aa9d2
1
Parent(s): be25dfa
update api ref for new `mdxify` version
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- docs/docs.json +40 -7
- docs/python-sdk/fastmcp-cli-claude.mdx +2 -2
- docs/python-sdk/fastmcp-cli-cli.mdx +30 -38
- docs/python-sdk/fastmcp-cli-install-__init__.mdx +9 -0
- docs/python-sdk/fastmcp-cli-install-claude_code.mdx +68 -0
- docs/python-sdk/fastmcp-cli-install-claude_desktop.mdx +55 -0
- docs/python-sdk/fastmcp-cli-install-cursor.mdx +78 -0
- docs/python-sdk/fastmcp-cli-install-mcp_config.mdx +46 -0
- docs/python-sdk/fastmcp-cli-install-shared.mdx +31 -0
- docs/python-sdk/fastmcp-cli-run.mdx +10 -8
- docs/python-sdk/fastmcp-client-auth-bearer.mdx +2 -2
- docs/python-sdk/fastmcp-client-auth-oauth.mdx +73 -23
- docs/python-sdk/fastmcp-client-client.mdx +423 -18
- docs/python-sdk/fastmcp-client-elicitation.mdx +18 -0
- docs/python-sdk/fastmcp-client-logging.mdx +7 -1
- docs/python-sdk/fastmcp-client-messages.mdx +107 -0
- docs/python-sdk/fastmcp-client-oauth_callback.mdx +5 -5
- docs/python-sdk/fastmcp-client-progress.mdx +18 -1
- docs/python-sdk/fastmcp-client-roots.mdx +2 -2
- docs/python-sdk/fastmcp-client-sampling.mdx +1 -1
- docs/python-sdk/fastmcp-client-transports.mdx +110 -14
- docs/python-sdk/fastmcp-exceptions.mdx +9 -9
- docs/python-sdk/fastmcp-mcp_config.mdx +150 -0
- docs/python-sdk/fastmcp-prompts-prompt.mdx +40 -10
- docs/python-sdk/fastmcp-prompts-prompt_manager.mdx +50 -4
- docs/python-sdk/fastmcp-resources-resource.mdx +40 -10
- docs/python-sdk/fastmcp-resources-resource_manager.mdx +77 -7
- docs/python-sdk/fastmcp-resources-template.mdx +52 -13
- docs/python-sdk/fastmcp-resources-types.mdx +60 -9
- docs/python-sdk/fastmcp-server-auth-auth.mdx +21 -1
- docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx +90 -7
- docs/python-sdk/fastmcp-server-auth-providers-bearer_env.mdx +2 -2
- docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx +82 -1
- docs/python-sdk/fastmcp-server-context.mdx +184 -9
- docs/python-sdk/fastmcp-server-dependencies.mdx +3 -3
- docs/python-sdk/fastmcp-server-elicitation.mdx +54 -0
- docs/python-sdk/fastmcp-server-http.mdx +8 -8
- docs/python-sdk/fastmcp-server-low_level.mdx +18 -0
- docs/python-sdk/fastmcp-server-middleware-error_handling.mdx +23 -3
- docs/python-sdk/fastmcp-server-middleware-logging.mdx +24 -2
- docs/python-sdk/fastmcp-server-middleware-middleware.mdx +66 -14
- docs/python-sdk/fastmcp-server-middleware-rate_limiting.mdx +55 -5
- docs/python-sdk/fastmcp-server-middleware-timing.mdx +78 -2
- docs/python-sdk/fastmcp-server-openapi.mdx +40 -7
- docs/python-sdk/fastmcp-server-proxy.mdx +211 -13
- docs/python-sdk/fastmcp-server-server.mdx +225 -37
- docs/python-sdk/fastmcp-settings.mdx +13 -7
- docs/python-sdk/fastmcp-tools-tool.mdx +59 -13
- docs/python-sdk/fastmcp-tools-tool_manager.mdx +51 -5
- docs/python-sdk/fastmcp-tools-tool_transform.mdx +108 -6
docs/docs.json
CHANGED
|
@@ -65,7 +65,10 @@
|
|
| 65 |
{
|
| 66 |
"group": "Essentials",
|
| 67 |
"icon": "cube",
|
| 68 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 69 |
},
|
| 70 |
{
|
| 71 |
"group": "Core Components",
|
|
@@ -93,7 +96,9 @@
|
|
| 93 |
{
|
| 94 |
"group": "Authentication",
|
| 95 |
"icon": "shield-check",
|
| 96 |
-
"pages": [
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
]
|
| 99 |
},
|
|
@@ -103,7 +108,10 @@
|
|
| 103 |
{
|
| 104 |
"group": "Essentials",
|
| 105 |
"icon": "cube",
|
| 106 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 107 |
},
|
| 108 |
{
|
| 109 |
"group": "Core Operations",
|
|
@@ -129,7 +137,10 @@
|
|
| 129 |
{
|
| 130 |
"group": "Authentication",
|
| 131 |
"icon": "user-shield",
|
| 132 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
| 134 |
]
|
| 135 |
},
|
|
@@ -174,12 +185,17 @@
|
|
| 174 |
},
|
| 175 |
{
|
| 176 |
"anchor": "What's New",
|
| 177 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 178 |
},
|
| 179 |
{
|
| 180 |
"anchor": "Community",
|
| 181 |
"icon": "users",
|
| 182 |
-
"pages": [
|
|
|
|
|
|
|
| 183 |
}
|
| 184 |
]
|
| 185 |
},
|
|
@@ -191,6 +207,7 @@
|
|
| 191 |
"icon": "python",
|
| 192 |
"pages": [
|
| 193 |
"python-sdk/fastmcp-exceptions",
|
|
|
|
| 194 |
"python-sdk/fastmcp-settings",
|
| 195 |
{
|
| 196 |
"group": "fastmcp.cli",
|
|
@@ -198,6 +215,17 @@
|
|
| 198 |
"python-sdk/fastmcp-cli-__init__",
|
| 199 |
"python-sdk/fastmcp-cli-claude",
|
| 200 |
"python-sdk/fastmcp-cli-cli",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
"python-sdk/fastmcp-cli-run"
|
| 202 |
]
|
| 203 |
},
|
|
@@ -214,7 +242,9 @@
|
|
| 214 |
]
|
| 215 |
},
|
| 216 |
"python-sdk/fastmcp-client-client",
|
|
|
|
| 217 |
"python-sdk/fastmcp-client-logging",
|
|
|
|
| 218 |
"python-sdk/fastmcp-client-oauth_callback",
|
| 219 |
"python-sdk/fastmcp-client-progress",
|
| 220 |
"python-sdk/fastmcp-client-roots",
|
|
@@ -262,7 +292,9 @@
|
|
| 262 |
},
|
| 263 |
"python-sdk/fastmcp-server-context",
|
| 264 |
"python-sdk/fastmcp-server-dependencies",
|
|
|
|
| 265 |
"python-sdk/fastmcp-server-http",
|
|
|
|
| 266 |
{
|
| 267 |
"group": "middleware",
|
| 268 |
"pages": [
|
|
@@ -293,13 +325,14 @@
|
|
| 293 |
"pages": [
|
| 294 |
"python-sdk/fastmcp-utilities-__init__",
|
| 295 |
"python-sdk/fastmcp-utilities-cache",
|
|
|
|
| 296 |
"python-sdk/fastmcp-utilities-components",
|
| 297 |
"python-sdk/fastmcp-utilities-exceptions",
|
| 298 |
"python-sdk/fastmcp-utilities-http",
|
| 299 |
"python-sdk/fastmcp-utilities-inspect",
|
| 300 |
"python-sdk/fastmcp-utilities-json_schema",
|
|
|
|
| 301 |
"python-sdk/fastmcp-utilities-logging",
|
| 302 |
-
"python-sdk/fastmcp-utilities-mcp_config",
|
| 303 |
"python-sdk/fastmcp-utilities-openapi",
|
| 304 |
"python-sdk/fastmcp-utilities-tests",
|
| 305 |
"python-sdk/fastmcp-utilities-types"
|
|
|
|
| 65 |
{
|
| 66 |
"group": "Essentials",
|
| 67 |
"icon": "cube",
|
| 68 |
+
"pages": [
|
| 69 |
+
"servers/server",
|
| 70 |
+
"deployment/running-server"
|
| 71 |
+
]
|
| 72 |
},
|
| 73 |
{
|
| 74 |
"group": "Core Components",
|
|
|
|
| 96 |
{
|
| 97 |
"group": "Authentication",
|
| 98 |
"icon": "shield-check",
|
| 99 |
+
"pages": [
|
| 100 |
+
"servers/auth/bearer"
|
| 101 |
+
]
|
| 102 |
}
|
| 103 |
]
|
| 104 |
},
|
|
|
|
| 108 |
{
|
| 109 |
"group": "Essentials",
|
| 110 |
"icon": "cube",
|
| 111 |
+
"pages": [
|
| 112 |
+
"clients/client",
|
| 113 |
+
"clients/transports"
|
| 114 |
+
]
|
| 115 |
},
|
| 116 |
{
|
| 117 |
"group": "Core Operations",
|
|
|
|
| 137 |
{
|
| 138 |
"group": "Authentication",
|
| 139 |
"icon": "user-shield",
|
| 140 |
+
"pages": [
|
| 141 |
+
"clients/auth/oauth",
|
| 142 |
+
"clients/auth/bearer"
|
| 143 |
+
]
|
| 144 |
}
|
| 145 |
]
|
| 146 |
},
|
|
|
|
| 185 |
},
|
| 186 |
{
|
| 187 |
"anchor": "What's New",
|
| 188 |
+
"pages": [
|
| 189 |
+
"updates",
|
| 190 |
+
"changelog"
|
| 191 |
+
]
|
| 192 |
},
|
| 193 |
{
|
| 194 |
"anchor": "Community",
|
| 195 |
"icon": "users",
|
| 196 |
+
"pages": [
|
| 197 |
+
"community/showcase"
|
| 198 |
+
]
|
| 199 |
}
|
| 200 |
]
|
| 201 |
},
|
|
|
|
| 207 |
"icon": "python",
|
| 208 |
"pages": [
|
| 209 |
"python-sdk/fastmcp-exceptions",
|
| 210 |
+
"python-sdk/fastmcp-mcp_config",
|
| 211 |
"python-sdk/fastmcp-settings",
|
| 212 |
{
|
| 213 |
"group": "fastmcp.cli",
|
|
|
|
| 215 |
"python-sdk/fastmcp-cli-__init__",
|
| 216 |
"python-sdk/fastmcp-cli-claude",
|
| 217 |
"python-sdk/fastmcp-cli-cli",
|
| 218 |
+
{
|
| 219 |
+
"group": "install",
|
| 220 |
+
"pages": [
|
| 221 |
+
"python-sdk/fastmcp-cli-install-__init__",
|
| 222 |
+
"python-sdk/fastmcp-cli-install-claude_code",
|
| 223 |
+
"python-sdk/fastmcp-cli-install-claude_desktop",
|
| 224 |
+
"python-sdk/fastmcp-cli-install-cursor",
|
| 225 |
+
"python-sdk/fastmcp-cli-install-mcp_config",
|
| 226 |
+
"python-sdk/fastmcp-cli-install-shared"
|
| 227 |
+
]
|
| 228 |
+
},
|
| 229 |
"python-sdk/fastmcp-cli-run"
|
| 230 |
]
|
| 231 |
},
|
|
|
|
| 242 |
]
|
| 243 |
},
|
| 244 |
"python-sdk/fastmcp-client-client",
|
| 245 |
+
"python-sdk/fastmcp-client-elicitation",
|
| 246 |
"python-sdk/fastmcp-client-logging",
|
| 247 |
+
"python-sdk/fastmcp-client-messages",
|
| 248 |
"python-sdk/fastmcp-client-oauth_callback",
|
| 249 |
"python-sdk/fastmcp-client-progress",
|
| 250 |
"python-sdk/fastmcp-client-roots",
|
|
|
|
| 292 |
},
|
| 293 |
"python-sdk/fastmcp-server-context",
|
| 294 |
"python-sdk/fastmcp-server-dependencies",
|
| 295 |
+
"python-sdk/fastmcp-server-elicitation",
|
| 296 |
"python-sdk/fastmcp-server-http",
|
| 297 |
+
"python-sdk/fastmcp-server-low_level",
|
| 298 |
{
|
| 299 |
"group": "middleware",
|
| 300 |
"pages": [
|
|
|
|
| 325 |
"pages": [
|
| 326 |
"python-sdk/fastmcp-utilities-__init__",
|
| 327 |
"python-sdk/fastmcp-utilities-cache",
|
| 328 |
+
"python-sdk/fastmcp-utilities-cli",
|
| 329 |
"python-sdk/fastmcp-utilities-components",
|
| 330 |
"python-sdk/fastmcp-utilities-exceptions",
|
| 331 |
"python-sdk/fastmcp-utilities-http",
|
| 332 |
"python-sdk/fastmcp-utilities-inspect",
|
| 333 |
"python-sdk/fastmcp-utilities-json_schema",
|
| 334 |
+
"python-sdk/fastmcp-utilities-json_schema_type",
|
| 335 |
"python-sdk/fastmcp-utilities-logging",
|
|
|
|
| 336 |
"python-sdk/fastmcp-utilities-openapi",
|
| 337 |
"python-sdk/fastmcp-utilities-tests",
|
| 338 |
"python-sdk/fastmcp-utilities-types"
|
docs/python-sdk/fastmcp-cli-claude.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Claude app integration utilities.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `get_claude_config_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/claude.py#L14"><Icon icon="github"
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_claude_config_path() -> Path | None
|
|
@@ -20,7 +20,7 @@ get_claude_config_path() -> Path | None
|
|
| 20 |
Get the Claude config directory based on platform.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `update_claude_config` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/claude.py#L32"><Icon icon="github"
|
| 24 |
|
| 25 |
```python
|
| 26 |
update_claude_config(file_spec: str, server_name: str) -> bool
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `get_claude_config_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/claude.py#L14" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_claude_config_path() -> Path | None
|
|
|
|
| 20 |
Get the Claude config directory based on platform.
|
| 21 |
|
| 22 |
|
| 23 |
+
### `update_claude_config` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/claude.py#L32" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
update_claude_config(file_spec: str, server_name: str) -> bool
|
docs/python-sdk/fastmcp-cli-cli.mdx
CHANGED
|
@@ -6,77 +6,66 @@ sidebarTitle: cli
|
|
| 6 |
# `fastmcp.cli.cli`
|
| 7 |
|
| 8 |
|
| 9 |
-
FastMCP CLI tools.
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `version` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
-
version(
|
| 17 |
```
|
| 18 |
|
| 19 |
-
### `dev` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L110"><Icon icon="github" size="14" /></a></sup>
|
| 20 |
-
|
| 21 |
-
```python
|
| 22 |
-
dev(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], inspector_version: Annotated[str | None, typer.Option('--inspector-version', help='Version of the MCP Inspector to use')] = None, ui_port: Annotated[int | None, typer.Option('--ui-port', help='Port for the MCP Inspector UI')] = None, server_port: Annotated[int | None, typer.Option('--server-port', help='Port for the MCP Inspector Proxy server')] = None) -> None
|
| 23 |
-
```
|
| 24 |
|
|
|
|
| 25 |
|
| 26 |
-
Run a MCP server with the MCP Inspector.
|
| 27 |
|
| 28 |
-
|
| 29 |
-
### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L227"><Icon icon="github" size="14" /></a></sup>
|
| 30 |
|
| 31 |
```python
|
| 32 |
-
|
| 33 |
```
|
| 34 |
|
| 35 |
|
| 36 |
-
Run
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
2. Import approach: server.py:app - imports and runs the specified server object.
|
| 42 |
|
| 43 |
-
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
Server arguments can be passed after -- :
|
| 51 |
fastmcp run server.py -- --config config.json --debug
|
| 52 |
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
### `install` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L313"><Icon icon="github" size="14" /></a></sup>
|
| 55 |
|
| 56 |
-
``
|
| 57 |
-
install(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), server_name: Annotated[str | None, typer.Option('--name', '-n', help="Custom name for the server (defaults to server's name attribute or file name)")] = None, with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], env_vars: Annotated[list[str], typer.Option('--env-var', '-v', help='Environment variables in KEY=VALUE format')] = [], env_file: Annotated[Path | None, typer.Option('--env-file', '-f', help='Load environment variables from a .env file', exists=True, file_okay=True, dir_okay=False, resolve_path=True)] = None) -> None
|
| 58 |
-
```
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
Install a MCP server in the Claude desktop app.
|
| 62 |
-
|
| 63 |
-
Environment variables are preserved once added and only updated if new values
|
| 64 |
-
are explicitly provided.
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
### `inspect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L444"><Icon icon="github" size="14" /></a></sup>
|
| 68 |
|
| 69 |
```python
|
| 70 |
-
inspect(server_spec: str
|
| 71 |
```
|
| 72 |
|
| 73 |
|
| 74 |
-
Inspect
|
| 75 |
|
| 76 |
-
This command analyzes
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
and capabilities.
|
| 80 |
|
| 81 |
**Examples:**
|
| 82 |
|
|
@@ -85,3 +74,6 @@ fastmcp inspect server.py -o report.json
|
|
| 85 |
fastmcp inspect server.py:mcp -o analysis.json
|
| 86 |
fastmcp inspect path/to/server.py:app -o /tmp/server-info.json
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# `fastmcp.cli.cli`
|
| 7 |
|
| 8 |
|
| 9 |
+
FastMCP CLI tools using Cyclopts.
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `version` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L89" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
+
version()
|
| 17 |
```
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
Display version information and platform details.
|
| 21 |
|
|
|
|
| 22 |
|
| 23 |
+
### `dev` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
| 24 |
|
| 25 |
```python
|
| 26 |
+
dev(server_spec: str) -> None
|
| 27 |
```
|
| 28 |
|
| 29 |
|
| 30 |
+
Run an MCP server with the MCP Inspector for development.
|
| 31 |
|
| 32 |
+
**Args:**
|
| 33 |
+
- `server_spec`: Python file to run, optionally with \:object suffix
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
+
### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L245" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
+
```python
|
| 39 |
+
run(server_spec: str) -> None
|
| 40 |
+
```
|
| 41 |
|
| 42 |
|
| 43 |
+
Run an MCP server or connect to a remote one.
|
| 44 |
+
|
| 45 |
+
The server can be specified in three ways:
|
| 46 |
+
1. Module approach: server.py - runs the module directly, looking for an object named 'mcp', 'server', or 'app'
|
| 47 |
+
2. Import approach: server.py:app - imports and runs the specified server object
|
| 48 |
+
3. URL approach: http://server-url - connects to a remote server and creates a proxy
|
| 49 |
|
| 50 |
Server arguments can be passed after -- :
|
| 51 |
fastmcp run server.py -- --config config.json --debug
|
| 52 |
|
| 53 |
+
**Args:**
|
| 54 |
+
- `server_spec`: Python file, object specification (file\:obj), or URL
|
| 55 |
|
|
|
|
| 56 |
|
| 57 |
+
### `inspect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L344" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
```python
|
| 60 |
+
inspect(server_spec: str) -> None
|
| 61 |
```
|
| 62 |
|
| 63 |
|
| 64 |
+
Inspect an MCP server and generate a JSON report.
|
| 65 |
|
| 66 |
+
This command analyzes an MCP server and generates a comprehensive JSON report
|
| 67 |
+
containing information about the server's name, instructions, version, tools,
|
| 68 |
+
prompts, resources, templates, and capabilities.
|
|
|
|
| 69 |
|
| 70 |
**Examples:**
|
| 71 |
|
|
|
|
| 74 |
fastmcp inspect server.py:mcp -o analysis.json
|
| 75 |
fastmcp inspect path/to/server.py:app -o /tmp/server-info.json
|
| 76 |
|
| 77 |
+
**Args:**
|
| 78 |
+
- `server_spec`: Python file to inspect, optionally with \:object suffix
|
| 79 |
+
|
docs/python-sdk/fastmcp-cli-install-__init__.mdx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.install`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Install subcommands for FastMCP CLI using Cyclopts.
|
docs/python-sdk/fastmcp-cli-install-claude_code.mdx
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: claude_code
|
| 3 |
+
sidebarTitle: claude_code
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.install.claude_code`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Claude Code integration for FastMCP install using Cyclopts.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `find_claude_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_code.py#L19" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
find_claude_command() -> str | None
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Find the Claude Code CLI command.
|
| 21 |
+
|
| 22 |
+
Checks common installation locations since 'claude' is often a shell alias
|
| 23 |
+
that doesn't work with subprocess calls.
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
### `check_claude_code_available` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_code.py#L67" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
check_claude_code_available() -> bool
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Check if Claude Code CLI is available.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
### `install_claude_code` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_code.py#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
install_claude_code(file: Path, server_object: str | None, name: str) -> bool
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Install FastMCP server in Claude Code.
|
| 44 |
+
|
| 45 |
+
**Args:**
|
| 46 |
+
- `file`: Path to the server file
|
| 47 |
+
- `server_object`: Optional server object name (for \:object suffix)
|
| 48 |
+
- `name`: Name for the server in Claude Code
|
| 49 |
+
- `with_editable`: Optional directory to install in editable mode
|
| 50 |
+
- `with_packages`: Optional list of additional packages to install
|
| 51 |
+
- `env_vars`: Optional dictionary of environment variables
|
| 52 |
+
|
| 53 |
+
**Returns:**
|
| 54 |
+
- True if installation was successful, False otherwise
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
### `claude_code_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_code.py#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
claude_code_command(server_spec: str) -> None
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Install an MCP server in Claude Code.
|
| 65 |
+
|
| 66 |
+
**Args:**
|
| 67 |
+
- `server_spec`: Python file to install, optionally with \:object suffix
|
| 68 |
+
|
docs/python-sdk/fastmcp-cli-install-claude_desktop.mdx
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: claude_desktop
|
| 3 |
+
sidebarTitle: claude_desktop
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.install.claude_desktop`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Claude Desktop integration for FastMCP install using Cyclopts.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `get_claude_config_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_desktop.py#L19" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
get_claude_config_path() -> Path | None
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Get the Claude config directory based on platform.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
### `install_claude_desktop` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_desktop.py#L37" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
install_claude_desktop(file: Path, server_object: str | None, name: str) -> bool
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Install FastMCP server in Claude Desktop.
|
| 31 |
+
|
| 32 |
+
**Args:**
|
| 33 |
+
- `file`: Path to the server file
|
| 34 |
+
- `server_object`: Optional server object name (for \:object suffix)
|
| 35 |
+
- `name`: Name for the server in Claude's config
|
| 36 |
+
- `with_editable`: Optional directory to install in editable mode
|
| 37 |
+
- `with_packages`: Optional list of additional packages to install
|
| 38 |
+
- `env_vars`: Optional dictionary of environment variables
|
| 39 |
+
|
| 40 |
+
**Returns:**
|
| 41 |
+
- True if installation was successful, False otherwise
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
### `claude_desktop_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_desktop.py#L126" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
claude_desktop_command(server_spec: str) -> None
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Install an MCP server in Claude Desktop.
|
| 52 |
+
|
| 53 |
+
**Args:**
|
| 54 |
+
- `server_spec`: Python file to install, optionally with \:object suffix
|
| 55 |
+
|
docs/python-sdk/fastmcp-cli-install-cursor.mdx
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: cursor
|
| 3 |
+
sidebarTitle: cursor
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.install.cursor`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Cursor integration for FastMCP install using Cyclopts.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `generate_cursor_deeplink` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/cursor.py#L20" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
generate_cursor_deeplink(server_name: str, server_config: StdioMCPServer) -> str
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Generate a Cursor deeplink for installing the MCP server.
|
| 21 |
+
|
| 22 |
+
**Args:**
|
| 23 |
+
- `server_name`: Name of the server
|
| 24 |
+
- `server_config`: Server configuration
|
| 25 |
+
|
| 26 |
+
**Returns:**
|
| 27 |
+
- Deeplink URL that can be clicked to install the server
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
### `open_deeplink` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/cursor.py#L44" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
open_deeplink(deeplink: str) -> bool
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Attempt to open a deeplink URL using the system's default handler.
|
| 38 |
+
|
| 39 |
+
**Args:**
|
| 40 |
+
- `deeplink`: The deeplink URL to open
|
| 41 |
+
|
| 42 |
+
**Returns:**
|
| 43 |
+
- True if the command succeeded, False otherwise
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
### `install_cursor` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/cursor.py#L67" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 47 |
+
|
| 48 |
+
```python
|
| 49 |
+
install_cursor(file: Path, server_object: str | None, name: str) -> bool
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Install FastMCP server in Cursor.
|
| 54 |
+
|
| 55 |
+
**Args:**
|
| 56 |
+
- `file`: Path to the server file
|
| 57 |
+
- `server_object`: Optional server object name (for \:object suffix)
|
| 58 |
+
- `name`: Name for the server in Cursor
|
| 59 |
+
- `with_editable`: Optional directory to install in editable mode
|
| 60 |
+
- `with_packages`: Optional list of additional packages to install
|
| 61 |
+
- `env_vars`: Optional dictionary of environment variables
|
| 62 |
+
|
| 63 |
+
**Returns:**
|
| 64 |
+
- True if installation was successful, False otherwise
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
### `cursor_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/cursor.py#L136" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
cursor_command(server_spec: str) -> None
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Install an MCP server in Cursor.
|
| 75 |
+
|
| 76 |
+
**Args:**
|
| 77 |
+
- `server_spec`: Python file to install, optionally with \:object suffix
|
| 78 |
+
|
docs/python-sdk/fastmcp-cli-install-mcp_config.mdx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: mcp_config
|
| 3 |
+
sidebarTitle: mcp_config
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.install.mcp_config`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
MCP configuration JSON generation for FastMCP install using Cyclopts.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `install_mcp_config` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/mcp_config.py#L19" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
install_mcp_config(file: Path, server_object: str | None, name: str) -> bool
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Generate MCP configuration JSON for manual installation.
|
| 21 |
+
|
| 22 |
+
**Args:**
|
| 23 |
+
- `file`: Path to the server file
|
| 24 |
+
- `server_object`: Optional server object name (for \:object suffix)
|
| 25 |
+
- `name`: Name for the server in MCP config
|
| 26 |
+
- `with_editable`: Optional directory to install in editable mode
|
| 27 |
+
- `with_packages`: Optional list of additional packages to install
|
| 28 |
+
- `env_vars`: Optional dictionary of environment variables
|
| 29 |
+
- `copy`: If True, copy to clipboard instead of printing to stdout
|
| 30 |
+
|
| 31 |
+
**Returns:**
|
| 32 |
+
- True if generation was successful, False otherwise
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
### `mcp_config_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/mcp_config.py#L96" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
mcp_config_command(server_spec: str) -> None
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Generate MCP configuration JSON for manual installation.
|
| 43 |
+
|
| 44 |
+
**Args:**
|
| 45 |
+
- `server_spec`: Python file to install, optionally with \:object suffix
|
| 46 |
+
|
docs/python-sdk/fastmcp-cli-install-shared.mdx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: shared
|
| 3 |
+
sidebarTitle: shared
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.install.shared`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Shared utilities for install commands.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `parse_env_var` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/shared.py#L15" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
parse_env_var(env_var: str) -> tuple[str, str]
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Parse environment variable string in format KEY=VALUE.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
### `process_common_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/shared.py#L26" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
process_common_args(server_spec: str, server_name: str | None, with_packages: list[str], env_vars: list[str], env_file: Path | None) -> tuple[Path, str | None, str, list[str], dict[str, str] | None]
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Process common arguments shared by all install commands.
|
| 31 |
+
|
docs/python-sdk/fastmcp-cli-run.mdx
CHANGED
|
@@ -6,11 +6,11 @@ sidebarTitle: run
|
|
| 6 |
# `fastmcp.cli.run`
|
| 7 |
|
| 8 |
|
| 9 |
-
FastMCP run command implementation.
|
| 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 |
-
### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 57 |
|
| 58 |
```python
|
| 59 |
create_client_server(url: str) -> Any
|
|
@@ -69,7 +69,7 @@ Create a FastMCP server from a client URL.
|
|
| 69 |
- A FastMCP server instance
|
| 70 |
|
| 71 |
|
| 72 |
-
### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 73 |
|
| 74 |
```python
|
| 75 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
@@ -87,10 +87,10 @@ Import a server with optional command line arguments.
|
|
| 87 |
- The imported server object
|
| 88 |
|
| 89 |
|
| 90 |
-
### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 91 |
|
| 92 |
```python
|
| 93 |
-
run_command(server_spec: str, transport:
|
| 94 |
```
|
| 95 |
|
| 96 |
|
|
@@ -101,6 +101,8 @@ Run a MCP server or connect to a remote one.
|
|
| 101 |
- `transport`: Transport protocol to use
|
| 102 |
- `host`: Host to bind to when using http transport
|
| 103 |
- `port`: Port to bind to when using http transport
|
|
|
|
| 104 |
- `log_level`: Log level
|
| 105 |
- `server_args`: Additional arguments to pass to the server
|
|
|
|
| 106 |
|
|
|
|
| 6 |
# `fastmcp.cli.run`
|
| 7 |
|
| 8 |
|
| 9 |
+
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#L18" 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#L24" 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#L55" 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 |
+
### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L125" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 57 |
|
| 58 |
```python
|
| 59 |
create_client_server(url: str) -> Any
|
|
|
|
| 69 |
- A FastMCP server instance
|
| 70 |
|
| 71 |
|
| 72 |
+
### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L145" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 73 |
|
| 74 |
```python
|
| 75 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
|
|
| 87 |
- The imported server object
|
| 88 |
|
| 89 |
|
| 90 |
+
### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L169" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 91 |
|
| 92 |
```python
|
| 93 |
+
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) -> None
|
| 94 |
```
|
| 95 |
|
| 96 |
|
|
|
|
| 101 |
- `transport`: Transport protocol to use
|
| 102 |
- `host`: Host to bind to when using http transport
|
| 103 |
- `port`: Port to bind to when using http transport
|
| 104 |
+
- `path`: Path to bind to when using http transport
|
| 105 |
- `log_level`: Log level
|
| 106 |
- `server_args`: Additional arguments to pass to the server
|
| 107 |
+
- `show_banner`: Whether to show the server banner
|
| 108 |
|
docs/python-sdk/fastmcp-client-auth-bearer.mdx
CHANGED
|
@@ -7,11 +7,11 @@ sidebarTitle: bearer
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `BearerAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/bearer.py#L11"><Icon icon="github"
|
| 11 |
|
| 12 |
**Methods:**
|
| 13 |
|
| 14 |
-
#### `auth_flow` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/bearer.py#L15"><Icon icon="github"
|
| 15 |
|
| 16 |
```python
|
| 17 |
auth_flow(self, request)
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `BearerAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/bearer.py#L11" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
**Methods:**
|
| 13 |
|
| 14 |
+
#### `auth_flow` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/bearer.py#L15" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 15 |
|
| 16 |
```python
|
| 17 |
auth_flow(self, request)
|
docs/python-sdk/fastmcp-client-auth-oauth.mdx
CHANGED
|
@@ -7,16 +7,46 @@ 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
```
|
| 21 |
|
| 22 |
|
|
@@ -38,52 +68,72 @@ httpx.AsyncClient (or appropriate FastMCP client/transport instance)
|
|
| 38 |
|
| 39 |
## Classes
|
| 40 |
|
| 41 |
-
### `
|
| 42 |
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
additional methods not in the MCP specification.
|
| 49 |
|
| 50 |
|
| 51 |
-
|
| 52 |
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
|
|
|
| 56 |
|
| 57 |
-
### `FileTokenStorage` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L116"><Icon icon="github" size="14" /></a></sup>
|
| 58 |
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
```python
|
| 71 |
-
|
| 72 |
```
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
|
| 77 |
-
#### `
|
| 78 |
|
| 79 |
```python
|
| 80 |
-
|
| 81 |
```
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
-
#### `clear` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 87 |
|
| 88 |
```python
|
| 89 |
clear(self) -> None
|
|
@@ -92,7 +142,7 @@ clear(self) -> None
|
|
| 92 |
Clear all cached data for this server.
|
| 93 |
|
| 94 |
|
| 95 |
-
#### `clear_all` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#
|
| 96 |
|
| 97 |
```python
|
| 98 |
clear_all(cls, cache_dir: Path | None = None) -> None
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_cache_dir` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L35" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_cache_dir() -> Path
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `discover_oauth_metadata` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Check if the MCP endpoint requires authentication by making a test request.
|
| 41 |
+
|
| 42 |
+
**Returns:**
|
| 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 |
|
|
|
|
| 68 |
|
| 69 |
## Classes
|
| 70 |
|
| 71 |
+
### `FileTokenStorage` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L39" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 72 |
|
| 73 |
|
| 74 |
+
File-based token storage implementation for OAuth credentials and tokens.
|
| 75 |
+
Implements the mcp.client.auth.TokenStorage protocol.
|
| 76 |
|
| 77 |
+
Each instance is tied to a specific server URL for proper token isolation.
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
+
**Methods:**
|
| 81 |
|
| 82 |
+
#### `get_base_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 83 |
|
| 84 |
+
```python
|
| 85 |
+
get_base_url(url: str) -> str
|
| 86 |
+
```
|
| 87 |
|
| 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#L59" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 92 |
|
| 93 |
+
```python
|
| 94 |
+
get_cache_key(self) -> str
|
| 95 |
+
```
|
| 96 |
|
| 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#L74" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
get_tokens(self) -> OAuthToken | None
|
| 104 |
+
```
|
| 105 |
|
| 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#L91" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 110 |
|
| 111 |
```python
|
| 112 |
+
set_tokens(self, tokens: OAuthToken) -> None
|
| 113 |
```
|
| 114 |
|
| 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#L97" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 119 |
|
| 120 |
```python
|
| 121 |
+
get_client_info(self) -> OAuthClientInformationFull | None
|
| 122 |
```
|
| 123 |
|
| 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#L125" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
+
|
| 129 |
+
```python
|
| 130 |
+
set_client_info(self, client_info: OAuthClientInformationFull) -> None
|
| 131 |
+
```
|
| 132 |
+
|
| 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#L131" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 137 |
|
| 138 |
```python
|
| 139 |
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#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 146 |
|
| 147 |
```python
|
| 148 |
clear_all(cls, cache_dir: Path | None = None) -> None
|
docs/python-sdk/fastmcp-client-client.mdx
CHANGED
|
@@ -7,7 +7,16 @@ sidebarTitle: client
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
MCP client that delegates connection management to a Transport instance.
|
|
@@ -16,14 +25,34 @@ The Client class is responsible for MCP protocol logic, while the Transport
|
|
| 16 |
handles connection establishment and management. Client provides methods for
|
| 17 |
working with resources, prompts, tools and other MCP capabilities.
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
**Args:**
|
| 20 |
-
- `transport`:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
-
|
| 24 |
-
-
|
| 25 |
-
-
|
| 26 |
-
-
|
|
|
|
|
|
|
| 27 |
- `roots`: Optional RootsList or RootsHandler for filesystem access
|
| 28 |
- `sampling_handler`: Optional handler for sampling requests
|
| 29 |
- `log_handler`: Optional handler for log messages
|
|
@@ -35,20 +64,22 @@ Set to 0 to disable. If None, uses the value in the FastMCP global settings.
|
|
| 35 |
|
| 36 |
**Examples:**
|
| 37 |
|
| 38 |
-
```python
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
async with client:
|
| 42 |
-
# List available resources
|
|
|
|
| 43 |
|
| 44 |
-
# Call a tool
|
| 45 |
-
"value"})
|
| 46 |
```
|
| 47 |
|
| 48 |
|
| 49 |
**Methods:**
|
| 50 |
|
| 51 |
-
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#
|
| 52 |
|
| 53 |
```python
|
| 54 |
session(self) -> ClientSession
|
|
@@ -57,7 +88,7 @@ session(self) -> ClientSession
|
|
| 57 |
Get the current active session. Raises RuntimeError if not connected.
|
| 58 |
|
| 59 |
|
| 60 |
-
#### `initialize_result` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#
|
| 61 |
|
| 62 |
```python
|
| 63 |
initialize_result(self) -> mcp.types.InitializeResult
|
|
@@ -66,7 +97,7 @@ initialize_result(self) -> mcp.types.InitializeResult
|
|
| 66 |
Get the result of the initialization request.
|
| 67 |
|
| 68 |
|
| 69 |
-
#### `set_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#
|
| 70 |
|
| 71 |
```python
|
| 72 |
set_roots(self, roots: RootsList | RootsHandler) -> None
|
|
@@ -75,7 +106,7 @@ set_roots(self, roots: RootsList | RootsHandler) -> None
|
|
| 75 |
Set the roots for the client. This does not automatically call `send_roots_list_changed`.
|
| 76 |
|
| 77 |
|
| 78 |
-
#### `set_sampling_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#
|
| 79 |
|
| 80 |
```python
|
| 81 |
set_sampling_callback(self, sampling_callback: SamplingHandler) -> None
|
|
@@ -84,7 +115,16 @@ set_sampling_callback(self, sampling_callback: SamplingHandler) -> None
|
|
| 84 |
Set the sampling callback for the client.
|
| 85 |
|
| 86 |
|
| 87 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
```python
|
| 90 |
is_connected(self) -> bool
|
|
@@ -92,3 +132,368 @@ is_connected(self) -> bool
|
|
| 92 |
|
| 93 |
Check if the client is currently connected.
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ClientSessionState` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L74" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Holds all session-related state for a Client instance.
|
| 14 |
+
|
| 15 |
+
This allows clean separation of configuration (which is copied) from
|
| 16 |
+
session state (which should be fresh for each new client instance).
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
### `Client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L90" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
MCP client that delegates connection management to a Transport instance.
|
|
|
|
| 25 |
handles connection establishment and management. Client provides methods for
|
| 26 |
working with resources, prompts, tools and other MCP capabilities.
|
| 27 |
|
| 28 |
+
This client supports reentrant context managers (multiple concurrent
|
| 29 |
+
`async with client:` blocks) using reference counting and background session
|
| 30 |
+
management. This allows efficient session reuse in any scenario with
|
| 31 |
+
nested or concurrent client usage.
|
| 32 |
+
|
| 33 |
+
MCP SDK 1.10 introduced automatic list_tools() calls during call_tool()
|
| 34 |
+
execution. This created a race condition where events could be reset while
|
| 35 |
+
other tasks were waiting on them, causing deadlocks. The issue was exposed
|
| 36 |
+
in proxy scenarios but affects any reentrant usage.
|
| 37 |
+
|
| 38 |
+
The solution uses reference counting to track active context managers,
|
| 39 |
+
a background task to manage the session lifecycle, events to coordinate
|
| 40 |
+
between tasks, and ensures all session state changes happen within a lock.
|
| 41 |
+
Events are only created when needed, never reset outside locks.
|
| 42 |
+
|
| 43 |
+
This design prevents race conditions where tasks wait on events that get
|
| 44 |
+
replaced by other tasks, ensuring reliable coordination in concurrent scenarios.
|
| 45 |
+
|
| 46 |
**Args:**
|
| 47 |
+
- `transport`:
|
| 48 |
+
Connection source specification, which can be\:
|
| 49 |
+
|
| 50 |
+
- ClientTransport\: Direct transport instance
|
| 51 |
+
- FastMCP\: In-process FastMCP server
|
| 52 |
+
- AnyUrl or str\: URL to connect to
|
| 53 |
+
- Path\: File path for local socket
|
| 54 |
+
- MCPConfig\: MCP server configuration
|
| 55 |
+
- dict\: Transport configuration
|
| 56 |
- `roots`: Optional RootsList or RootsHandler for filesystem access
|
| 57 |
- `sampling_handler`: Optional handler for sampling requests
|
| 58 |
- `log_handler`: Optional handler for log messages
|
|
|
|
| 64 |
|
| 65 |
**Examples:**
|
| 66 |
|
| 67 |
+
```python
|
| 68 |
+
# Connect to FastMCP server
|
| 69 |
+
client = Client("http://localhost:8080")
|
| 70 |
|
| 71 |
async with client:
|
| 72 |
+
# List available resources
|
| 73 |
+
resources = await client.list_resources()
|
| 74 |
|
| 75 |
+
# Call a tool
|
| 76 |
+
result = await client.call_tool("my_tool", {"param": "value"})
|
| 77 |
```
|
| 78 |
|
| 79 |
|
| 80 |
**Methods:**
|
| 81 |
|
| 82 |
+
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L273" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 83 |
|
| 84 |
```python
|
| 85 |
session(self) -> ClientSession
|
|
|
|
| 88 |
Get the current active session. Raises RuntimeError if not connected.
|
| 89 |
|
| 90 |
|
| 91 |
+
#### `initialize_result` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L283" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 92 |
|
| 93 |
```python
|
| 94 |
initialize_result(self) -> mcp.types.InitializeResult
|
|
|
|
| 97 |
Get the result of the initialization request.
|
| 98 |
|
| 99 |
|
| 100 |
+
#### `set_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L291" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 101 |
|
| 102 |
```python
|
| 103 |
set_roots(self, roots: RootsList | RootsHandler) -> None
|
|
|
|
| 106 |
Set the roots for the client. This does not automatically call `send_roots_list_changed`.
|
| 107 |
|
| 108 |
|
| 109 |
+
#### `set_sampling_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L295" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 110 |
|
| 111 |
```python
|
| 112 |
set_sampling_callback(self, sampling_callback: SamplingHandler) -> None
|
|
|
|
| 115 |
Set the sampling callback for the client.
|
| 116 |
|
| 117 |
|
| 118 |
+
#### `set_elicitation_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L301" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 119 |
+
|
| 120 |
+
```python
|
| 121 |
+
set_elicitation_callback(self, elicitation_callback: ElicitationHandler) -> None
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
Set the elicitation callback for the client.
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
#### `is_connected` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L309" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
|
| 129 |
```python
|
| 130 |
is_connected(self) -> bool
|
|
|
|
| 132 |
|
| 133 |
Check if the client is currently connected.
|
| 134 |
|
| 135 |
+
|
| 136 |
+
#### `new` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L313" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 137 |
+
|
| 138 |
+
```python
|
| 139 |
+
new(self) -> Client[ClientTransportT]
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
Create a new client instance with the same configuration but fresh session state.
|
| 143 |
+
|
| 144 |
+
This creates a new client with the same transport, handlers, and configuration,
|
| 145 |
+
but with no active session. Useful for creating independent sessions that don't
|
| 146 |
+
share state with the original client.
|
| 147 |
+
|
| 148 |
+
**Returns:**
|
| 149 |
+
- A new Client instance with the same configuration but disconnected state.
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
#### `close` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L476" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 153 |
+
|
| 154 |
+
```python
|
| 155 |
+
close(self)
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
#### `ping` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L482" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 159 |
+
|
| 160 |
+
```python
|
| 161 |
+
ping(self) -> bool
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
Send a ping request.
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
#### `cancel` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L487" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 168 |
+
|
| 169 |
+
```python
|
| 170 |
+
cancel(self, request_id: str | int, reason: str | None = None) -> None
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
Send a cancellation notification for an in-progress request.
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
#### `progress` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L504" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 177 |
+
|
| 178 |
+
```python
|
| 179 |
+
progress(self, progress_token: str | int, progress: float, total: float | None = None, message: str | None = None) -> None
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
Send a progress notification.
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
#### `set_logging_level` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L516" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 186 |
+
|
| 187 |
+
```python
|
| 188 |
+
set_logging_level(self, level: mcp.types.LoggingLevel) -> None
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
Send a logging/setLevel request.
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
#### `send_roots_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L520" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 195 |
+
|
| 196 |
+
```python
|
| 197 |
+
send_roots_list_changed(self) -> None
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
Send a roots/list_changed notification.
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
#### `list_resources_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L526" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 204 |
+
|
| 205 |
+
```python
|
| 206 |
+
list_resources_mcp(self) -> mcp.types.ListResourcesResult
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
Send a resources/list request and return the complete MCP protocol result.
|
| 210 |
+
|
| 211 |
+
**Returns:**
|
| 212 |
+
- mcp.types.ListResourcesResult: The complete response object from the protocol,
|
| 213 |
+
containing the list of resources and any additional metadata.
|
| 214 |
+
|
| 215 |
+
**Raises:**
|
| 216 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
#### `list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L539" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 220 |
+
|
| 221 |
+
```python
|
| 222 |
+
list_resources(self) -> list[mcp.types.Resource]
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
Retrieve a list of resources available on the server.
|
| 226 |
+
|
| 227 |
+
**Returns:**
|
| 228 |
+
- list\[mcp.types.Resource]: A list of Resource objects.
|
| 229 |
+
|
| 230 |
+
**Raises:**
|
| 231 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
#### `list_resource_templates_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L551" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 235 |
+
|
| 236 |
+
```python
|
| 237 |
+
list_resource_templates_mcp(self) -> mcp.types.ListResourceTemplatesResult
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
Send a resources/listResourceTemplates request and return the complete MCP protocol result.
|
| 241 |
+
|
| 242 |
+
**Returns:**
|
| 243 |
+
- mcp.types.ListResourceTemplatesResult: The complete response object from the protocol,
|
| 244 |
+
containing the list of resource templates and any additional metadata.
|
| 245 |
+
|
| 246 |
+
**Raises:**
|
| 247 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
#### `list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L566" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 251 |
+
|
| 252 |
+
```python
|
| 253 |
+
list_resource_templates(self) -> list[mcp.types.ResourceTemplate]
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
Retrieve a list of resource templates available on the server.
|
| 257 |
+
|
| 258 |
+
**Returns:**
|
| 259 |
+
- list\[mcp.types.ResourceTemplate]: A list of ResourceTemplate objects.
|
| 260 |
+
|
| 261 |
+
**Raises:**
|
| 262 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
#### `read_resource_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L580" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 266 |
+
|
| 267 |
+
```python
|
| 268 |
+
read_resource_mcp(self, uri: AnyUrl | str) -> mcp.types.ReadResourceResult
|
| 269 |
+
```
|
| 270 |
+
|
| 271 |
+
Send a resources/read request and return the complete MCP protocol result.
|
| 272 |
+
|
| 273 |
+
**Args:**
|
| 274 |
+
- `uri`: The URI of the resource to read. Can be a string or an AnyUrl object.
|
| 275 |
+
|
| 276 |
+
**Returns:**
|
| 277 |
+
- mcp.types.ReadResourceResult: The complete response object from the protocol,
|
| 278 |
+
containing the resource contents and any additional metadata.
|
| 279 |
+
|
| 280 |
+
**Raises:**
|
| 281 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L600" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 285 |
+
|
| 286 |
+
```python
|
| 287 |
+
read_resource(self, uri: AnyUrl | str) -> list[mcp.types.TextResourceContents | mcp.types.BlobResourceContents]
|
| 288 |
+
```
|
| 289 |
+
|
| 290 |
+
Read the contents of a resource or resolved template.
|
| 291 |
+
|
| 292 |
+
**Args:**
|
| 293 |
+
- `uri`: The URI of the resource to read. Can be a string or an AnyUrl object.
|
| 294 |
+
|
| 295 |
+
**Returns:**
|
| 296 |
+
- list\[mcp.types.TextResourceContents | mcp.types.BlobResourceContents]: A list of content
|
| 297 |
+
objects, typically containing either text or binary data.
|
| 298 |
+
|
| 299 |
+
**Raises:**
|
| 300 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
#### `list_prompts_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L639" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 304 |
+
|
| 305 |
+
```python
|
| 306 |
+
list_prompts_mcp(self) -> mcp.types.ListPromptsResult
|
| 307 |
+
```
|
| 308 |
+
|
| 309 |
+
Send a prompts/list request and return the complete MCP protocol result.
|
| 310 |
+
|
| 311 |
+
**Returns:**
|
| 312 |
+
- mcp.types.ListPromptsResult: The complete response object from the protocol,
|
| 313 |
+
containing the list of prompts and any additional metadata.
|
| 314 |
+
|
| 315 |
+
**Raises:**
|
| 316 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
#### `list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L652" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 320 |
+
|
| 321 |
+
```python
|
| 322 |
+
list_prompts(self) -> list[mcp.types.Prompt]
|
| 323 |
+
```
|
| 324 |
+
|
| 325 |
+
Retrieve a list of prompts available on the server.
|
| 326 |
+
|
| 327 |
+
**Returns:**
|
| 328 |
+
- list\[mcp.types.Prompt]: A list of Prompt objects.
|
| 329 |
+
|
| 330 |
+
**Raises:**
|
| 331 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
#### `get_prompt_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L665" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 335 |
+
|
| 336 |
+
```python
|
| 337 |
+
get_prompt_mcp(self, name: str, arguments: dict[str, Any] | None = None) -> mcp.types.GetPromptResult
|
| 338 |
+
```
|
| 339 |
+
|
| 340 |
+
Send a prompts/get request and return the complete MCP protocol result.
|
| 341 |
+
|
| 342 |
+
**Args:**
|
| 343 |
+
- `name`: The name of the prompt to retrieve.
|
| 344 |
+
- `arguments`: Arguments to pass to the prompt. Defaults to None.
|
| 345 |
+
|
| 346 |
+
**Returns:**
|
| 347 |
+
- mcp.types.GetPromptResult: The complete response object from the protocol,
|
| 348 |
+
containing the prompt messages and any additional metadata.
|
| 349 |
+
|
| 350 |
+
**Raises:**
|
| 351 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
#### `get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L699" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 355 |
+
|
| 356 |
+
```python
|
| 357 |
+
get_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> mcp.types.GetPromptResult
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
Retrieve a rendered prompt message list from the server.
|
| 361 |
+
|
| 362 |
+
**Args:**
|
| 363 |
+
- `name`: The name of the prompt to retrieve.
|
| 364 |
+
- `arguments`: Arguments to pass to the prompt. Defaults to None.
|
| 365 |
+
|
| 366 |
+
**Returns:**
|
| 367 |
+
- mcp.types.GetPromptResult: The complete response object from the protocol,
|
| 368 |
+
containing the prompt messages and any additional metadata.
|
| 369 |
+
|
| 370 |
+
**Raises:**
|
| 371 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
#### `complete_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L720" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 375 |
+
|
| 376 |
+
```python
|
| 377 |
+
complete_mcp(self, ref: mcp.types.ResourceReference | mcp.types.PromptReference, argument: dict[str, str]) -> mcp.types.CompleteResult
|
| 378 |
+
```
|
| 379 |
+
|
| 380 |
+
Send a completion request and return the complete MCP protocol result.
|
| 381 |
+
|
| 382 |
+
**Args:**
|
| 383 |
+
- `ref`: The reference to complete.
|
| 384 |
+
- `argument`: Arguments to pass to the completion request.
|
| 385 |
+
|
| 386 |
+
**Returns:**
|
| 387 |
+
- mcp.types.CompleteResult: The complete response object from the protocol,
|
| 388 |
+
containing the completion and any additional metadata.
|
| 389 |
+
|
| 390 |
+
**Raises:**
|
| 391 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
#### `complete` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L741" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 395 |
+
|
| 396 |
+
```python
|
| 397 |
+
complete(self, ref: mcp.types.ResourceReference | mcp.types.PromptReference, argument: dict[str, str]) -> mcp.types.Completion
|
| 398 |
+
```
|
| 399 |
+
|
| 400 |
+
Send a completion request to the server.
|
| 401 |
+
|
| 402 |
+
**Args:**
|
| 403 |
+
- `ref`: The reference to complete.
|
| 404 |
+
- `argument`: Arguments to pass to the completion request.
|
| 405 |
+
|
| 406 |
+
**Returns:**
|
| 407 |
+
- mcp.types.Completion: The completion object.
|
| 408 |
+
|
| 409 |
+
**Raises:**
|
| 410 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
#### `list_tools_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L763" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 414 |
+
|
| 415 |
+
```python
|
| 416 |
+
list_tools_mcp(self) -> mcp.types.ListToolsResult
|
| 417 |
+
```
|
| 418 |
+
|
| 419 |
+
Send a tools/list request and return the complete MCP protocol result.
|
| 420 |
+
|
| 421 |
+
**Returns:**
|
| 422 |
+
- mcp.types.ListToolsResult: The complete response object from the protocol,
|
| 423 |
+
containing the list of tools and any additional metadata.
|
| 424 |
+
|
| 425 |
+
**Raises:**
|
| 426 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
#### `list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L776" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 430 |
+
|
| 431 |
+
```python
|
| 432 |
+
list_tools(self) -> list[mcp.types.Tool]
|
| 433 |
+
```
|
| 434 |
+
|
| 435 |
+
Retrieve a list of tools available on the server.
|
| 436 |
+
|
| 437 |
+
**Returns:**
|
| 438 |
+
- list\[mcp.types.Tool]: A list of Tool objects.
|
| 439 |
+
|
| 440 |
+
**Raises:**
|
| 441 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
#### `call_tool_mcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L790" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 445 |
+
|
| 446 |
+
```python
|
| 447 |
+
call_tool_mcp(self, name: str, arguments: dict[str, Any], progress_handler: ProgressHandler | None = None, timeout: datetime.timedelta | float | int | None = None) -> mcp.types.CallToolResult
|
| 448 |
+
```
|
| 449 |
+
|
| 450 |
+
Send a tools/call request and return the complete MCP protocol result.
|
| 451 |
+
|
| 452 |
+
This method returns the raw CallToolResult object, which includes an isError flag
|
| 453 |
+
and other metadata. It does not raise an exception if the tool call results in an error.
|
| 454 |
+
|
| 455 |
+
**Args:**
|
| 456 |
+
- `name`: The name of the tool to call.
|
| 457 |
+
- `arguments`: Arguments to pass to the tool.
|
| 458 |
+
- `timeout`: The timeout for the tool call. Defaults to None.
|
| 459 |
+
- `progress_handler`: The progress handler to use for the tool call. Defaults to None.
|
| 460 |
+
|
| 461 |
+
**Returns:**
|
| 462 |
+
- mcp.types.CallToolResult: The complete response object from the protocol,
|
| 463 |
+
containing the tool result and any additional metadata.
|
| 464 |
+
|
| 465 |
+
**Raises:**
|
| 466 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
#### `call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L826" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 470 |
+
|
| 471 |
+
```python
|
| 472 |
+
call_tool(self, name: str, arguments: dict[str, Any] | None = None, timeout: datetime.timedelta | float | int | None = None, progress_handler: ProgressHandler | None = None, raise_on_error: bool = True) -> CallToolResult
|
| 473 |
+
```
|
| 474 |
+
|
| 475 |
+
Call a tool on the server.
|
| 476 |
+
|
| 477 |
+
Unlike call_tool_mcp, this method raises a ToolError if the tool call results in an error.
|
| 478 |
+
|
| 479 |
+
**Args:**
|
| 480 |
+
- `name`: The name of the tool to call.
|
| 481 |
+
- `arguments`: Arguments to pass to the tool. Defaults to None.
|
| 482 |
+
- `timeout`: The timeout for the tool call. Defaults to None.
|
| 483 |
+
- `progress_handler`: The progress handler to use for the tool call. Defaults to None.
|
| 484 |
+
|
| 485 |
+
**Returns:**
|
| 486 |
+
-
|
| 487 |
+
The content returned by the tool. If the tool returns structured
|
| 488 |
+
outputs, they are returned as a dataclass (if an output schema
|
| 489 |
+
is available) or a dictionary; otherwise, a list of content
|
| 490 |
+
blocks is returned. Note: to receive both structured and
|
| 491 |
+
unstructured outputs, use call_tool_mcp instead and access the
|
| 492 |
+
raw result object.
|
| 493 |
+
|
| 494 |
+
**Raises:**
|
| 495 |
+
- `ToolError`: If the tool call results in an error.
|
| 496 |
+
- `RuntimeError`: If called while the client is not connected.
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
### `CallToolResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L898" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
docs/python-sdk/fastmcp-client-elicitation.mdx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: elicitation
|
| 3 |
+
sidebarTitle: elicitation
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.elicitation`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `create_elicitation_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/elicitation.py#L36" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
create_elicitation_callback(elicitation_handler: ElicitationHandler) -> ElicitationFnT
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
## Classes
|
| 17 |
+
|
| 18 |
+
### `ElicitResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/elicitation.py#L21" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
docs/python-sdk/fastmcp-client-logging.mdx
CHANGED
|
@@ -7,7 +7,13 @@ sidebarTitle: logging
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
```python
|
| 13 |
create_log_callback(handler: LogHandler | None = None) -> LoggingFnT
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_log_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/logging.py#L15" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
default_log_handler(message: LogMessage) -> None
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### `create_log_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/logging.py#L19" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
create_log_callback(handler: LogHandler | None = None) -> LoggingFnT
|
docs/python-sdk/fastmcp-client-messages.mdx
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: messages
|
| 3 |
+
sidebarTitle: messages
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.messages`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `MessageHandler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L16" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
This class is used to handle MCP messages sent to the client. It is used to handle all messages,
|
| 14 |
+
requests, notifications, and exceptions. Users can override any of the hooks
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
**Methods:**
|
| 18 |
+
|
| 19 |
+
#### `dispatch` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L30" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
dispatch(self, message: Message) -> None
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
#### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L74" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
on_message(self, message: Message) -> None
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L77" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
on_request(self, message: RequestResponder[mcp.types.ServerRequest, mcp.types.ClientResult]) -> None
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
#### `on_ping` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L82" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
on_ping(self, message: mcp.types.PingRequest) -> None
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
#### `on_list_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L85" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
on_list_roots(self, message: mcp.types.ListRootsRequest) -> None
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
#### `on_create_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L88" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
on_create_message(self, message: mcp.types.CreateMessageRequest) -> None
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
#### `on_notification` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L91" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
on_notification(self, message: mcp.types.ServerNotification) -> None
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
#### `on_exception` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L94" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
on_exception(self, message: Exception) -> None
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
#### `on_progress` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L97" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
on_progress(self, message: mcp.types.ProgressNotification) -> None
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
#### `on_logging_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L100" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 74 |
+
|
| 75 |
+
```python
|
| 76 |
+
on_logging_message(self, message: mcp.types.LoggingMessageNotification) -> None
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
#### `on_tool_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L105" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
on_tool_list_changed(self, message: mcp.types.ToolListChangedNotification) -> None
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
#### `on_resource_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
on_resource_list_changed(self, message: mcp.types.ResourceListChangedNotification) -> None
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
#### `on_prompt_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L115" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 92 |
+
|
| 93 |
+
```python
|
| 94 |
+
on_prompt_list_changed(self, message: mcp.types.PromptListChangedNotification) -> None
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
#### `on_resource_updated` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L120" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 98 |
+
|
| 99 |
+
```python
|
| 100 |
+
on_resource_updated(self, message: mcp.types.ResourceUpdatedNotification) -> None
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
#### `on_cancelled` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/messages.py#L125" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
on_cancelled(self, message: mcp.types.CancelledNotification) -> None
|
| 107 |
+
```
|
docs/python-sdk/fastmcp-client-oauth_callback.mdx
CHANGED
|
@@ -15,7 +15,7 @@ and display styled responses to users.
|
|
| 15 |
|
| 16 |
## Functions
|
| 17 |
|
| 18 |
-
### `create_callback_html` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L25"><Icon icon="github"
|
| 19 |
|
| 20 |
```python
|
| 21 |
create_callback_html(message: str, is_success: bool = True, title: str = 'FastMCP OAuth', server_url: str | None = None) -> str
|
|
@@ -25,7 +25,7 @@ create_callback_html(message: str, is_success: bool = True, title: str = 'FastMC
|
|
| 25 |
Create a styled HTML response for OAuth callbacks.
|
| 26 |
|
| 27 |
|
| 28 |
-
### `create_oauth_callback_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L197"><Icon icon="github"
|
| 29 |
|
| 30 |
```python
|
| 31 |
create_oauth_callback_server(port: int, callback_path: str = '/callback', server_url: str | None = None, response_future: asyncio.Future | None = None) -> Server
|
|
@@ -46,17 +46,17 @@ Create an OAuth callback server.
|
|
| 46 |
|
| 47 |
## Classes
|
| 48 |
|
| 49 |
-
### `CallbackResponse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L183"><Icon icon="github"
|
| 50 |
|
| 51 |
**Methods:**
|
| 52 |
|
| 53 |
-
#### `from_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L190"><Icon icon="github"
|
| 54 |
|
| 55 |
```python
|
| 56 |
from_dict(cls, data: dict[str, str]) -> CallbackResponse
|
| 57 |
```
|
| 58 |
|
| 59 |
-
#### `to_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L193"><Icon icon="github"
|
| 60 |
|
| 61 |
```python
|
| 62 |
to_dict(self) -> dict[str, str]
|
|
|
|
| 15 |
|
| 16 |
## Functions
|
| 17 |
|
| 18 |
+
### `create_callback_html` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L25" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 19 |
|
| 20 |
```python
|
| 21 |
create_callback_html(message: str, is_success: bool = True, title: str = 'FastMCP OAuth', server_url: str | None = None) -> str
|
|
|
|
| 25 |
Create a styled HTML response for OAuth callbacks.
|
| 26 |
|
| 27 |
|
| 28 |
+
### `create_oauth_callback_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L197" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 29 |
|
| 30 |
```python
|
| 31 |
create_oauth_callback_server(port: int, callback_path: str = '/callback', server_url: str | None = None, response_future: asyncio.Future | None = None) -> Server
|
|
|
|
| 46 |
|
| 47 |
## Classes
|
| 48 |
|
| 49 |
+
### `CallbackResponse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L183" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 50 |
|
| 51 |
**Methods:**
|
| 52 |
|
| 53 |
+
#### `from_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L190" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 54 |
|
| 55 |
```python
|
| 56 |
from_dict(cls, data: dict[str, str]) -> CallbackResponse
|
| 57 |
```
|
| 58 |
|
| 59 |
+
#### `to_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L193" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 60 |
|
| 61 |
```python
|
| 62 |
to_dict(self) -> dict[str, str]
|
docs/python-sdk/fastmcp-client-progress.mdx
CHANGED
|
@@ -5,4 +5,21 @@ sidebarTitle: progress
|
|
| 5 |
|
| 6 |
# `fastmcp.client.progress`
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# `fastmcp.client.progress`
|
| 7 |
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `default_progress_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/progress.py#L12" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
default_progress_handler(progress: float, total: float | None, message: str | None) -> None
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Default handler for progress notifications.
|
| 18 |
+
|
| 19 |
+
Logs progress updates at debug level, properly handling missing total or message values.
|
| 20 |
+
|
| 21 |
+
**Args:**
|
| 22 |
+
- `progress`: Current progress value
|
| 23 |
+
- `total`: Optional total expected value
|
| 24 |
+
- `message`: Optional status message
|
| 25 |
+
|
docs/python-sdk/fastmcp-client-roots.mdx
CHANGED
|
@@ -7,13 +7,13 @@ sidebarTitle: roots
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `convert_roots_list` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/roots.py#L19"><Icon icon="github"
|
| 11 |
|
| 12 |
```python
|
| 13 |
convert_roots_list(roots: RootsList) -> list[mcp.types.Root]
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `create_roots_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/roots.py#L33"><Icon icon="github"
|
| 17 |
|
| 18 |
```python
|
| 19 |
create_roots_callback(handler: RootsList | RootsHandler) -> ListRootsFnT
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `convert_roots_list` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/roots.py#L19" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
convert_roots_list(roots: RootsList) -> list[mcp.types.Root]
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `create_roots_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/roots.py#L33" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
create_roots_callback(handler: RootsList | RootsHandler) -> ListRootsFnT
|
docs/python-sdk/fastmcp-client-sampling.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: sampling
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `create_sampling_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/sampling.py#L25"><Icon icon="github"
|
| 11 |
|
| 12 |
```python
|
| 13 |
create_sampling_callback(sampling_handler: SamplingHandler) -> SamplingFnT
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `create_sampling_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/sampling.py#L25" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
create_sampling_callback(sampling_handler: SamplingHandler) -> SamplingFnT
|
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.
|
|
@@ -72,25 +72,79 @@ A Transport is responsible for establishing and managing connections
|
|
| 72 |
to an MCP server, and providing a ClientSession within an async context.
|
| 73 |
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
|
| 78 |
Transport implementation that connects to an MCP server via WebSockets.
|
| 79 |
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
Transport implementation that connects to an MCP server via Server-Sent Events.
|
| 85 |
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
Transport implementation that connects to an MCP server via Streamable HTTP Requests.
|
| 91 |
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
Base transport for connecting to an MCP server via subprocess with stdio.
|
|
@@ -99,37 +153,63 @@ This is a base class that can be subclassed for specific command-based
|
|
| 99 |
transports like Python, Node, Uvx, etc.
|
| 100 |
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
Transport for running Python scripts.
|
| 106 |
|
| 107 |
|
| 108 |
-
### `FastMCPStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 109 |
|
| 110 |
|
| 111 |
Transport for running FastMCP servers using the FastMCP CLI.
|
| 112 |
|
| 113 |
|
| 114 |
-
### `NodeStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 115 |
|
| 116 |
|
| 117 |
Transport for running Node.js scripts.
|
| 118 |
|
| 119 |
|
| 120 |
-
### `UvxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 121 |
|
| 122 |
|
| 123 |
Transport for running commands via the uvx tool.
|
| 124 |
|
| 125 |
|
| 126 |
-
### `NpxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 127 |
|
| 128 |
|
| 129 |
Transport for running commands via the npx tool.
|
| 130 |
|
| 131 |
|
| 132 |
-
### `FastMCPTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 133 |
|
| 134 |
|
| 135 |
In-memory transport for FastMCP servers.
|
|
@@ -140,7 +220,15 @@ servers from the low-level MCP SDK. This is particularly useful for unit
|
|
| 140 |
tests or scenarios where client and server run in the same runtime.
|
| 141 |
|
| 142 |
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
|
| 146 |
Transport for connecting to one or more MCP servers defined in an MCPConfig.
|
|
@@ -190,3 +278,11 @@ async with client:
|
|
| 190 |
icons = await client.read_resource("weather://weather/icons/sunny")
|
| 191 |
```
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `infer_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L849" 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#L57" 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#L69" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 67 |
|
| 68 |
|
| 69 |
Abstract base class for different MCP client transport mechanisms.
|
|
|
|
| 72 |
to an MCP server, and providing a ClientSession within an async context.
|
| 73 |
|
| 74 |
|
| 75 |
+
**Methods:**
|
| 76 |
+
|
| 77 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L80" 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]
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
Establishes a connection and yields an active ClientSession.
|
| 84 |
+
|
| 85 |
+
The ClientSession is *not* expected to be initialized in this context manager.
|
| 86 |
+
|
| 87 |
+
The session is guaranteed to be valid only within the scope of the
|
| 88 |
+
async context manager. Connection setup and teardown are handled
|
| 89 |
+
within this context.
|
| 90 |
+
|
| 91 |
+
**Args:**
|
| 92 |
+
- `**session_kwargs`: Keyword arguments to pass to the 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#L106" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
close(self)
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
Close the transport.
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
### `WSTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L115" 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.
|
| 109 |
|
| 110 |
|
| 111 |
+
**Methods:**
|
| 112 |
+
|
| 113 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L133" 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#L154" 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.
|
| 123 |
|
| 124 |
|
| 125 |
+
**Methods:**
|
| 126 |
+
|
| 127 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L190" 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#L226" 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.
|
| 137 |
|
| 138 |
|
| 139 |
+
**Methods:**
|
| 140 |
+
|
| 141 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L262" 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#L299" 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.
|
|
|
|
| 153 |
transports like Python, Node, Uvx, etc.
|
| 154 |
|
| 155 |
|
| 156 |
+
**Methods:**
|
| 157 |
+
|
| 158 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L342" 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#L355" 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#L406" 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#L421" 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#L430" 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#L476" 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#L503" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 195 |
|
| 196 |
|
| 197 |
Transport for running Node.js scripts.
|
| 198 |
|
| 199 |
|
| 200 |
+
### `UvxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L545" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L611" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L673" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 213 |
|
| 214 |
|
| 215 |
In-memory transport for FastMCP servers.
|
|
|
|
| 220 |
tests or scenarios where client and server run in the same runtime.
|
| 221 |
|
| 222 |
|
| 223 |
+
**Methods:**
|
| 224 |
+
|
| 225 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L692" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L727" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 232 |
|
| 233 |
|
| 234 |
Transport for connecting to one or more MCP servers defined in an MCPConfig.
|
|
|
|
| 278 |
icons = await client.read_resource("weather://weather/icons/sunny")
|
| 279 |
```
|
| 280 |
|
| 281 |
+
|
| 282 |
+
**Methods:**
|
| 283 |
+
|
| 284 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L801" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 285 |
+
|
| 286 |
+
```python
|
| 287 |
+
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
| 288 |
+
```
|
docs/python-sdk/fastmcp-exceptions.mdx
CHANGED
|
@@ -10,55 +10,55 @@ Custom exceptions for FastMCP.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `FastMCPError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L6"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
Base error for FastMCP.
|
| 17 |
|
| 18 |
|
| 19 |
-
### `ValidationError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L10"><Icon icon="github"
|
| 20 |
|
| 21 |
|
| 22 |
Error in validating parameters or return values.
|
| 23 |
|
| 24 |
|
| 25 |
-
### `ResourceError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L14"><Icon icon="github"
|
| 26 |
|
| 27 |
|
| 28 |
Error in resource operations.
|
| 29 |
|
| 30 |
|
| 31 |
-
### `ToolError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L18"><Icon icon="github"
|
| 32 |
|
| 33 |
|
| 34 |
Error in tool operations.
|
| 35 |
|
| 36 |
|
| 37 |
-
### `PromptError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L22"><Icon icon="github"
|
| 38 |
|
| 39 |
|
| 40 |
Error in prompt operations.
|
| 41 |
|
| 42 |
|
| 43 |
-
### `InvalidSignature` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L26"><Icon icon="github"
|
| 44 |
|
| 45 |
|
| 46 |
Invalid signature for use with FastMCP.
|
| 47 |
|
| 48 |
|
| 49 |
-
### `ClientError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L30"><Icon icon="github"
|
| 50 |
|
| 51 |
|
| 52 |
Error in client operations.
|
| 53 |
|
| 54 |
|
| 55 |
-
### `NotFoundError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L34"><Icon icon="github"
|
| 56 |
|
| 57 |
|
| 58 |
Object not found.
|
| 59 |
|
| 60 |
|
| 61 |
-
### `DisabledError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L38"><Icon icon="github"
|
| 62 |
|
| 63 |
|
| 64 |
Object is disabled.
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `FastMCPError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L6" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Base error for FastMCP.
|
| 17 |
|
| 18 |
|
| 19 |
+
### `ValidationError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L10" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
Error in validating parameters or return values.
|
| 23 |
|
| 24 |
|
| 25 |
+
### `ResourceError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L14" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 26 |
|
| 27 |
|
| 28 |
Error in resource operations.
|
| 29 |
|
| 30 |
|
| 31 |
+
### `ToolError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L18" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 32 |
|
| 33 |
|
| 34 |
Error in tool operations.
|
| 35 |
|
| 36 |
|
| 37 |
+
### `PromptError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L22" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 38 |
|
| 39 |
|
| 40 |
Error in prompt operations.
|
| 41 |
|
| 42 |
|
| 43 |
+
### `InvalidSignature` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L26" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 44 |
|
| 45 |
|
| 46 |
Invalid signature for use with FastMCP.
|
| 47 |
|
| 48 |
|
| 49 |
+
### `ClientError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L30" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 50 |
|
| 51 |
|
| 52 |
Error in client operations.
|
| 53 |
|
| 54 |
|
| 55 |
+
### `NotFoundError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L34" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 56 |
|
| 57 |
|
| 58 |
Object not found.
|
| 59 |
|
| 60 |
|
| 61 |
+
### `DisabledError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 62 |
|
| 63 |
|
| 64 |
Object is disabled.
|
docs/python-sdk/fastmcp-mcp_config.mdx
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: mcp_config
|
| 3 |
+
sidebarTitle: mcp_config
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.mcp_config`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Canonical MCP Configuration Format.
|
| 10 |
+
|
| 11 |
+
This module defines the standard configuration format for Model Context Protocol (MCP) servers.
|
| 12 |
+
It provides a client-agnostic, extensible format that can be used across all MCP implementations.
|
| 13 |
+
|
| 14 |
+
The configuration format supports both stdio and remote (HTTP/SSE) transports, with comprehensive
|
| 15 |
+
field definitions for server metadata, authentication, and execution parameters.
|
| 16 |
+
|
| 17 |
+
Example configuration:
|
| 18 |
+
{
|
| 19 |
+
"mcpServers": {
|
| 20 |
+
"my-server": {
|
| 21 |
+
"command": "npx",
|
| 22 |
+
"args": ["-y", "@my/mcp-server"],
|
| 23 |
+
"env": {"API_KEY": "secret"},
|
| 24 |
+
"timeout": 30000,
|
| 25 |
+
"description": "My MCP server"
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
## Functions
|
| 32 |
+
|
| 33 |
+
### `infer_transport_type_from_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L43" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
infer_transport_type_from_url(url: str | AnyUrl) -> Literal['http', 'sse']
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Infer the appropriate transport type from the given URL.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
### `update_config_file` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L253" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
update_config_file(file_path: Path, server_name: str, server_config: StdioMCPServer | RemoteMCPServer) -> None
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Update MCP configuration file with new server, preserving existing fields.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
## Classes
|
| 54 |
+
|
| 55 |
+
### `StdioMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L63" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
MCP server configuration for stdio transport.
|
| 59 |
+
|
| 60 |
+
This is the canonical configuration format for MCP servers using stdio transport.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
**Methods:**
|
| 64 |
+
|
| 65 |
+
#### `to_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L93" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
to_transport(self) -> StdioTransport
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### `RemoteMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L104" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
MCP server configuration for HTTP/SSE transport.
|
| 75 |
+
|
| 76 |
+
This is the canonical configuration format for MCP servers using remote transports.
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
**Methods:**
|
| 80 |
+
|
| 81 |
+
#### `to_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
to_transport(self) -> StreamableHttpTransport | SSETransport
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### `MCPConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L165" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
Canonical MCP configuration format.
|
| 91 |
+
|
| 92 |
+
This defines the standard configuration format for Model Context Protocol servers.
|
| 93 |
+
The format is designed to be client-agnostic and extensible for future use cases.
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
**Methods:**
|
| 97 |
+
|
| 98 |
+
#### `from_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L177" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 99 |
+
|
| 100 |
+
```python
|
| 101 |
+
from_dict(cls, config: dict[str, Any]) -> MCPConfig
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
Parse MCP configuration from dictionary format.
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
#### `to_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L212" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
to_dict(self) -> dict[str, Any]
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
Convert MCPConfig to dictionary format, preserving all fields.
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
#### `write_to_file` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L225" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 117 |
+
|
| 118 |
+
```python
|
| 119 |
+
write_to_file(self, file_path: Path) -> None
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
Write configuration to JSON file.
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
#### `from_file` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L232" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 126 |
+
|
| 127 |
+
```python
|
| 128 |
+
from_file(cls, file_path: Path) -> MCPConfig
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Load configuration from JSON file.
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
#### `add_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L243" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 135 |
+
|
| 136 |
+
```python
|
| 137 |
+
add_server(self, name: str, server: StdioMCPServer | RemoteMCPServer) -> None
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
Add or update a server in the configuration.
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
#### `remove_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L247" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 144 |
+
|
| 145 |
+
```python
|
| 146 |
+
remove_server(self, name: str) -> None
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
Remove a server from the configuration.
|
| 150 |
+
|
docs/python-sdk/fastmcp-prompts-prompt.mdx
CHANGED
|
@@ -10,10 +10,10 @@ Base classes for FastMCP prompts.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `Message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
-
Message(content: str |
|
| 17 |
```
|
| 18 |
|
| 19 |
|
|
@@ -22,13 +22,13 @@ A user-friendly constructor for PromptMessage.
|
|
| 22 |
|
| 23 |
## Classes
|
| 24 |
|
| 25 |
-
### `PromptArgument` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 26 |
|
| 27 |
|
| 28 |
An argument that can be passed to a prompt.
|
| 29 |
|
| 30 |
|
| 31 |
-
### `Prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 32 |
|
| 33 |
|
| 34 |
A prompt template that can be rendered with parameters.
|
|
@@ -36,7 +36,19 @@ A prompt template that can be rendered with parameters.
|
|
| 36 |
|
| 37 |
**Methods:**
|
| 38 |
|
| 39 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
```python
|
| 42 |
to_mcp_prompt(self, **overrides: Any) -> MCPPrompt
|
|
@@ -45,10 +57,10 @@ to_mcp_prompt(self, **overrides: Any) -> MCPPrompt
|
|
| 45 |
Convert the prompt to an MCP prompt.
|
| 46 |
|
| 47 |
|
| 48 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 49 |
|
| 50 |
```python
|
| 51 |
-
from_function(fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
| 52 |
```
|
| 53 |
|
| 54 |
Create a Prompt from a function.
|
|
@@ -60,7 +72,16 @@ The function can return:
|
|
| 60 |
- A sequence of any of the above
|
| 61 |
|
| 62 |
|
| 63 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
A prompt that is a function.
|
|
@@ -68,10 +89,10 @@ A prompt that is a function.
|
|
| 68 |
|
| 69 |
**Methods:**
|
| 70 |
|
| 71 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#
|
| 72 |
|
| 73 |
```python
|
| 74 |
-
from_function(cls, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
| 75 |
```
|
| 76 |
|
| 77 |
Create a Prompt from a function.
|
|
@@ -82,3 +103,12 @@ The function can return:
|
|
| 82 |
- A dict (converted to a message)
|
| 83 |
- A sequence of any of the above
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `Message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L31" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
+
Message(content: str | ContentBlock, role: Role | None = None, **kwargs: Any) -> PromptMessage
|
| 17 |
```
|
| 18 |
|
| 19 |
|
|
|
|
| 22 |
|
| 23 |
## Classes
|
| 24 |
|
| 25 |
+
### `PromptArgument` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L53" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 26 |
|
| 27 |
|
| 28 |
An argument that can be passed to a prompt.
|
| 29 |
|
| 30 |
|
| 31 |
+
### `Prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L65" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 32 |
|
| 33 |
|
| 34 |
A prompt template that can be rendered with parameters.
|
|
|
|
| 36 |
|
| 37 |
**Methods:**
|
| 38 |
|
| 39 |
+
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
enable(self) -> None
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L80" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
disable(self) -> None
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
#### `to_mcp_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L88" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 52 |
|
| 53 |
```python
|
| 54 |
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#L107" 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) -> 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#L133" 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]
|
| 79 |
+
```
|
| 80 |
+
|
| 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#L141" 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#L147" 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) -> FunctionPrompt
|
| 96 |
```
|
| 97 |
|
| 98 |
Create a Prompt from a function.
|
|
|
|
| 103 |
- A dict (converted to a message)
|
| 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#L305" 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]
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
Render the prompt with arguments.
|
| 114 |
+
|
docs/python-sdk/fastmcp-prompts-prompt_manager.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: prompt_manager
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `PromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L21"><Icon icon="github"
|
| 11 |
|
| 12 |
|
| 13 |
Manages FastMCP prompts.
|
|
@@ -15,7 +15,7 @@ Manages FastMCP prompts.
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
-
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L45"><Icon icon="github"
|
| 19 |
|
| 20 |
```python
|
| 21 |
mount(self, server: MountedServer) -> None
|
|
@@ -24,7 +24,43 @@ mount(self, server: MountedServer) -> None
|
|
| 24 |
Adds a mounted server as a source for prompts.
|
| 25 |
|
| 26 |
|
| 27 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
```python
|
| 30 |
add_prompt_from_fn(self, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None) -> FunctionPrompt
|
|
@@ -33,7 +69,7 @@ add_prompt_from_fn(self, fn: Callable[..., PromptResult | Awaitable[PromptResult
|
|
| 33 |
Create a prompt from a function.
|
| 34 |
|
| 35 |
|
| 36 |
-
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L134"><Icon icon="github"
|
| 37 |
|
| 38 |
```python
|
| 39 |
add_prompt(self, prompt: Prompt) -> Prompt
|
|
@@ -41,3 +77,13 @@ add_prompt(self, prompt: Prompt) -> Prompt
|
|
| 41 |
|
| 42 |
Add a prompt to the manager.
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `PromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L21" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
Manages FastMCP prompts.
|
|
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L45" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 19 |
|
| 20 |
```python
|
| 21 |
mount(self, server: MountedServer) -> None
|
|
|
|
| 24 |
Adds a mounted server as a source for prompts.
|
| 25 |
|
| 26 |
|
| 27 |
+
#### `has_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L89" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
has_prompt(self, key: str) -> bool
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Check if a prompt exists.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#### `get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L94" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
get_prompt(self, key: str) -> Prompt
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Get prompt by key.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L101" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
get_prompts(self) -> dict[str, Prompt]
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Gets the complete, unfiltered inventory of all prompts.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
#### `list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L107" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
list_prompts(self) -> list[Prompt]
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
Lists all prompts, applying protocol filtering.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
#### `add_prompt_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L114" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
|
| 65 |
```python
|
| 66 |
add_prompt_from_fn(self, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None) -> FunctionPrompt
|
|
|
|
| 69 |
Create a prompt from a function.
|
| 70 |
|
| 71 |
|
| 72 |
+
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 73 |
|
| 74 |
```python
|
| 75 |
add_prompt(self, prompt: Prompt) -> Prompt
|
|
|
|
| 77 |
|
| 78 |
Add a prompt to the manager.
|
| 79 |
|
| 80 |
+
|
| 81 |
+
#### `render_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L152" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
render_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> GetPromptResult
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
Internal API for servers: Finds and renders a prompt, respecting the
|
| 88 |
+
filtered protocol path.
|
| 89 |
+
|
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#L32"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
Base class for all resources.
|
|
@@ -18,13 +18,25 @@ Base class for all resources.
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
-
#### `
|
| 22 |
|
| 23 |
```python
|
| 24 |
-
|
| 25 |
```
|
| 26 |
|
| 27 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
```python
|
| 30 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
@@ -33,7 +45,7 @@ set_default_mime_type(cls, mime_type: str | None) -> str
|
|
| 33 |
Set default MIME type if not provided.
|
| 34 |
|
| 35 |
|
| 36 |
-
#### `set_default_name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
set_default_name(self) -> Self
|
|
@@ -42,7 +54,16 @@ set_default_name(self) -> Self
|
|
| 42 |
Set default name from URI if not provided.
|
| 43 |
|
| 44 |
|
| 45 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
```python
|
| 48 |
to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
@@ -51,7 +72,7 @@ to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
| 51 |
Convert the resource to an MCPResource.
|
| 52 |
|
| 53 |
|
| 54 |
-
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 55 |
|
| 56 |
```python
|
| 57 |
key(self) -> str
|
|
@@ -63,7 +84,7 @@ keys having a certain value, as the same tool loaded from different
|
|
| 63 |
hierarchies of servers may have different keys.
|
| 64 |
|
| 65 |
|
| 66 |
-
### `FunctionResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 67 |
|
| 68 |
|
| 69 |
A resource that defers data loading by wrapping a function.
|
|
@@ -80,11 +101,20 @@ The function can return:
|
|
| 80 |
|
| 81 |
**Methods:**
|
| 82 |
|
| 83 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#
|
| 84 |
|
| 85 |
```python
|
| 86 |
-
from_function(cls, fn: Callable[
|
| 87 |
```
|
| 88 |
|
| 89 |
Create a FunctionResource from a function.
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `Resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L32" 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#L47" 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#L55" 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#L64" 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) -> FunctionResource
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L87" 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#L94" 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#L105" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
read(self) -> str | bytes
|
| 61 |
+
```
|
| 62 |
+
|
| 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#L109" 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#L124" 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#L134" 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#L150" 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) -> 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#L175" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 114 |
+
|
| 115 |
+
```python
|
| 116 |
+
read(self) -> str | bytes
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
Read the resource by calling the wrapped function.
|
| 120 |
+
|
docs/python-sdk/fastmcp-resources-resource_manager.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Resource manager functionality.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `ResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L28"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
Manages FastMCP resources.
|
|
@@ -18,7 +18,7 @@ Manages FastMCP resources.
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
-
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L60"><Icon icon="github"
|
| 22 |
|
| 23 |
```python
|
| 24 |
mount(self, server: MountedServer) -> None
|
|
@@ -27,7 +27,43 @@ mount(self, server: MountedServer) -> None
|
|
| 27 |
Adds a mounted server as a source for resources and templates.
|
| 28 |
|
| 29 |
|
| 30 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
```python
|
| 33 |
add_resource_or_template_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource | ResourceTemplate
|
|
@@ -48,7 +84,7 @@ Add a resource or template to the manager from a function.
|
|
| 48 |
- returns the existing resource or template.
|
| 49 |
|
| 50 |
|
| 51 |
-
#### `add_resource_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L230"><Icon icon="github"
|
| 52 |
|
| 53 |
```python
|
| 54 |
add_resource_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource
|
|
@@ -69,7 +105,7 @@ Add a resource to the manager from a function.
|
|
| 69 |
- returns the existing resource.
|
| 70 |
|
| 71 |
|
| 72 |
-
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L270"><Icon icon="github"
|
| 73 |
|
| 74 |
```python
|
| 75 |
add_resource(self, resource: Resource) -> Resource
|
|
@@ -83,7 +119,7 @@ will be used as the storage key. To overwrite it, call
|
|
| 83 |
Resource.with_key() before calling this method.
|
| 84 |
|
| 85 |
|
| 86 |
-
#### `add_template_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L292"><Icon icon="github"
|
| 87 |
|
| 88 |
```python
|
| 89 |
add_template_from_fn(self, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> ResourceTemplate
|
|
@@ -92,7 +128,7 @@ add_template_from_fn(self, fn: Callable[..., Any], uri_template: str, name: str
|
|
| 92 |
Create a template from a function.
|
| 93 |
|
| 94 |
|
| 95 |
-
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L319"><Icon icon="github"
|
| 96 |
|
| 97 |
```python
|
| 98 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
|
@@ -109,3 +145,37 @@ ResourceTemplate.with_key() before calling this method.
|
|
| 109 |
- The added template. If a template with the same URI already exists,
|
| 110 |
- returns the existing template.
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `ResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L28" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Manages FastMCP resources.
|
|
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 22 |
|
| 23 |
```python
|
| 24 |
mount(self, server: MountedServer) -> None
|
|
|
|
| 27 |
Adds a mounted server as a source for resources and templates.
|
| 28 |
|
| 29 |
|
| 30 |
+
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L64" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
get_resources(self) -> dict[str, Resource]
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
Get all registered resources, keyed by URI.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L68" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Get all registered templates, keyed by URI template.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
#### `list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L168" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
list_resources(self) -> list[Resource]
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
Lists all resources, applying protocol filtering.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
#### `list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L175" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
list_resource_templates(self) -> list[ResourceTemplate]
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Lists all templates, applying protocol filtering.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
#### `add_resource_or_template_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 67 |
|
| 68 |
```python
|
| 69 |
add_resource_or_template_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource | ResourceTemplate
|
|
|
|
| 84 |
- returns the existing resource or template.
|
| 85 |
|
| 86 |
|
| 87 |
+
#### `add_resource_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L230" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 88 |
|
| 89 |
```python
|
| 90 |
add_resource_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource
|
|
|
|
| 105 |
- returns the existing resource.
|
| 106 |
|
| 107 |
|
| 108 |
+
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L270" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 109 |
|
| 110 |
```python
|
| 111 |
add_resource(self, resource: Resource) -> Resource
|
|
|
|
| 119 |
Resource.with_key() before calling this method.
|
| 120 |
|
| 121 |
|
| 122 |
+
#### `add_template_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L292" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 123 |
|
| 124 |
```python
|
| 125 |
add_template_from_fn(self, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> ResourceTemplate
|
|
|
|
| 128 |
Create a template from a function.
|
| 129 |
|
| 130 |
|
| 131 |
+
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L319" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 132 |
|
| 133 |
```python
|
| 134 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
|
|
|
| 145 |
- The added template. If a template with the same URI already exists,
|
| 146 |
- returns the existing template.
|
| 147 |
|
| 148 |
+
|
| 149 |
+
#### `has_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L345" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 150 |
+
|
| 151 |
+
```python
|
| 152 |
+
has_resource(self, uri: AnyUrl | str) -> bool
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
Check if a resource exists.
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
#### `get_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L362" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 159 |
+
|
| 160 |
+
```python
|
| 161 |
+
get_resource(self, uri: AnyUrl | str) -> Resource
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
Get resource by URI, checking concrete resources first, then templates.
|
| 165 |
+
|
| 166 |
+
**Args:**
|
| 167 |
+
- `uri`: The URI of the resource to get
|
| 168 |
+
|
| 169 |
+
**Raises:**
|
| 170 |
+
- `NotFoundError`: If no resource or template matching the URI is found.
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L407" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 174 |
+
|
| 175 |
+
```python
|
| 176 |
+
read_resource(self, uri: AnyUrl | str) -> str | bytes
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
Internal API for servers: Finds and reads a resource, respecting the
|
| 180 |
+
filtered protocol path.
|
| 181 |
+
|
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#L28"><Icon icon="github"
|
| 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#L44"><Icon icon="github"
|
| 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#L52"><Icon icon="github"
|
| 28 |
|
| 29 |
|
| 30 |
A template for dynamically creating resources.
|
|
@@ -32,13 +32,25 @@ A template for dynamically creating resources.
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
-
#### `
|
| 36 |
|
| 37 |
```python
|
| 38 |
-
|
| 39 |
```
|
| 40 |
|
| 41 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
```python
|
| 44 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
@@ -47,7 +59,7 @@ set_default_mime_type(cls, mime_type: str | None) -> str
|
|
| 47 |
Set default MIME type if not provided.
|
| 48 |
|
| 49 |
|
| 50 |
-
#### `matches` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 51 |
|
| 52 |
```python
|
| 53 |
matches(self, uri: str) -> dict[str, Any] | None
|
|
@@ -56,7 +68,25 @@ matches(self, uri: str) -> dict[str, Any] | None
|
|
| 56 |
Check if URI matches template and extract parameters.
|
| 57 |
|
| 58 |
|
| 59 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
```python
|
| 62 |
to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
@@ -65,7 +95,7 @@ to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
| 65 |
Convert the resource template to an MCPResourceTemplate.
|
| 66 |
|
| 67 |
|
| 68 |
-
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 69 |
|
| 70 |
```python
|
| 71 |
from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
@@ -74,7 +104,7 @@ from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
| 74 |
Creates a FastMCP ResourceTemplate from a raw MCP ResourceTemplate object.
|
| 75 |
|
| 76 |
|
| 77 |
-
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 78 |
|
| 79 |
```python
|
| 80 |
key(self) -> str
|
|
@@ -86,7 +116,7 @@ keys having a certain value, as the same tool loaded from different
|
|
| 86 |
hierarchies of servers may have different keys.
|
| 87 |
|
| 88 |
|
| 89 |
-
### `FunctionResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#
|
| 90 |
|
| 91 |
|
| 92 |
A template for dynamically creating resources.
|
|
@@ -94,10 +124,19 @@ A template for dynamically creating resources.
|
|
| 94 |
|
| 95 |
**Methods:**
|
| 96 |
|
| 97 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
```python
|
| 100 |
-
from_function(cls, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
| 101 |
```
|
| 102 |
|
| 103 |
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#L28" 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#L44" 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#L52" 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#L68" 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#L76" 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#L85" 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) -> FunctionResourceTemplate
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L108" 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#L114" 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#L118" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
read(self, arguments: dict[str, Any]) -> str | bytes
|
| 75 |
+
```
|
| 76 |
+
|
| 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#L124" 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
|
| 84 |
+
```
|
| 85 |
+
|
| 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#L142" 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#L154" 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#L167" 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#L177" 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#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
+
|
| 129 |
+
```python
|
| 130 |
+
read(self, arguments: dict[str, Any]) -> str | bytes
|
| 131 |
+
```
|
| 132 |
+
|
| 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#L198" 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) -> FunctionResourceTemplate
|
| 140 |
```
|
| 141 |
|
| 142 |
Create a template from a function.
|
docs/python-sdk/fastmcp-resources-types.mdx
CHANGED
|
@@ -10,19 +10,41 @@ Concrete resource implementations.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `TextResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L21"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
A resource that reads from a string.
|
| 17 |
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
A resource that reads from bytes.
|
| 23 |
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
A resource that reads from a file.
|
|
@@ -32,7 +54,7 @@ Set is_binary=True to read file as binary data instead of text.
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
-
#### `validate_absolute_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L59"><Icon icon="github"
|
| 36 |
|
| 37 |
```python
|
| 38 |
validate_absolute_path(cls, path: Path) -> Path
|
|
@@ -41,7 +63,7 @@ validate_absolute_path(cls, path: Path) -> Path
|
|
| 41 |
Ensure path is absolute.
|
| 42 |
|
| 43 |
|
| 44 |
-
#### `set_binary_from_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L67"><Icon icon="github"
|
| 45 |
|
| 46 |
```python
|
| 47 |
set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool
|
|
@@ -50,13 +72,33 @@ set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool
|
|
| 50 |
Set is_binary based on mime_type if not explicitly set.
|
| 51 |
|
| 52 |
|
| 53 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
A resource that reads from an HTTP endpoint.
|
| 57 |
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
A resource that lists files in a directory.
|
|
@@ -64,7 +106,7 @@ A resource that lists files in a directory.
|
|
| 64 |
|
| 65 |
**Methods:**
|
| 66 |
|
| 67 |
-
#### `validate_absolute_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L116"><Icon icon="github"
|
| 68 |
|
| 69 |
```python
|
| 70 |
validate_absolute_path(cls, path: Path) -> Path
|
|
@@ -73,7 +115,7 @@ validate_absolute_path(cls, path: Path) -> Path
|
|
| 73 |
Ensure path is absolute.
|
| 74 |
|
| 75 |
|
| 76 |
-
#### `list_files` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L122"><Icon icon="github"
|
| 77 |
|
| 78 |
```python
|
| 79 |
list_files(self) -> list[Path]
|
|
@@ -81,3 +123,12 @@ list_files(self) -> list[Path]
|
|
| 81 |
|
| 82 |
List files in the directory.
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `TextResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L21" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
A resource that reads from a string.
|
| 17 |
|
| 18 |
|
| 19 |
+
**Methods:**
|
| 20 |
+
|
| 21 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L26" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 22 |
+
|
| 23 |
+
```python
|
| 24 |
+
read(self) -> str
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
Read the text content.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
### `BinaryResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L31" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 31 |
|
| 32 |
|
| 33 |
A resource that reads from bytes.
|
| 34 |
|
| 35 |
|
| 36 |
+
**Methods:**
|
| 37 |
+
|
| 38 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L36" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
read(self) -> bytes
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Read the binary content.
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
### `FileResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L41" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 48 |
|
| 49 |
|
| 50 |
A resource that reads from a file.
|
|
|
|
| 54 |
|
| 55 |
**Methods:**
|
| 56 |
|
| 57 |
+
#### `validate_absolute_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L59" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 58 |
|
| 59 |
```python
|
| 60 |
validate_absolute_path(cls, path: Path) -> Path
|
|
|
|
| 63 |
Ensure path is absolute.
|
| 64 |
|
| 65 |
|
| 66 |
+
#### `set_binary_from_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L67" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 67 |
|
| 68 |
```python
|
| 69 |
set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool
|
|
|
|
| 72 |
Set is_binary based on mime_type if not explicitly set.
|
| 73 |
|
| 74 |
|
| 75 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L74" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 76 |
+
|
| 77 |
+
```python
|
| 78 |
+
read(self) -> str | bytes
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
Read the file content.
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
### `HttpResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L84" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 85 |
|
| 86 |
|
| 87 |
A resource that reads from an HTTP endpoint.
|
| 88 |
|
| 89 |
|
| 90 |
+
**Methods:**
|
| 91 |
+
|
| 92 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L92" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
read(self) -> str | bytes
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
Read the HTTP content.
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
### `DirectoryResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L100" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 102 |
|
| 103 |
|
| 104 |
A resource that lists files in a directory.
|
|
|
|
| 106 |
|
| 107 |
**Methods:**
|
| 108 |
|
| 109 |
+
#### `validate_absolute_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L116" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 110 |
|
| 111 |
```python
|
| 112 |
validate_absolute_path(cls, path: Path) -> Path
|
|
|
|
| 115 |
Ensure path is absolute.
|
| 116 |
|
| 117 |
|
| 118 |
+
#### `list_files` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L122" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 119 |
|
| 120 |
```python
|
| 121 |
list_files(self) -> list[Path]
|
|
|
|
| 123 |
|
| 124 |
List files in the directory.
|
| 125 |
|
| 126 |
+
|
| 127 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L144" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
+
|
| 129 |
+
```python
|
| 130 |
+
read(self) -> str
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
Read the directory listing.
|
| 134 |
+
|
docs/python-sdk/fastmcp-server-auth-auth.mdx
CHANGED
|
@@ -7,4 +7,24 @@ sidebarTitle: auth
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `OAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L14"><Icon icon="github"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `OAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L14" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
**Methods:**
|
| 13 |
+
|
| 14 |
+
#### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L47" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
verify_token(self, token: str) -> AccessToken | None
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
Verify a bearer token and return access info if valid.
|
| 21 |
+
|
| 22 |
+
This method implements the TokenVerifier protocol by delegating
|
| 23 |
+
to our existing load_access_token method.
|
| 24 |
+
|
| 25 |
+
**Args:**
|
| 26 |
+
- `token`: The token string to validate
|
| 27 |
+
|
| 28 |
+
**Returns:**
|
| 29 |
+
- AccessToken object if valid, None if invalid or expired
|
| 30 |
+
|
docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx
CHANGED
|
@@ -7,23 +7,23 @@ sidebarTitle: bearer
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `JWKData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#
|
| 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#
|
| 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#
|
| 23 |
|
| 24 |
**Methods:**
|
| 25 |
|
| 26 |
-
#### `generate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#
|
| 27 |
|
| 28 |
```python
|
| 29 |
generate(cls) -> 'RSAKeyPair'
|
|
@@ -35,7 +35,7 @@ Generate an RSA key pair for testing.
|
|
| 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#
|
| 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
|
|
@@ -57,13 +57,96 @@ Generate a test JWT token for testing purposes.
|
|
| 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#
|
| 61 |
|
| 62 |
|
| 63 |
Simple JWT Bearer Token validator for hosted MCP servers.
|
| 64 |
-
Uses RS256 asymmetric encryption. 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `JWKData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L31" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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'
|
|
|
|
| 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
|
|
|
|
| 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 |
+
```
|
docs/python-sdk/fastmcp-server-auth-providers-bearer_env.mdx
CHANGED
|
@@ -7,13 +7,13 @@ sidebarTitle: bearer_env
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `EnvBearerAuthProviderSettings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer_env.py#L8"><Icon icon="github"
|
| 11 |
|
| 12 |
|
| 13 |
Settings for the BearerAuthProvider.
|
| 14 |
|
| 15 |
|
| 16 |
-
### `EnvBearerAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer_env.py#
|
| 17 |
|
| 18 |
|
| 19 |
A BearerAuthProvider that loads settings from environment variables. Any
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `EnvBearerAuthProviderSettings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer_env.py#L8" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
Settings for the BearerAuthProvider.
|
| 14 |
|
| 15 |
|
| 16 |
+
### `EnvBearerAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer_env.py#L25" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 17 |
|
| 18 |
|
| 19 |
A BearerAuthProvider that loads settings from environment variables. Any
|
docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx
CHANGED
|
@@ -7,9 +7,90 @@ sidebarTitle: in_memory
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `InMemoryOAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L31"><Icon icon="github"
|
| 11 |
|
| 12 |
|
| 13 |
An in-memory OAuth provider for testing purposes.
|
| 14 |
It simulates the OAuth 2.1 flow locally without external calls.
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `InMemoryOAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L31" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
An in-memory OAuth provider for testing purposes.
|
| 14 |
It simulates the OAuth 2.1 flow locally without external calls.
|
| 15 |
|
| 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#L65" 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#L68" 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#L76" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
authorize(self, client: OAuthClientInformationFull, params: AuthorizationParams) -> str
|
| 35 |
+
```
|
| 36 |
+
|
| 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#L129" 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#L142" 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#L193" 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#L208" 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#L263" 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#L274" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
verify_token(self, token: str) -> AccessToken | None
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
Verify a bearer token and return access info if valid.
|
| 78 |
+
|
| 79 |
+
This method implements the TokenVerifier protocol by delegating
|
| 80 |
+
to our existing load_access_token method.
|
| 81 |
+
|
| 82 |
+
**Args:**
|
| 83 |
+
- `token`: The token string to validate
|
| 84 |
+
|
| 85 |
+
**Returns:**
|
| 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#L331" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
revoke_token(self, token: AccessToken | RefreshToken) -> None
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
Revokes an access or refresh token and its counterpart.
|
| 96 |
+
|
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,7 @@ set_context(context: Context) -> Generator[Context, None, None]
|
|
| 15 |
|
| 16 |
## Classes
|
| 17 |
|
| 18 |
-
### `Context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 19 |
|
| 20 |
|
| 21 |
Context object providing access to MCP capabilities.
|
|
@@ -53,7 +53,7 @@ The context is optional - tools that don't need it can omit the parameter.
|
|
| 53 |
|
| 54 |
**Methods:**
|
| 55 |
|
| 56 |
-
#### `request_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 57 |
|
| 58 |
```python
|
| 59 |
request_context(self) -> RequestContext
|
|
@@ -64,7 +64,50 @@ Access to the underlying request context.
|
|
| 64 |
If called outside of a request context, this will raise a ValueError.
|
| 65 |
|
| 66 |
|
| 67 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
```python
|
| 70 |
client_id(self) -> str | None
|
|
@@ -73,7 +116,7 @@ client_id(self) -> str | None
|
|
| 73 |
Get the client ID if available.
|
| 74 |
|
| 75 |
|
| 76 |
-
#### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 77 |
|
| 78 |
```python
|
| 79 |
request_id(self) -> str
|
|
@@ -82,7 +125,7 @@ request_id(self) -> str
|
|
| 82 |
Get the unique ID for this request.
|
| 83 |
|
| 84 |
|
| 85 |
-
#### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 86 |
|
| 87 |
```python
|
| 88 |
session_id(self) -> str | None
|
|
@@ -99,16 +142,148 @@ the same client session.
|
|
| 99 |
- for stdio and in-memory transports which don't use session IDs.
|
| 100 |
|
| 101 |
|
| 102 |
-
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#
|
| 103 |
|
| 104 |
```python
|
| 105 |
-
session(self)
|
| 106 |
```
|
| 107 |
|
| 108 |
Access to the underlying session for advanced usage.
|
| 109 |
|
| 110 |
|
| 111 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
```python
|
| 114 |
get_http_request(self) -> Request
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `set_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L50" 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 |
+
### `Context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L59" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 19 |
|
| 20 |
|
| 21 |
Context object providing access to MCP capabilities.
|
|
|
|
| 53 |
|
| 54 |
**Methods:**
|
| 55 |
|
| 56 |
+
#### `request_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L116" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 57 |
|
| 58 |
```python
|
| 59 |
request_context(self) -> RequestContext
|
|
|
|
| 64 |
If called outside of a request context, this will raise a ValueError.
|
| 65 |
|
| 66 |
|
| 67 |
+
#### `report_progress` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L126" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
report_progress(self, progress: float, total: float | None = None, message: str | None = None) -> None
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
Report progress for the current operation.
|
| 74 |
+
|
| 75 |
+
**Args:**
|
| 76 |
+
- `progress`: Current progress value e.g. 24
|
| 77 |
+
- `total`: Optional total value e.g. 100
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
read_resource(self, uri: str | AnyUrl) -> list[ReadResourceContents]
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Read a resource by URI.
|
| 87 |
+
|
| 88 |
+
**Args:**
|
| 89 |
+
- `uri`: Resource URI to read
|
| 90 |
+
|
| 91 |
+
**Returns:**
|
| 92 |
+
- The resource content as either text or bytes
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
#### `log` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L165" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 96 |
+
|
| 97 |
+
```python
|
| 98 |
+
log(self, message: str, level: LoggingLevel | None = None, logger_name: str | None = None) -> None
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
Send a log message to the client.
|
| 102 |
+
|
| 103 |
+
**Args:**
|
| 104 |
+
- `message`: Log message
|
| 105 |
+
- `level`: Optional log level. One of "debug", "info", "notice", "warning", "error", "critical",
|
| 106 |
+
"alert", or "emergency". Default is "info".
|
| 107 |
+
- `logger_name`: Optional logger name
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
#### `client_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L189" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 111 |
|
| 112 |
```python
|
| 113 |
client_id(self) -> str | None
|
|
|
|
| 116 |
Get the client ID if available.
|
| 117 |
|
| 118 |
|
| 119 |
+
#### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L198" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 120 |
|
| 121 |
```python
|
| 122 |
request_id(self) -> str
|
|
|
|
| 125 |
Get the unique ID for this request.
|
| 126 |
|
| 127 |
|
| 128 |
+
#### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L203" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 129 |
|
| 130 |
```python
|
| 131 |
session_id(self) -> str | None
|
|
|
|
| 142 |
- for stdio and in-memory transports which don't use session IDs.
|
| 143 |
|
| 144 |
|
| 145 |
+
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L234" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 146 |
|
| 147 |
```python
|
| 148 |
+
session(self) -> ServerSession
|
| 149 |
```
|
| 150 |
|
| 151 |
Access to the underlying session for advanced usage.
|
| 152 |
|
| 153 |
|
| 154 |
+
#### `debug` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L239" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 155 |
+
|
| 156 |
+
```python
|
| 157 |
+
debug(self, message: str, logger_name: str | None = None) -> None
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
Send a debug log message.
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
#### `info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L243" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 164 |
+
|
| 165 |
+
```python
|
| 166 |
+
info(self, message: str, logger_name: str | None = None) -> None
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
Send an info log message.
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
#### `warning` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L247" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 173 |
+
|
| 174 |
+
```python
|
| 175 |
+
warning(self, message: str, logger_name: str | None = None) -> None
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
Send a warning log message.
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
#### `error` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L251" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 182 |
+
|
| 183 |
+
```python
|
| 184 |
+
error(self, message: str, logger_name: str | None = None) -> None
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
Send an error log message.
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
#### `list_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L255" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 191 |
+
|
| 192 |
+
```python
|
| 193 |
+
list_roots(self) -> list[Root]
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
List the roots available to the server, as indicated by the client.
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
#### `send_tool_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L260" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 200 |
+
|
| 201 |
+
```python
|
| 202 |
+
send_tool_list_changed(self) -> None
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
Send a tool list changed notification to the client.
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
#### `send_resource_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L264" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 209 |
+
|
| 210 |
+
```python
|
| 211 |
+
send_resource_list_changed(self) -> None
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
Send a resource list changed notification to the client.
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
#### `send_prompt_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L268" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 218 |
+
|
| 219 |
+
```python
|
| 220 |
+
send_prompt_list_changed(self) -> None
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
Send a prompt list changed notification to the client.
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
#### `sample` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L272" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 227 |
+
|
| 228 |
+
```python
|
| 229 |
+
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
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
Send a sampling request to the client and await the response.
|
| 233 |
+
|
| 234 |
+
Call this method at any time to have the server request an LLM
|
| 235 |
+
completion from the client. The client must be appropriately configured,
|
| 236 |
+
or the request will error.
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L319" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 240 |
+
|
| 241 |
+
```python
|
| 242 |
+
elicit(self, message: str, response_type: None) -> AcceptedElicitation[dict[str, Any]] | DeclinedElicitation | CancelledElicitation
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L331" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 246 |
+
|
| 247 |
+
```python
|
| 248 |
+
elicit(self, message: str, response_type: type[T]) -> AcceptedElicitation[T] | DeclinedElicitation | CancelledElicitation
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
#### `elicit` <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>
|
| 252 |
+
|
| 253 |
+
```python
|
| 254 |
+
elicit(self, message: str, response_type: list[str]) -> AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L350" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 258 |
+
|
| 259 |
+
```python
|
| 260 |
+
elicit(self, message: str, response_type: type[T] | list[str] | None = None) -> AcceptedElicitation[T] | AcceptedElicitation[dict[str, Any]] | AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
Send an elicitation request to the client and await the response.
|
| 264 |
+
|
| 265 |
+
Call this method at any time to request additional information from
|
| 266 |
+
the user through the client. The client must support elicitation,
|
| 267 |
+
or the request will error.
|
| 268 |
+
|
| 269 |
+
Note that the MCP protocol only supports simple object schemas with
|
| 270 |
+
primitive types. You can provide a dataclass, TypedDict, or BaseModel to
|
| 271 |
+
comply. If you provide a primitive type, an object schema with a single
|
| 272 |
+
"value" field will be generated for the MCP interaction and
|
| 273 |
+
automatically deconstructed into the primitive type upon response.
|
| 274 |
+
|
| 275 |
+
If the response_type is None, the generated schema will be that of an
|
| 276 |
+
empty object in order to comply with the MCP protocol requirements.
|
| 277 |
+
Clients must send an empty object ("{}")in response.
|
| 278 |
+
|
| 279 |
+
**Args:**
|
| 280 |
+
- `message`: A human-readable message explaining what information is needed
|
| 281 |
+
- `response_type`: The type of the response, which should be a primitive
|
| 282 |
+
type or dataclass or BaseModel. If it is a primitive type, an
|
| 283 |
+
object schema with a single "value" field will be generated.
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
#### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L443" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 287 |
|
| 288 |
```python
|
| 289 |
get_http_request(self) -> Request
|
docs/python-sdk/fastmcp-server-dependencies.mdx
CHANGED
|
@@ -7,19 +7,19 @@ sidebarTitle: dependencies
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `get_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L27"><Icon icon="github"
|
| 11 |
|
| 12 |
```python
|
| 13 |
get_context() -> Context
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L39"><Icon icon="github"
|
| 17 |
|
| 18 |
```python
|
| 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#L48"><Icon icon="github"
|
| 23 |
|
| 24 |
```python
|
| 25 |
get_http_headers(include_all: bool = False) -> dict[str, str]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `get_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L27" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
get_context() -> Context
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L39" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 17 |
|
| 18 |
```python
|
| 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#L48" 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-elicitation.mdx
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: elicitation
|
| 3 |
+
sidebarTitle: elicitation
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.elicitation`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `get_elicitation_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L42" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
get_elicitation_schema(response_type: type[T]) -> dict[str, Any]
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Get the schema for an elicitation response.
|
| 18 |
+
|
| 19 |
+
**Args:**
|
| 20 |
+
- `response_type`: The type of the response
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
### `validate_elicitation_json_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L58" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
validate_elicitation_json_schema(schema: dict[str, Any]) -> None
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Validate that a JSON schema follows MCP elicitation requirements.
|
| 31 |
+
|
| 32 |
+
This ensures the schema is compatible with MCP elicitation requirements:
|
| 33 |
+
- Must be an object schema
|
| 34 |
+
- Must only contain primitive field types (string, number, integer, boolean)
|
| 35 |
+
- Must be flat (no nested objects or arrays of objects)
|
| 36 |
+
- Allows const fields (for Literal types) and enum fields (for Enum types)
|
| 37 |
+
- Only primitive types and their nullable variants are allowed
|
| 38 |
+
|
| 39 |
+
**Args:**
|
| 40 |
+
- `schema`: The JSON schema to validate
|
| 41 |
+
|
| 42 |
+
**Raises:**
|
| 43 |
+
- `TypeError`: If the schema doesn't meet MCP elicitation requirements
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
## Classes
|
| 47 |
+
|
| 48 |
+
### `AcceptedElicitation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L30" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Result when user accepts the elicitation.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
### `ScalarElicitationType` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
docs/python-sdk/fastmcp-server-http.mdx
CHANGED
|
@@ -7,13 +7,13 @@ 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#L48"><Icon icon="github"
|
| 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#L72"><Icon icon="github"
|
| 17 |
|
| 18 |
```python
|
| 19 |
setup_auth_middleware_and_routes(auth: OAuthProvider) -> tuple[list[Middleware], list[BaseRoute], list[str]]
|
|
@@ -29,7 +29,7 @@ Set up authentication middleware and routes if auth is enabled.
|
|
| 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#L110"><Icon icon="github"
|
| 33 |
|
| 34 |
```python
|
| 35 |
create_base_app(routes: list[BaseRoute], middleware: list[Middleware], debug: bool = False, lifespan: Callable | None = None) -> StarletteWithLifespan
|
|
@@ -48,7 +48,7 @@ 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#L138"><Icon icon="github"
|
| 52 |
|
| 53 |
```python
|
| 54 |
create_sse_app(server: FastMCP[LifespanResultT], message_path: str, sse_path: str, auth: OAuthProvider | None = None, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
@@ -70,7 +70,7 @@ 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: OAuthProvider | None = None, json_response: bool = False, stateless_http: bool = False, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
@@ -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#L41"><Icon icon="github"
|
| 100 |
|
| 101 |
**Methods:**
|
| 102 |
|
| 103 |
-
#### `lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L43"><Icon icon="github"
|
| 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#L56"><Icon icon="github"
|
| 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#L48" 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#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
setup_auth_middleware_and_routes(auth: OAuthProvider) -> tuple[list[Middleware], list[BaseRoute], list[str]]
|
|
|
|
| 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#L110" 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#L138" 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: OAuthProvider | None = None, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 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#L242" 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: OAuthProvider | None = None, json_response: bool = False, stateless_http: bool = False, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 96 |
|
| 97 |
## Classes
|
| 98 |
|
| 99 |
+
### `StarletteWithLifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L41" 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#L43" 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#L56" 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-low_level.mdx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: low_level
|
| 3 |
+
sidebarTitle: low_level
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.low_level`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `LowLevelServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/low_level.py#L14" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
**Methods:**
|
| 13 |
+
|
| 14 |
+
#### `create_initialization_options` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/low_level.py#L24" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
create_initialization_options(self, notification_options: NotificationOptions | None = None, experimental_capabilities: dict[str, dict[str, Any]] | None = None, **kwargs: Any) -> InitializationOptions
|
| 18 |
+
```
|
docs/python-sdk/fastmcp-server-middleware-error_handling.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Error handling middleware for consistent error responses and tracking.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `ErrorHandlingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L15"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
Middleware that provides consistent error handling and logging.
|
|
@@ -21,7 +21,16 @@ proper MCP error responses. Also tracks error patterns for monitoring.
|
|
| 21 |
|
| 22 |
**Methods:**
|
| 23 |
|
| 24 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
```python
|
| 27 |
get_error_stats(self) -> dict[str, int]
|
|
@@ -30,7 +39,7 @@ get_error_stats(self) -> dict[str, int]
|
|
| 30 |
Get error statistics for monitoring.
|
| 31 |
|
| 32 |
|
| 33 |
-
### `RetryMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L126"><Icon icon="github"
|
| 34 |
|
| 35 |
|
| 36 |
Middleware that implements automatic retry logic for failed requests.
|
|
@@ -38,3 +47,14 @@ Middleware that implements automatic retry logic for failed requests.
|
|
| 38 |
Retries requests that fail with transient errors, using exponential
|
| 39 |
backoff to avoid overwhelming the server or external dependencies.
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `ErrorHandlingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L15" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Middleware that provides consistent error handling and logging.
|
|
|
|
| 21 |
|
| 22 |
**Methods:**
|
| 23 |
|
| 24 |
+
#### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
on_message(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
Handle errors for all messages.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
#### `get_error_stats` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L121" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
|
| 35 |
```python
|
| 36 |
get_error_stats(self) -> dict[str, int]
|
|
|
|
| 39 |
Get error statistics for monitoring.
|
| 40 |
|
| 41 |
|
| 42 |
+
### `RetryMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L126" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 43 |
|
| 44 |
|
| 45 |
Middleware that implements automatic retry logic for failed requests.
|
|
|
|
| 47 |
Retries requests that fail with transient errors, using exponential
|
| 48 |
backoff to avoid overwhelming the server or external dependencies.
|
| 49 |
|
| 50 |
+
|
| 51 |
+
**Methods:**
|
| 52 |
+
|
| 53 |
+
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
on_request(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Implement retry logic for requests.
|
| 60 |
+
|
docs/python-sdk/fastmcp-server-middleware-logging.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Comprehensive logging middleware for FastMCP servers.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `LoggingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L10"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
Middleware that provides comprehensive request and response logging.
|
|
@@ -19,7 +19,18 @@ Logs all MCP messages with configurable detail levels. Useful for debugging,
|
|
| 19 |
monitoring, and understanding server usage patterns.
|
| 20 |
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
Middleware that provides structured JSON logging for better log analysis.
|
|
@@ -27,3 +38,14 @@ Middleware that provides structured JSON logging for better log analysis.
|
|
| 27 |
Outputs structured logs that are easier to parse and analyze with log
|
| 28 |
aggregation tools like ELK stack, Splunk, or cloud logging services.
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `LoggingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L10" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Middleware that provides comprehensive request and response logging.
|
|
|
|
| 19 |
monitoring, and understanding server usage patterns.
|
| 20 |
|
| 21 |
|
| 22 |
+
**Methods:**
|
| 23 |
+
|
| 24 |
+
#### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L71" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
on_message(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
Log all messages.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
### `StructuredLoggingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L92" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
|
| 35 |
|
| 36 |
Middleware that provides structured JSON logging for better log analysis.
|
|
|
|
| 38 |
Outputs structured logs that are easier to parse and analyze with log
|
| 39 |
aggregation tools like ELK stack, Splunk, or cloud logging services.
|
| 40 |
|
| 41 |
+
|
| 42 |
+
**Methods:**
|
| 43 |
+
|
| 44 |
+
#### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L149" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
on_message(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
Log structured message information.
|
| 51 |
+
|
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]
|
|
@@ -21,36 +21,88 @@ passed to other functions that expect a call_next function.
|
|
| 21 |
|
| 22 |
## Classes
|
| 23 |
|
| 24 |
-
### `CallNext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#
|
| 25 |
|
| 26 |
-
### `
|
| 27 |
|
| 28 |
-
### `
|
| 29 |
|
| 30 |
-
### `ListResourcesResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L67"><Icon icon="github" size="14" /></a></sup>
|
| 31 |
|
| 32 |
-
|
| 33 |
|
| 34 |
-
### `ListPromptsResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L77"><Icon icon="github" size="14" /></a></sup>
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
### `
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
**Methods:**
|
| 45 |
|
| 46 |
-
#### `
|
| 47 |
|
| 48 |
```python
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
-
### `
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `make_middleware_wrapper` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L86" 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]
|
|
|
|
| 21 |
|
| 22 |
## Classes
|
| 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 |
+
### `ServerResultProtocol` <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>
|
| 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.
|
| 32 |
|
|
|
|
| 33 |
|
| 34 |
+
**Methods:**
|
| 35 |
|
| 36 |
+
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L82" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L99" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Base class for FastMCP middleware with dispatching hooks.
|
| 46 |
|
| 47 |
|
| 48 |
**Methods:**
|
| 49 |
|
| 50 |
+
#### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L146" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L160" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L167" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 69 |
|
| 70 |
+
```python
|
| 71 |
+
on_call_tool(self, context: MiddlewareContext[mt.CallToolRequestParams], call_next: CallNext[mt.CallToolRequestParams, mt.CallToolResult]) -> mt.CallToolResult
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
#### `on_read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L174" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L181" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L188" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L195" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L202" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L209" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 105 |
+
|
| 106 |
+
```python
|
| 107 |
+
on_list_prompts(self, context: MiddlewareContext[mt.ListPromptsRequest], call_next: CallNext[mt.ListPromptsRequest, list[Prompt]]) -> list[Prompt]
|
| 108 |
+
```
|
docs/python-sdk/fastmcp-server-middleware-rate_limiting.mdx
CHANGED
|
@@ -10,25 +10,53 @@ Rate limiting middleware for protecting FastMCP servers from abuse.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `RateLimitError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L15"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
Error raised when rate limit is exceeded.
|
| 17 |
|
| 18 |
|
| 19 |
-
### `TokenBucketRateLimiter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L22"><Icon icon="github"
|
| 20 |
|
| 21 |
|
| 22 |
Token bucket implementation for rate limiting.
|
| 23 |
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
Sliding window rate limiter implementation.
|
| 29 |
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
Middleware that implements rate limiting to prevent server abuse.
|
|
@@ -37,7 +65,18 @@ Uses a token bucket algorithm by default, allowing for burst traffic
|
|
| 37 |
while maintaining a sustainable long-term rate.
|
| 38 |
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
Middleware that implements sliding window rate limiting.
|
|
@@ -45,3 +84,14 @@ Middleware that implements sliding window rate limiting.
|
|
| 45 |
Uses a sliding window approach which provides more precise rate limiting
|
| 46 |
but uses more memory to track individual request timestamps.
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `RateLimitError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L15" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Error raised when rate limit is exceeded.
|
| 17 |
|
| 18 |
|
| 19 |
+
### `TokenBucketRateLimiter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L22" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
Token bucket implementation for rate limiting.
|
| 23 |
|
| 24 |
|
| 25 |
+
**Methods:**
|
| 26 |
+
|
| 27 |
+
#### `consume` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
consume(self, tokens: int = 1) -> bool
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Try to consume tokens from the bucket.
|
| 34 |
+
|
| 35 |
+
**Args:**
|
| 36 |
+
- `tokens`: Number of tokens to consume
|
| 37 |
+
|
| 38 |
+
**Returns:**
|
| 39 |
+
- True if tokens were available and consumed, False otherwise
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
### `SlidingWindowRateLimiter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L61" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 43 |
|
| 44 |
|
| 45 |
Sliding window rate limiter implementation.
|
| 46 |
|
| 47 |
|
| 48 |
+
**Methods:**
|
| 49 |
+
|
| 50 |
+
#### `is_allowed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L76" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
is_allowed(self) -> bool
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Check if a request is allowed.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
### `RateLimitingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L92" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 60 |
|
| 61 |
|
| 62 |
Middleware that implements rate limiting to prevent server abuse.
|
|
|
|
| 65 |
while maintaining a sustainable long-term rate.
|
| 66 |
|
| 67 |
|
| 68 |
+
**Methods:**
|
| 69 |
+
|
| 70 |
+
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L152" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
on_request(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
Apply rate limiting to requests.
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
### `SlidingWindowRateLimitingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L170" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 80 |
|
| 81 |
|
| 82 |
Middleware that implements sliding window rate limiting.
|
|
|
|
| 84 |
Uses a sliding window approach which provides more precise rate limiting
|
| 85 |
but uses more memory to track individual request timestamps.
|
| 86 |
|
| 87 |
+
|
| 88 |
+
**Methods:**
|
| 89 |
+
|
| 90 |
+
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L219" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
on_request(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
Apply sliding window rate limiting to requests.
|
| 97 |
+
|
docs/python-sdk/fastmcp-server-middleware-timing.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Timing middleware for measuring and logging request performance.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `TimingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L10"><Icon icon="github"
|
| 14 |
|
| 15 |
|
| 16 |
Middleware that logs the execution time of requests.
|
|
@@ -19,7 +19,18 @@ Only measures and logs timing for request messages (not notifications).
|
|
| 19 |
Provides insights into performance characteristics of your MCP server.
|
| 20 |
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
Enhanced timing middleware with per-operation breakdowns.
|
|
@@ -27,3 +38,68 @@ Enhanced timing middleware with per-operation breakdowns.
|
|
| 27 |
Provides detailed timing information for different types of MCP operations,
|
| 28 |
allowing you to identify performance bottlenecks in specific operations.
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `TimingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L10" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Middleware that logs the execution time of requests.
|
|
|
|
| 19 |
Provides insights into performance characteristics of your MCP server.
|
| 20 |
|
| 21 |
|
| 22 |
+
**Methods:**
|
| 23 |
+
|
| 24 |
+
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L39" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
on_request(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
Time request execution and log the results.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
### `DetailedTimingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
|
| 35 |
|
| 36 |
Enhanced timing middleware with per-operation breakdowns.
|
|
|
|
| 38 |
Provides detailed timing information for different types of MCP operations,
|
| 39 |
allowing you to identify performance bottlenecks in specific operations.
|
| 40 |
|
| 41 |
+
|
| 42 |
+
**Methods:**
|
| 43 |
+
|
| 44 |
+
#### `on_call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L111" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
on_call_tool(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
Time tool execution.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
#### `on_read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L118" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
on_read_resource(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Time resource reading.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
#### `on_get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
on_get_prompt(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
Time prompt retrieval.
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
#### `on_list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
on_list_tools(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
Time tool listing.
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
#### `on_list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
on_list_resources(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Time resource listing.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
#### `on_list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L146" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
on_list_resource_templates(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
Time resource template listing.
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
#### `on_list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L152" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 99 |
+
|
| 100 |
+
```python
|
| 101 |
+
on_list_prompts(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
Time prompt listing.
|
| 105 |
+
|
docs/python-sdk/fastmcp-server-openapi.mdx
CHANGED
|
@@ -10,13 +10,13 @@ FastMCP server implementation for OpenAPI integration.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `MCPType` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#
|
| 14 |
|
| 15 |
|
| 16 |
Type of FastMCP component to create from a route.
|
| 17 |
|
| 18 |
|
| 19 |
-
### `RouteType` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#
|
| 20 |
|
| 21 |
|
| 22 |
Deprecated: Use MCPType instead.
|
|
@@ -24,31 +24,64 @@ Deprecated: Use MCPType instead.
|
|
| 24 |
This enum is kept for backward compatibility and will be removed in a future version.
|
| 25 |
|
| 26 |
|
| 27 |
-
### `RouteMap` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#
|
| 28 |
|
| 29 |
|
| 30 |
Mapping configuration for HTTP routes to FastMCP component types.
|
| 31 |
|
| 32 |
|
| 33 |
-
### `OpenAPITool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#
|
| 34 |
|
| 35 |
|
| 36 |
Tool implementation for OpenAPI endpoints.
|
| 37 |
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
Resource implementation for OpenAPI endpoints.
|
| 43 |
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
Resource template implementation for OpenAPI endpoints.
|
| 49 |
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
FastMCP server implementation that creates components from an OpenAPI schema.
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `MCPType` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L78" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Type of FastMCP component to create from a route.
|
| 17 |
|
| 18 |
|
| 19 |
+
### `RouteType` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L97" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
Deprecated: Use MCPType instead.
|
|
|
|
| 24 |
This enum is kept for backward compatibility and will be removed in a future version.
|
| 25 |
|
| 26 |
|
| 27 |
+
### `RouteMap` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L111" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
|
| 29 |
|
| 30 |
Mapping configuration for HTTP routes to FastMCP component types.
|
| 31 |
|
| 32 |
|
| 33 |
+
### `OpenAPITool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L229" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 34 |
|
| 35 |
|
| 36 |
Tool implementation for OpenAPI endpoints.
|
| 37 |
|
| 38 |
|
| 39 |
+
**Methods:**
|
| 40 |
+
|
| 41 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L262" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
run(self, arguments: dict[str, Any]) -> ToolResult
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Execute the HTTP request based on the route configuration.
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
### `OpenAPIResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L523" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 51 |
|
| 52 |
|
| 53 |
Resource implementation for OpenAPI endpoints.
|
| 54 |
|
| 55 |
|
| 56 |
+
**Methods:**
|
| 57 |
+
|
| 58 |
+
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L552" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
read(self) -> str | bytes
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
Fetch the resource data by making an HTTP request.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
### `OpenAPIResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L642" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 68 |
|
| 69 |
|
| 70 |
Resource template implementation for OpenAPI endpoints.
|
| 71 |
|
| 72 |
|
| 73 |
+
**Methods:**
|
| 74 |
+
|
| 75 |
+
#### `create_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L671" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 76 |
+
|
| 77 |
+
```python
|
| 78 |
+
create_resource(self, uri: str, params: dict[str, Any], context: Context | None = None) -> Resource
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
Create a resource with the given parameters.
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
### `FastMCPOpenAPI` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L696" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 85 |
|
| 86 |
|
| 87 |
FastMCP server implementation that creates components from an OpenAPI schema.
|
docs/python-sdk/fastmcp-server-proxy.mdx
CHANGED
|
@@ -5,27 +5,144 @@ sidebarTitle: proxy
|
|
| 5 |
|
| 6 |
# `fastmcp.server.proxy`
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `ProxyToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 11 |
|
| 12 |
|
| 13 |
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
| 14 |
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
| 20 |
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
| 26 |
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
A Tool that represents and executes a tool on a remote server.
|
|
@@ -33,7 +150,7 @@ A Tool that represents and executes a tool on a remote server.
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
-
#### `from_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
@@ -42,7 +159,16 @@ from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
| 42 |
Factory method to create a ProxyTool from a raw MCP tool schema.
|
| 43 |
|
| 44 |
|
| 45 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
A Resource that represents and reads a resource from a remote server.
|
|
@@ -50,7 +176,7 @@ A Resource that represents and reads a resource from a remote server.
|
|
| 50 |
|
| 51 |
**Methods:**
|
| 52 |
|
| 53 |
-
#### `from_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 54 |
|
| 55 |
```python
|
| 56 |
from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> ProxyResource
|
|
@@ -59,7 +185,16 @@ from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> Prox
|
|
| 59 |
Factory method to create a ProxyResource from a raw MCP resource schema.
|
| 60 |
|
| 61 |
|
| 62 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
A ResourceTemplate that represents and creates resources from a remote server template.
|
|
@@ -67,7 +202,7 @@ A ResourceTemplate that represents and creates resources from a remote server te
|
|
| 67 |
|
| 68 |
**Methods:**
|
| 69 |
|
| 70 |
-
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 71 |
|
| 72 |
```python
|
| 73 |
from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate) -> ProxyTemplate
|
|
@@ -76,7 +211,16 @@ from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate)
|
|
| 76 |
Factory method to create a ProxyTemplate from a raw MCP template schema.
|
| 77 |
|
| 78 |
|
| 79 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
A Prompt that represents and renders a prompt from a remote server.
|
|
@@ -84,7 +228,7 @@ A Prompt that represents and renders a prompt from a remote server.
|
|
| 84 |
|
| 85 |
**Methods:**
|
| 86 |
|
| 87 |
-
#### `from_mcp_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 88 |
|
| 89 |
```python
|
| 90 |
from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPrompt
|
|
@@ -93,9 +237,63 @@ from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPromp
|
|
| 93 |
Factory method to create a ProxyPrompt from a raw MCP prompt schema.
|
| 94 |
|
| 95 |
|
| 96 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
A FastMCP server that acts as a proxy to a remote MCP-compliant server.
|
| 100 |
-
It uses specialized managers that fulfill requests via
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
|
|
|
| 5 |
|
| 6 |
# `fastmcp.server.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#L479" 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
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
A handler that forwards the list roots request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
## Classes
|
| 21 |
|
| 22 |
+
### `ProxyToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L48" 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.
|
| 26 |
|
| 27 |
|
| 28 |
+
**Methods:**
|
| 29 |
+
|
| 30 |
+
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L55" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
get_tools(self) -> dict[str, Tool]
|
| 34 |
+
```
|
| 35 |
+
|
| 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#L76" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
list_tools(self) -> list[Tool]
|
| 43 |
+
```
|
| 44 |
+
|
| 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#L81" 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
|
| 52 |
+
```
|
| 53 |
+
|
| 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#L97" 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.
|
| 61 |
|
| 62 |
|
| 63 |
+
**Methods:**
|
| 64 |
+
|
| 65 |
+
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L104" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
get_resources(self) -> dict[str, Resource]
|
| 69 |
+
```
|
| 70 |
+
|
| 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#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
| 78 |
+
```
|
| 79 |
+
|
| 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#L150" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
list_resources(self) -> list[Resource]
|
| 87 |
+
```
|
| 88 |
+
|
| 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#L155" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
list_resource_templates(self) -> list[ResourceTemplate]
|
| 96 |
+
```
|
| 97 |
+
|
| 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#L160" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 102 |
+
|
| 103 |
+
```python
|
| 104 |
+
read_resource(self, uri: AnyUrl | str) -> str | bytes
|
| 105 |
+
```
|
| 106 |
+
|
| 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#L178" 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.
|
| 114 |
|
| 115 |
|
| 116 |
+
**Methods:**
|
| 117 |
+
|
| 118 |
+
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L185" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 119 |
+
|
| 120 |
+
```python
|
| 121 |
+
get_prompts(self) -> dict[str, Prompt]
|
| 122 |
+
```
|
| 123 |
+
|
| 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#L208" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
+
|
| 129 |
+
```python
|
| 130 |
+
list_prompts(self) -> list[Prompt]
|
| 131 |
+
```
|
| 132 |
+
|
| 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#L213" 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
|
| 140 |
+
```
|
| 141 |
+
|
| 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#L230" 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#L240" 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#L252" 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
|
| 166 |
+
```
|
| 167 |
+
|
| 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#L271" 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#L291" 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#L306" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 189 |
+
|
| 190 |
+
```python
|
| 191 |
+
read(self) -> str | bytes
|
| 192 |
+
```
|
| 193 |
+
|
| 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#L321" 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#L331" 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#L345" 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
|
| 218 |
+
```
|
| 219 |
+
|
| 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#L378" 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#L390" 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#L410" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 241 |
+
|
| 242 |
+
```python
|
| 243 |
+
render(self, arguments: dict[str, Any]) -> list[PromptMessage]
|
| 244 |
+
```
|
| 245 |
+
|
| 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#L417" 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#L489" 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.
|
| 260 |
+
Supports forwarding roots, sampling, elicitation, logging, and progress.
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
**Methods:**
|
| 264 |
+
|
| 265 |
+
#### `default_sampling_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L520" 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
|
| 269 |
+
```
|
| 270 |
+
|
| 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#L546" 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
|
| 278 |
+
```
|
| 279 |
+
|
| 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#L564" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 284 |
+
|
| 285 |
+
```python
|
| 286 |
+
default_log_handler(cls, message: LogMessage) -> None
|
| 287 |
+
```
|
| 288 |
+
|
| 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#L572" 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
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
A handler that forwards the progress notification from the remote server to the proxy's connected clients.
|
| 299 |
|
docs/python-sdk/fastmcp-server-server.mdx
CHANGED
|
@@ -10,7 +10,23 @@ FastMCP - A more ergonomic interface for MCP servers.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
```python
|
| 16 |
add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -48,7 +64,7 @@ add_resource_prefix("resource:///absolute/path", "prefix")
|
|
| 48 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 49 |
|
| 50 |
|
| 51 |
-
### `remove_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 52 |
|
| 53 |
```python
|
| 54 |
remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -87,7 +103,7 @@ remove_resource_prefix("resource://prefix//absolute/path", "prefix")
|
|
| 87 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 88 |
|
| 89 |
|
| 90 |
-
### `has_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 91 |
|
| 92 |
```python
|
| 93 |
has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> bool
|
|
@@ -127,32 +143,44 @@ False
|
|
| 127 |
|
| 128 |
## Classes
|
| 129 |
|
| 130 |
-
### `FastMCP` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 131 |
|
| 132 |
**Methods:**
|
| 133 |
|
| 134 |
-
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 135 |
|
| 136 |
```python
|
| 137 |
settings(self) -> Settings
|
| 138 |
```
|
| 139 |
|
| 140 |
-
#### `name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 141 |
|
| 142 |
```python
|
| 143 |
name(self) -> str
|
| 144 |
```
|
| 145 |
|
| 146 |
-
#### `instructions` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 147 |
|
| 148 |
```python
|
| 149 |
instructions(self) -> str | None
|
| 150 |
```
|
| 151 |
|
| 152 |
-
#### `
|
| 153 |
|
| 154 |
```python
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
```
|
| 157 |
|
| 158 |
Run the FastMCP server. Note this is a synchronous function.
|
|
@@ -161,13 +189,76 @@ Run the FastMCP server. Note this is a synchronous function.
|
|
| 161 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 162 |
|
| 163 |
|
| 164 |
-
#### `add_middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 165 |
|
| 166 |
```python
|
| 167 |
add_middleware(self, middleware: Middleware) -> None
|
| 168 |
```
|
| 169 |
|
| 170 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
```python
|
| 173 |
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True)
|
|
@@ -188,10 +279,10 @@ Starlette's reverse URL lookup feature)
|
|
| 188 |
- `include_in_schema`: Whether to include in OpenAPI schema, defaults to True
|
| 189 |
|
| 190 |
|
| 191 |
-
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 192 |
|
| 193 |
```python
|
| 194 |
-
add_tool(self, tool: Tool) ->
|
| 195 |
```
|
| 196 |
|
| 197 |
Add a tool to the server.
|
|
@@ -202,8 +293,11 @@ with the Context type annotation. See the @tool decorator for examples.
|
|
| 202 |
**Args:**
|
| 203 |
- `tool`: The Tool instance to register
|
| 204 |
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 207 |
|
| 208 |
```python
|
| 209 |
remove_tool(self, name: str) -> None
|
|
@@ -218,19 +312,19 @@ Remove a tool from the server.
|
|
| 218 |
- `NotFoundError`: If the tool is not found
|
| 219 |
|
| 220 |
|
| 221 |
-
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 222 |
|
| 223 |
```python
|
| 224 |
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 225 |
```
|
| 226 |
|
| 227 |
-
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 228 |
|
| 229 |
```python
|
| 230 |
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 231 |
```
|
| 232 |
|
| 233 |
-
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 234 |
|
| 235 |
```python
|
| 236 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
@@ -254,6 +348,7 @@ This decorator supports multiple calling patterns:
|
|
| 254 |
- `name`: Optional name for the tool (keyword-only, alternative to name_or_fn)
|
| 255 |
- `description`: Optional description of what the tool does
|
| 256 |
- `tags`: Optional set of tags for categorizing the tool
|
|
|
|
| 257 |
- `annotations`: Optional annotations about the tool's behavior
|
| 258 |
- `exclude_args`: Optional list of argument names to exclude from the tool schema
|
| 259 |
- `enabled`: Optional boolean to enable or disable the tool
|
|
@@ -284,10 +379,10 @@ server.tool(my_function, name="custom_name")
|
|
| 284 |
```
|
| 285 |
|
| 286 |
|
| 287 |
-
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 288 |
|
| 289 |
```python
|
| 290 |
-
add_resource(self, resource: Resource) ->
|
| 291 |
```
|
| 292 |
|
| 293 |
Add a resource to the server.
|
|
@@ -295,11 +390,14 @@ Add a resource to the server.
|
|
| 295 |
**Args:**
|
| 296 |
- `resource`: A Resource instance to add
|
| 297 |
|
|
|
|
|
|
|
| 298 |
|
| 299 |
-
|
|
|
|
| 300 |
|
| 301 |
```python
|
| 302 |
-
add_template(self, template: ResourceTemplate) ->
|
| 303 |
```
|
| 304 |
|
| 305 |
Add a resource template to the server.
|
|
@@ -307,8 +405,11 @@ Add a resource template to the server.
|
|
| 307 |
**Args:**
|
| 308 |
- `template`: A ResourceTemplate instance to add
|
| 309 |
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
-
#### `add_resource_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 312 |
|
| 313 |
```python
|
| 314 |
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
|
|
@@ -328,7 +429,7 @@ has parameters, it will be registered as a template resource.
|
|
| 328 |
- `tags`: Optional set of tags for categorizing the resource
|
| 329 |
|
| 330 |
|
| 331 |
-
#### `resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 332 |
|
| 333 |
```python
|
| 334 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
@@ -386,10 +487,10 @@ async def get_weather(city: str) -> str:
|
|
| 386 |
```
|
| 387 |
|
| 388 |
|
| 389 |
-
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 390 |
|
| 391 |
```python
|
| 392 |
-
add_prompt(self, prompt: Prompt) ->
|
| 393 |
```
|
| 394 |
|
| 395 |
Add a prompt to the server.
|
|
@@ -397,20 +498,23 @@ Add a prompt to the server.
|
|
| 397 |
**Args:**
|
| 398 |
- `prompt`: A Prompt instance to add
|
| 399 |
|
|
|
|
|
|
|
|
|
|
| 400 |
|
| 401 |
-
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 402 |
|
| 403 |
```python
|
| 404 |
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 405 |
```
|
| 406 |
|
| 407 |
-
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 408 |
|
| 409 |
```python
|
| 410 |
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 411 |
```
|
| 412 |
|
| 413 |
-
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 414 |
|
| 415 |
```python
|
| 416 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
@@ -487,7 +591,44 @@ Decorator to register a prompt.
|
|
| 487 |
```
|
| 488 |
|
| 489 |
|
| 490 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
|
| 492 |
```python
|
| 493 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -501,7 +642,7 @@ Create a Starlette app for the SSE server.
|
|
| 501 |
- `middleware`: A list of middleware to apply to the app
|
| 502 |
|
| 503 |
|
| 504 |
-
#### `streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 505 |
|
| 506 |
```python
|
| 507 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -514,7 +655,7 @@ Create a Starlette app for the StreamableHTTP server.
|
|
| 514 |
- `middleware`: A list of middleware to apply to the app
|
| 515 |
|
| 516 |
|
| 517 |
-
#### `http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 518 |
|
| 519 |
```python
|
| 520 |
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
|
|
@@ -531,7 +672,13 @@ Create a Starlette app using the specified HTTP transport.
|
|
| 531 |
- A Starlette application configured with the specified transport
|
| 532 |
|
| 533 |
|
| 534 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
```python
|
| 537 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
@@ -585,7 +732,48 @@ automatically determined based on whether the server has a custom lifespan
|
|
| 585 |
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 586 |
|
| 587 |
|
| 588 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
|
| 590 |
```python
|
| 591 |
from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route_maps: list[RouteMap] | None = None, route_map_fn: OpenAPIRouteMapFn | None = None, mcp_component_fn: OpenAPIComponentFn | None = None, mcp_names: dict[str, str] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI
|
|
@@ -594,7 +782,7 @@ from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route
|
|
| 594 |
Create a FastMCP server from an OpenAPI specification.
|
| 595 |
|
| 596 |
|
| 597 |
-
#### `from_fastapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 598 |
|
| 599 |
```python
|
| 600 |
from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap] | None = None, route_map_fn: OpenAPIRouteMapFn | None = None, mcp_component_fn: OpenAPIComponentFn | 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
|
|
@@ -603,7 +791,7 @@ from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap]
|
|
| 603 |
Create a FastMCP server from a FastAPI application.
|
| 604 |
|
| 605 |
|
| 606 |
-
#### `as_proxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 607 |
|
| 608 |
```python
|
| 609 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
@@ -617,7 +805,7 @@ instance or any value accepted as the `transport` argument of
|
|
| 617 |
`fastmcp.client.Client` constructor.
|
| 618 |
|
| 619 |
|
| 620 |
-
#### `from_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 621 |
|
| 622 |
```python
|
| 623 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
@@ -626,4 +814,4 @@ from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPPr
|
|
| 626 |
Create a FastMCP proxy server from a FastMCP client.
|
| 627 |
|
| 628 |
|
| 629 |
-
### `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#L86" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Default lifespan context manager that does nothing.
|
| 21 |
+
|
| 22 |
+
**Args:**
|
| 23 |
+
- `server`: The server instance this lifespan is managing
|
| 24 |
+
|
| 25 |
+
**Returns:**
|
| 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#L2047" 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#L2107" 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#L2174" 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#L117" 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#L268" 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#L279" 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#L283" 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#L286" 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
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
Run the FastMCP server asynchronously.
|
| 175 |
+
|
| 176 |
+
**Args:**
|
| 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#L316" 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
|
| 184 |
```
|
| 185 |
|
| 186 |
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#L358" 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#L361" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 199 |
+
|
| 200 |
+
```python
|
| 201 |
+
get_tools(self) -> dict[str, Tool]
|
| 202 |
+
```
|
| 203 |
+
|
| 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#L365" 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#L371" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 214 |
+
|
| 215 |
+
```python
|
| 216 |
+
get_resources(self) -> dict[str, Resource]
|
| 217 |
+
```
|
| 218 |
+
|
| 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#L375" 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#L381" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 229 |
+
|
| 230 |
+
```python
|
| 231 |
+
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
| 232 |
+
```
|
| 233 |
+
|
| 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#L385" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 238 |
+
|
| 239 |
+
```python
|
| 240 |
+
get_resource_template(self, key: str) -> ResourceTemplate
|
| 241 |
+
```
|
| 242 |
+
|
| 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#L392" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 247 |
+
|
| 248 |
+
```python
|
| 249 |
+
get_prompts(self) -> dict[str, Prompt]
|
| 250 |
+
```
|
| 251 |
+
|
| 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#L398" 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#L404" 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)
|
|
|
|
| 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#L762" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 283 |
|
| 284 |
```python
|
| 285 |
+
add_tool(self, tool: Tool) -> Tool
|
| 286 |
```
|
| 287 |
|
| 288 |
Add a tool to the server.
|
|
|
|
| 293 |
**Args:**
|
| 294 |
- `tool`: The Tool instance to register
|
| 295 |
|
| 296 |
+
**Returns:**
|
| 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#L788" 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 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L810" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 316 |
|
| 317 |
```python
|
| 318 |
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 319 |
```
|
| 320 |
|
| 321 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L825" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 322 |
|
| 323 |
```python
|
| 324 |
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 325 |
```
|
| 326 |
|
| 327 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L839" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 328 |
|
| 329 |
```python
|
| 330 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
|
|
| 348 |
- `name`: Optional name for the tool (keyword-only, alternative to name_or_fn)
|
| 349 |
- `description`: Optional description of what the tool does
|
| 350 |
- `tags`: Optional set of tags for categorizing the tool
|
| 351 |
+
- `output_schema`: Optional JSON schema for the tool's output
|
| 352 |
- `annotations`: Optional annotations about the tool's behavior
|
| 353 |
- `exclude_args`: Optional list of argument names to exclude from the tool schema
|
| 354 |
- `enabled`: Optional boolean to enable or disable the tool
|
|
|
|
| 379 |
```
|
| 380 |
|
| 381 |
|
| 382 |
+
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L966" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 383 |
|
| 384 |
```python
|
| 385 |
+
add_resource(self, resource: Resource) -> Resource
|
| 386 |
```
|
| 387 |
|
| 388 |
Add a resource to the server.
|
|
|
|
| 390 |
**Args:**
|
| 391 |
- `resource`: A Resource instance to add
|
| 392 |
|
| 393 |
+
**Returns:**
|
| 394 |
+
- The resource instance that was added to the server.
|
| 395 |
|
| 396 |
+
|
| 397 |
+
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L989" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 398 |
|
| 399 |
```python
|
| 400 |
+
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
| 401 |
```
|
| 402 |
|
| 403 |
Add a resource template to the server.
|
|
|
|
| 405 |
**Args:**
|
| 406 |
- `template`: A ResourceTemplate instance to add
|
| 407 |
|
| 408 |
+
**Returns:**
|
| 409 |
+
- The template instance that was added to the server.
|
| 410 |
+
|
| 411 |
|
| 412 |
+
#### `add_resource_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1011" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 413 |
|
| 414 |
```python
|
| 415 |
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
|
|
|
|
| 429 |
- `tags`: Optional set of tags for categorizing the resource
|
| 430 |
|
| 431 |
|
| 432 |
+
#### `resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1050" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 433 |
|
| 434 |
```python
|
| 435 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
|
|
| 487 |
```
|
| 488 |
|
| 489 |
|
| 490 |
+
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1176" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 491 |
|
| 492 |
```python
|
| 493 |
+
add_prompt(self, prompt: Prompt) -> Prompt
|
| 494 |
```
|
| 495 |
|
| 496 |
Add a prompt to the server.
|
|
|
|
| 498 |
**Args:**
|
| 499 |
- `prompt`: A Prompt instance to add
|
| 500 |
|
| 501 |
+
**Returns:**
|
| 502 |
+
- The prompt instance that was added to the server.
|
| 503 |
+
|
| 504 |
|
| 505 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1200" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 506 |
|
| 507 |
```python
|
| 508 |
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 509 |
```
|
| 510 |
|
| 511 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1212" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 512 |
|
| 513 |
```python
|
| 514 |
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 515 |
```
|
| 516 |
|
| 517 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1223" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 518 |
|
| 519 |
```python
|
| 520 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
|
|
| 591 |
```
|
| 592 |
|
| 593 |
|
| 594 |
+
#### `run_stdio_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1360" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 595 |
+
|
| 596 |
+
```python
|
| 597 |
+
run_stdio_async(self, show_banner: bool = True) -> None
|
| 598 |
+
```
|
| 599 |
+
|
| 600 |
+
Run the server using stdio transport.
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
#### `run_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1380" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 604 |
+
|
| 605 |
+
```python
|
| 606 |
+
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
|
| 607 |
+
```
|
| 608 |
+
|
| 609 |
+
Run the server using HTTP transport.
|
| 610 |
+
|
| 611 |
+
**Args:**
|
| 612 |
+
- `transport`: Transport protocol to use - either "streamable-http" (default) or "sse"
|
| 613 |
+
- `host`: Host address to bind to (defaults to settings.host)
|
| 614 |
+
- `port`: Port to bind to (defaults to settings.port)
|
| 615 |
+
- `log_level`: Log level for the server (defaults to settings.log_level)
|
| 616 |
+
- `path`: Path for the endpoint (defaults to settings.streamable_http_path or settings.sse_path)
|
| 617 |
+
- `uvicorn_config`: Additional configuration for the Uvicorn server
|
| 618 |
+
- `middleware`: A list of middleware to apply to the app
|
| 619 |
+
- `stateless_http`: Whether to use stateless HTTP (defaults to settings.stateless_http)
|
| 620 |
+
|
| 621 |
+
|
| 622 |
+
#### `run_sse_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1454" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 623 |
+
|
| 624 |
+
```python
|
| 625 |
+
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
|
| 626 |
+
```
|
| 627 |
+
|
| 628 |
+
Run the server using SSE transport.
|
| 629 |
+
|
| 630 |
+
|
| 631 |
+
#### `sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1482" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 632 |
|
| 633 |
```python
|
| 634 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 642 |
- `middleware`: A list of middleware to apply to the app
|
| 643 |
|
| 644 |
|
| 645 |
+
#### `streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1513" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 646 |
|
| 647 |
```python
|
| 648 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 655 |
- `middleware`: A list of middleware to apply to the app
|
| 656 |
|
| 657 |
|
| 658 |
+
#### `http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1534" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 659 |
|
| 660 |
```python
|
| 661 |
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
|
|
|
|
| 672 |
- A Starlette application configured with the specified transport
|
| 673 |
|
| 674 |
|
| 675 |
+
#### `run_streamable_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1583" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 676 |
+
|
| 677 |
+
```python
|
| 678 |
+
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
|
| 679 |
+
```
|
| 680 |
+
|
| 681 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1608" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 682 |
|
| 683 |
```python
|
| 684 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
|
|
| 732 |
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 733 |
|
| 734 |
|
| 735 |
+
#### `import_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1732" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 736 |
+
|
| 737 |
+
```python
|
| 738 |
+
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
|
| 739 |
+
```
|
| 740 |
+
|
| 741 |
+
Import the MCP objects from another FastMCP server into this one,
|
| 742 |
+
optionally with a given prefix.
|
| 743 |
+
|
| 744 |
+
Note that when a server is *imported*, its objects are immediately
|
| 745 |
+
registered to the importing server. This is a one-time operation and
|
| 746 |
+
future changes to the imported server will not be reflected in the
|
| 747 |
+
importing server. Server-level configurations and lifespans are not imported.
|
| 748 |
+
|
| 749 |
+
When a server is imported with a prefix:
|
| 750 |
+
- The tools are imported with prefixed names
|
| 751 |
+
Example: If server has a tool named "get_weather", it will be
|
| 752 |
+
available as "prefix_get_weather"
|
| 753 |
+
- The resources are imported with prefixed URIs using the new format
|
| 754 |
+
Example: If server has a resource with URI "weather://forecast", it will
|
| 755 |
+
be available as "weather://prefix/forecast"
|
| 756 |
+
- The templates are imported with prefixed URI templates using the new format
|
| 757 |
+
Example: If server has a template with URI "weather://location/{id}", it will
|
| 758 |
+
be available as "weather://prefix/location/{id}"
|
| 759 |
+
- The prompts are imported with prefixed names
|
| 760 |
+
Example: If server has a prompt named "weather_prompt", it will be available as
|
| 761 |
+
"prefix_weather_prompt"
|
| 762 |
+
|
| 763 |
+
When a server is imported without a prefix (prefix=None), its tools, resources,
|
| 764 |
+
templates, and prompts are imported with their original names.
|
| 765 |
+
|
| 766 |
+
**Args:**
|
| 767 |
+
- `server`: The FastMCP server to import
|
| 768 |
+
- `prefix`: Optional prefix to use for the imported server's objects. If None,
|
| 769 |
+
objects are imported with their original names.
|
| 770 |
+
- `tool_separator`: Deprecated. Separator for tool names.
|
| 771 |
+
- `resource_separator`: Deprecated and ignored. Prefix is now
|
| 772 |
+
applied using the protocol\://prefix/path format
|
| 773 |
+
- `prompt_separator`: Deprecated. Separator for prompt names.
|
| 774 |
+
|
| 775 |
+
|
| 776 |
+
#### `from_openapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1857" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 777 |
|
| 778 |
```python
|
| 779 |
from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route_maps: list[RouteMap] | None = None, route_map_fn: OpenAPIRouteMapFn | None = None, mcp_component_fn: OpenAPIComponentFn | None = None, mcp_names: dict[str, str] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI
|
|
|
|
| 782 |
Create a FastMCP server from an OpenAPI specification.
|
| 783 |
|
| 784 |
|
| 785 |
+
#### `from_fastapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1885" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 786 |
|
| 787 |
```python
|
| 788 |
from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap] | None = None, route_map_fn: OpenAPIRouteMapFn | None = None, mcp_component_fn: OpenAPIComponentFn | 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
|
|
|
|
| 791 |
Create a FastMCP server from a FastAPI application.
|
| 792 |
|
| 793 |
|
| 794 |
+
#### `as_proxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1927" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 795 |
|
| 796 |
```python
|
| 797 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
|
|
| 805 |
`fastmcp.client.Client` constructor.
|
| 806 |
|
| 807 |
|
| 808 |
+
#### `from_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1988" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 809 |
|
| 810 |
```python
|
| 811 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
|
|
| 814 |
Create a FastMCP proxy server from a FastMCP client.
|
| 815 |
|
| 816 |
|
| 817 |
+
### `MountedServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2041" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
docs/python-sdk/fastmcp-settings.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: settings
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `ExtendedEnvSettingsSource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#
|
| 11 |
|
| 12 |
|
| 13 |
A special EnvSettingsSource that allows for multiple env var prefixes to be used.
|
|
@@ -17,15 +17,15 @@ Raises a deprecation warning if the old `FASTMCP_SERVER_` prefix is used.
|
|
| 17 |
|
| 18 |
**Methods:**
|
| 19 |
|
| 20 |
-
#### `get_field_value` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#
|
| 21 |
|
| 22 |
```python
|
| 23 |
get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool]
|
| 24 |
```
|
| 25 |
|
| 26 |
-
### `ExtendedSettingsConfigDict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#
|
| 27 |
|
| 28 |
-
### `Settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#
|
| 29 |
|
| 30 |
|
| 31 |
FastMCP settings.
|
|
@@ -33,13 +33,13 @@ FastMCP settings.
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
-
#### `settings_customise_sources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
settings_customise_sources(cls, settings_cls: type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> tuple[PydanticBaseSettingsSource, ...]
|
| 40 |
```
|
| 41 |
|
| 42 |
-
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#
|
| 43 |
|
| 44 |
```python
|
| 45 |
settings(self) -> Self
|
|
@@ -49,7 +49,13 @@ This property is for backwards compatibility with FastMCP < 2.8.0,
|
|
| 49 |
which accessed fastmcp.settings.settings
|
| 50 |
|
| 51 |
|
| 52 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
```python
|
| 55 |
setup_logging(self) -> Self
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ExtendedEnvSettingsSource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L27" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
A special EnvSettingsSource that allows for multiple env var prefixes to be used.
|
|
|
|
| 17 |
|
| 18 |
**Methods:**
|
| 19 |
|
| 20 |
+
#### `get_field_value` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L34" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 21 |
|
| 22 |
```python
|
| 23 |
get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool]
|
| 24 |
```
|
| 25 |
|
| 26 |
+
### `ExtendedSettingsConfigDict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 27 |
|
| 28 |
+
### `Settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L58" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 29 |
|
| 30 |
|
| 31 |
FastMCP settings.
|
|
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
+
#### `settings_customise_sources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L70" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
settings_customise_sources(cls, settings_cls: type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> tuple[PydanticBaseSettingsSource, ...]
|
| 40 |
```
|
| 41 |
|
| 42 |
+
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L88" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 43 |
|
| 44 |
```python
|
| 45 |
settings(self) -> Self
|
|
|
|
| 49 |
which accessed fastmcp.settings.settings
|
| 50 |
|
| 51 |
|
| 52 |
+
#### `normalize_log_level` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L107" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 53 |
+
|
| 54 |
+
```python
|
| 55 |
+
normalize_log_level(cls, v)
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
#### `setup_logging` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L175" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 59 |
|
| 60 |
```python
|
| 61 |
setup_logging(self) -> Self
|
docs/python-sdk/fastmcp-tools-tool.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: tool
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `default_serializer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_serializer(data: Any) -> str
|
|
@@ -15,7 +15,17 @@ default_serializer(data: Any) -> str
|
|
| 15 |
|
| 16 |
## Classes
|
| 17 |
|
| 18 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
Internal tool registration info.
|
|
@@ -23,46 +33,82 @@ Internal tool registration info.
|
|
| 23 |
|
| 24 |
**Methods:**
|
| 25 |
|
| 26 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
```python
|
| 29 |
to_mcp_tool(self, **overrides: Any) -> MCPTool
|
| 30 |
```
|
| 31 |
|
| 32 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 33 |
|
| 34 |
```python
|
| 35 |
-
from_function(fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 36 |
```
|
| 37 |
|
| 38 |
Create a Tool from a function.
|
| 39 |
|
| 40 |
|
| 41 |
-
#### `
|
| 42 |
|
| 43 |
```python
|
| 44 |
-
|
| 45 |
```
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
**Methods:**
|
| 50 |
|
| 51 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 52 |
|
| 53 |
```python
|
| 54 |
-
from_function(cls, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 55 |
```
|
| 56 |
|
| 57 |
Create a Tool from a function.
|
| 58 |
|
| 59 |
|
| 60 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
**Methods:**
|
| 63 |
|
| 64 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 65 |
|
| 66 |
```python
|
| 67 |
-
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True) -> ParsedFunction
|
| 68 |
```
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_serializer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L48" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_serializer(data: Any) -> str
|
|
|
|
| 15 |
|
| 16 |
## Classes
|
| 17 |
|
| 18 |
+
### `ToolResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L52" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 19 |
+
|
| 20 |
+
**Methods:**
|
| 21 |
+
|
| 22 |
+
#### `to_mcp_result` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L83" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 23 |
+
|
| 24 |
+
```python
|
| 25 |
+
to_mcp_result(self) -> list[ContentBlock] | tuple[list[ContentBlock], dict[str, Any]]
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### `Tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L91" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 29 |
|
| 30 |
|
| 31 |
Internal tool registration info.
|
|
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
+
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L109" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
enable(self) -> None
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L117" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
disable(self) -> None
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
#### `to_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L125" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
|
| 50 |
```python
|
| 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#L144" 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, 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#L170" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
|
| 65 |
```python
|
| 66 |
+
run(self, arguments: dict[str, Any]) -> ToolResult
|
| 67 |
```
|
| 68 |
|
| 69 |
+
Run the tool with arguments.
|
| 70 |
+
|
| 71 |
+
This method is not implemented in the base Tool class and must be
|
| 72 |
+
implemented by subclasses.
|
| 73 |
+
|
| 74 |
+
`run()` can EITHER return a list of ContentBlocks, or a tuple of
|
| 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#L183" 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, enabled: bool | None = None) -> TransformedTool
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
### `FunctionTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L214" 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#L218" 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, 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#L264" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 98 |
+
|
| 99 |
+
```python
|
| 100 |
+
run(self, arguments: dict[str, Any]) -> ToolResult
|
| 101 |
+
```
|
| 102 |
+
|
| 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#L310" 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#L318" 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
|
| 114 |
```
|
docs/python-sdk/fastmcp-tools-tool_manager.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: tool_manager
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `ToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#
|
| 11 |
|
| 12 |
|
| 13 |
Manages FastMCP tools.
|
|
@@ -15,7 +15,7 @@ Manages FastMCP tools.
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
-
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#
|
| 19 |
|
| 20 |
```python
|
| 21 |
mount(self, server: MountedServer) -> None
|
|
@@ -24,7 +24,43 @@ mount(self, server: MountedServer) -> None
|
|
| 24 |
Adds a mounted server as a source for tools.
|
| 25 |
|
| 26 |
|
| 27 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
```python
|
| 30 |
add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, exclude_args: list[str] | None = None) -> Tool
|
|
@@ -33,7 +69,7 @@ add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, descript
|
|
| 33 |
Add a tool to the server.
|
| 34 |
|
| 35 |
|
| 36 |
-
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
add_tool(self, tool: Tool) -> Tool
|
|
@@ -42,7 +78,7 @@ add_tool(self, tool: Tool) -> Tool
|
|
| 42 |
Register a tool with the server.
|
| 43 |
|
| 44 |
|
| 45 |
-
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#
|
| 46 |
|
| 47 |
```python
|
| 48 |
remove_tool(self, key: str) -> None
|
|
@@ -56,3 +92,13 @@ Remove a tool from the server.
|
|
| 56 |
**Raises:**
|
| 57 |
- `NotFoundError`: If the tool is not found
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L21" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
Manages FastMCP tools.
|
|
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L45" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 19 |
|
| 20 |
```python
|
| 21 |
mount(self, server: MountedServer) -> None
|
|
|
|
| 24 |
Adds a mounted server as a source for tools.
|
| 25 |
|
| 26 |
|
| 27 |
+
#### `has_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L87" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
has_tool(self, key: str) -> bool
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Check if a tool exists.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#### `get_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L92" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
get_tool(self, key: str) -> Tool
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Get tool by key.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L99" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
get_tools(self) -> dict[str, Tool]
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Gets the complete, unfiltered inventory of all tools.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
#### `list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L105" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
list_tools(self) -> list[Tool]
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
Lists all tools, applying protocol filtering.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
#### `add_tool_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L112" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
|
| 65 |
```python
|
| 66 |
add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, exclude_args: list[str] | None = None) -> Tool
|
|
|
|
| 69 |
Add a tool to the server.
|
| 70 |
|
| 71 |
|
| 72 |
+
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L141" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 73 |
|
| 74 |
```python
|
| 75 |
add_tool(self, tool: Tool) -> Tool
|
|
|
|
| 78 |
Register a tool with the server.
|
| 79 |
|
| 80 |
|
| 81 |
+
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L158" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 82 |
|
| 83 |
```python
|
| 84 |
remove_tool(self, key: str) -> None
|
|
|
|
| 92 |
**Raises:**
|
| 93 |
- `NotFoundError`: If the tool is not found
|
| 94 |
|
| 95 |
+
|
| 96 |
+
#### `call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L172" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
Internal API for servers: Finds and calls a tool, respecting the
|
| 103 |
+
filtered protocol path.
|
| 104 |
+
|
docs/python-sdk/fastmcp-tools-tool_transform.mdx
CHANGED
|
@@ -5,9 +5,66 @@ sidebarTitle: tool_transform
|
|
| 5 |
|
| 6 |
# `fastmcp.tools.tool_transform`
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `ArgTransform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 11 |
|
| 12 |
|
| 13 |
Configuration for transforming a parent tool's argument.
|
|
@@ -69,26 +126,46 @@ ArgTransform(name="new_name", description="New desc", default=None, type=int)
|
|
| 69 |
```
|
| 70 |
|
| 71 |
|
| 72 |
-
### `TransformedTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 73 |
|
| 74 |
|
| 75 |
A tool that is transformed from another tool.
|
| 76 |
|
| 77 |
This class represents a tool that has been created by transforming another tool.
|
| 78 |
It supports argument renaming, schema modification, custom function injection,
|
| 79 |
-
and provides context for the forward() and forward_raw() functions.
|
| 80 |
|
| 81 |
The transformation can be purely schema-based (argument renaming, dropping, etc.)
|
| 82 |
or can include a custom function that uses forward() to call the parent tool
|
| 83 |
-
with transformed arguments.
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
**Methods:**
|
| 87 |
|
| 88 |
-
#### `
|
| 89 |
|
| 90 |
```python
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
```
|
| 93 |
|
| 94 |
Create a transformed tool from a parent tool.
|
|
@@ -99,6 +176,7 @@ Create a transformed tool from a parent tool.
|
|
| 99 |
to call the parent tool. Functions with **kwargs receive transformed
|
| 100 |
argument names.
|
| 101 |
- `name`: New name for the tool. Defaults to parent tool's name.
|
|
|
|
| 102 |
- `transform_args`: Optional transformations for parent tool arguments.
|
| 103 |
Only specified arguments are transformed, others pass through unchanged\:
|
| 104 |
- Simple rename (str)
|
|
@@ -107,6 +185,10 @@ Only specified arguments are transformed, others pass through unchanged\:
|
|
| 107 |
- `description`: New description. Defaults to parent's description.
|
| 108 |
- `tags`: New tags. Defaults to parent's tags.
|
| 109 |
- `annotations`: New annotations. Defaults to parent's annotations.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
- `serializer`: New serializer. Defaults to parent's serializer.
|
| 111 |
|
| 112 |
**Returns:**
|
|
@@ -137,3 +219,23 @@ async def flexible(**kwargs) -> str:
|
|
| 137 |
Tool.from_tool(parent, transform_fn=flexible, transform_args={"a": "x"})
|
| 138 |
```
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# `fastmcp.tools.tool_transform`
|
| 7 |
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `forward` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L25" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
forward(**kwargs) -> ToolResult
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Forward to parent tool with argument transformation applied.
|
| 18 |
+
|
| 19 |
+
This function can only be called from within a transformed tool's custom
|
| 20 |
+
function. It applies argument transformation (renaming, validation) before
|
| 21 |
+
calling the parent tool.
|
| 22 |
+
|
| 23 |
+
For example, if the parent tool has args `x` and `y`, but the transformed
|
| 24 |
+
tool has args `a` and `b`, and an `transform_args` was provided that maps `x` to
|
| 25 |
+
`a` and `y` to `b`, then `forward(a=1, b=2)` will call the parent tool with
|
| 26 |
+
`x=1` and `y=2`.
|
| 27 |
+
|
| 28 |
+
**Args:**
|
| 29 |
+
- `**kwargs`: Arguments to forward to the parent tool (using transformed names).
|
| 30 |
+
|
| 31 |
+
**Returns:**
|
| 32 |
+
- The ToolResult from the parent tool execution.
|
| 33 |
+
|
| 34 |
+
**Raises:**
|
| 35 |
+
- `RuntimeError`: If called outside a transformed tool context.
|
| 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#L55" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
forward_raw(**kwargs) -> ToolResult
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Forward directly to parent tool without transformation.
|
| 47 |
+
|
| 48 |
+
This function bypasses all argument transformation and validation, calling the parent
|
| 49 |
+
tool directly with the provided arguments. Use this when you need to call the parent
|
| 50 |
+
with its original parameter names and structure.
|
| 51 |
+
|
| 52 |
+
For example, if the parent tool has args `x` and `y`, then `forward_raw(x=1,
|
| 53 |
+
y=2)` will call the parent tool with `x=1` and `y=2`.
|
| 54 |
+
|
| 55 |
+
**Args:**
|
| 56 |
+
- `**kwargs`: Arguments to pass directly to the parent tool (using original names).
|
| 57 |
+
|
| 58 |
+
**Returns:**
|
| 59 |
+
- The ToolResult from the parent tool execution.
|
| 60 |
+
|
| 61 |
+
**Raises:**
|
| 62 |
+
- `RuntimeError`: If called outside a transformed tool context.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
## Classes
|
| 66 |
|
| 67 |
+
### `ArgTransform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L82" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 68 |
|
| 69 |
|
| 70 |
Configuration for transforming a parent tool's argument.
|
|
|
|
| 126 |
```
|
| 127 |
|
| 128 |
|
| 129 |
+
### `TransformedTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L196" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 130 |
|
| 131 |
|
| 132 |
A tool that is transformed from another tool.
|
| 133 |
|
| 134 |
This class represents a tool that has been created by transforming another tool.
|
| 135 |
It supports argument renaming, schema modification, custom function injection,
|
| 136 |
+
structured output control, and provides context for the forward() and forward_raw() functions.
|
| 137 |
|
| 138 |
The transformation can be purely schema-based (argument renaming, dropping, etc.)
|
| 139 |
or can include a custom function that uses forward() to call the parent tool
|
| 140 |
+
with transformed arguments. Output schemas and structured outputs are automatically
|
| 141 |
+
inherited from the parent tool but can be overridden or disabled.
|
| 142 |
|
| 143 |
|
| 144 |
**Methods:**
|
| 145 |
|
| 146 |
+
#### `run` <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>
|
| 147 |
|
| 148 |
```python
|
| 149 |
+
run(self, arguments: dict[str, Any]) -> ToolResult
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
Run the tool with context set for forward() functions.
|
| 153 |
+
|
| 154 |
+
This method executes the tool's function while setting up the context
|
| 155 |
+
that allows forward() and forward_raw() to work correctly within custom
|
| 156 |
+
functions.
|
| 157 |
+
|
| 158 |
+
**Args:**
|
| 159 |
+
- `arguments`: Dictionary of arguments to pass to the tool's function.
|
| 160 |
+
|
| 161 |
+
**Returns:**
|
| 162 |
+
- ToolResult object containing content and optional structured output.
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L324" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 166 |
+
|
| 167 |
+
```python
|
| 168 |
+
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
|
| 169 |
```
|
| 170 |
|
| 171 |
Create a transformed tool from a parent tool.
|
|
|
|
| 176 |
to call the parent tool. Functions with **kwargs receive transformed
|
| 177 |
argument names.
|
| 178 |
- `name`: New name for the tool. Defaults to parent tool's name.
|
| 179 |
+
- `title`: New title for the tool. Defaults to parent tool's title.
|
| 180 |
- `transform_args`: Optional transformations for parent tool arguments.
|
| 181 |
Only specified arguments are transformed, others pass through unchanged\:
|
| 182 |
- Simple rename (str)
|
|
|
|
| 185 |
- `description`: New description. Defaults to parent's description.
|
| 186 |
- `tags`: New tags. Defaults to parent's tags.
|
| 187 |
- `annotations`: New annotations. Defaults to parent's annotations.
|
| 188 |
+
- `output_schema`: Control output schema for structured outputs\:
|
| 189 |
+
- None (default)\: Inherit from transform_fn if available, then parent tool
|
| 190 |
+
- dict\: Use custom output schema
|
| 191 |
+
- False\: Disable output schema and structured outputs
|
| 192 |
- `serializer`: New serializer. Defaults to parent's serializer.
|
| 193 |
|
| 194 |
**Returns:**
|
|
|
|
| 219 |
Tool.from_tool(parent, transform_fn=flexible, transform_args={"a": "x"})
|
| 220 |
```
|
| 221 |
|
| 222 |
+
# Control structured outputs and schemas
|
| 223 |
+
```python
|
| 224 |
+
# Custom output schema
|
| 225 |
+
Tool.from_tool(parent, output_schema={
|
| 226 |
+
"type": "object",
|
| 227 |
+
"properties": {"status": {"type": "string"}}
|
| 228 |
+
})
|
| 229 |
+
|
| 230 |
+
# Disable structured outputs
|
| 231 |
+
Tool.from_tool(parent, output_schema=False)
|
| 232 |
+
|
| 233 |
+
# Return ToolResult for full control
|
| 234 |
+
async def custom_output(**kwargs) -> ToolResult:
|
| 235 |
+
result = await forward(**kwargs)
|
| 236 |
+
return ToolResult(
|
| 237 |
+
content=[TextContent(text="Summary")],
|
| 238 |
+
structured_content={"processed": True}
|
| 239 |
+
)
|
| 240 |
+
```
|
| 241 |
+
|