Spaces:
Running
Running
Jeremiah Lowin commited on
Update SDK docs (#1236)
Browse files- docs/docs.json +24 -7
- docs/python-sdk/fastmcp-cli-cli.mdx +10 -9
- docs/python-sdk/fastmcp-cli-install-claude_code.mdx +4 -1
- docs/python-sdk/fastmcp-cli-install-claude_desktop.mdx +4 -1
- docs/python-sdk/fastmcp-cli-install-cursor.mdx +4 -1
- docs/python-sdk/{fastmcp-cli-install-mcp_config.mdx → fastmcp-cli-install-mcp_json.mdx} +10 -7
- docs/python-sdk/fastmcp-cli-run.mdx +42 -8
- docs/python-sdk/fastmcp-client-transports.mdx +3 -3
- docs/python-sdk/fastmcp-mcp_config.mdx +73 -35
- docs/python-sdk/fastmcp-server-context.mdx +52 -24
- docs/python-sdk/fastmcp-server-middleware.mdx +0 -56
- docs/python-sdk/fastmcp-server-proxy.mdx +58 -33
- docs/python-sdk/fastmcp-server-server.mdx +68 -50
- docs/python-sdk/fastmcp-settings.mdx +25 -12
- docs/python-sdk/fastmcp-tools-tool.mdx +15 -15
- docs/python-sdk/fastmcp-tools-tool_manager.mdx +37 -10
- docs/python-sdk/fastmcp-tools-tool_transform.mdx +51 -6
- docs/python-sdk/fastmcp-utilities-json_schema.mdx +1 -1
- docs/python-sdk/fastmcp-utilities-mcp_config.mdx +6 -28
- docs/python-sdk/fastmcp-utilities-openapi.mdx +15 -16
- docs/python-sdk/fastmcp-utilities-tests.mdx +2 -2
- docs/python-sdk/fastmcp-utilities-types.mdx +19 -17
- src/fastmcp/mcp_config.py +11 -9
- src/fastmcp/utilities/openapi.py +1 -2
- src/fastmcp/utilities/types.py +6 -5
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 |
},
|
|
@@ -175,12 +186,17 @@
|
|
| 175 |
},
|
| 176 |
{
|
| 177 |
"anchor": "What's New",
|
| 178 |
-
"pages": [
|
|
|
|
|
|
|
|
|
|
| 179 |
},
|
| 180 |
{
|
| 181 |
"anchor": "Community",
|
| 182 |
"icon": "users",
|
| 183 |
-
"pages": [
|
|
|
|
|
|
|
| 184 |
}
|
| 185 |
]
|
| 186 |
},
|
|
@@ -207,7 +223,7 @@
|
|
| 207 |
"python-sdk/fastmcp-cli-install-claude_code",
|
| 208 |
"python-sdk/fastmcp-cli-install-claude_desktop",
|
| 209 |
"python-sdk/fastmcp-cli-install-cursor",
|
| 210 |
-
"python-sdk/fastmcp-cli-install-
|
| 211 |
"python-sdk/fastmcp-cli-install-shared"
|
| 212 |
]
|
| 213 |
},
|
|
@@ -318,6 +334,7 @@
|
|
| 318 |
"python-sdk/fastmcp-utilities-json_schema",
|
| 319 |
"python-sdk/fastmcp-utilities-json_schema_type",
|
| 320 |
"python-sdk/fastmcp-utilities-logging",
|
|
|
|
| 321 |
"python-sdk/fastmcp-utilities-openapi",
|
| 322 |
"python-sdk/fastmcp-utilities-tests",
|
| 323 |
"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 |
},
|
|
|
|
| 186 |
},
|
| 187 |
{
|
| 188 |
"anchor": "What's New",
|
| 189 |
+
"pages": [
|
| 190 |
+
"updates",
|
| 191 |
+
"changelog"
|
| 192 |
+
]
|
| 193 |
},
|
| 194 |
{
|
| 195 |
"anchor": "Community",
|
| 196 |
"icon": "users",
|
| 197 |
+
"pages": [
|
| 198 |
+
"community/showcase"
|
| 199 |
+
]
|
| 200 |
}
|
| 201 |
]
|
| 202 |
},
|
|
|
|
| 223 |
"python-sdk/fastmcp-cli-install-claude_code",
|
| 224 |
"python-sdk/fastmcp-cli-install-claude_desktop",
|
| 225 |
"python-sdk/fastmcp-cli-install-cursor",
|
| 226 |
+
"python-sdk/fastmcp-cli-install-mcp_json",
|
| 227 |
"python-sdk/fastmcp-cli-install-shared"
|
| 228 |
]
|
| 229 |
},
|
|
|
|
| 334 |
"python-sdk/fastmcp-utilities-json_schema",
|
| 335 |
"python-sdk/fastmcp-utilities-json_schema_type",
|
| 336 |
"python-sdk/fastmcp-utilities-logging",
|
| 337 |
+
"python-sdk/fastmcp-utilities-mcp_config",
|
| 338 |
"python-sdk/fastmcp-utilities-openapi",
|
| 339 |
"python-sdk/fastmcp-utilities-tests",
|
| 340 |
"python-sdk/fastmcp-utilities-types"
|
docs/python-sdk/fastmcp-cli-cli.mdx
CHANGED
|
@@ -10,7 +10,7 @@ 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#
|
| 14 |
|
| 15 |
```python
|
| 16 |
version()
|
|
@@ -20,7 +20,7 @@ version()
|
|
| 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#
|
| 24 |
|
| 25 |
```python
|
| 26 |
dev(server_spec: str) -> None
|
|
@@ -33,7 +33,7 @@ Run an MCP server with the MCP Inspector for development.
|
|
| 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#
|
| 37 |
|
| 38 |
```python
|
| 39 |
run(server_spec: str) -> None
|
|
@@ -42,19 +42,20 @@ run(server_spec: str) -> None
|
|
| 42 |
|
| 43 |
Run an MCP server or connect to a remote one.
|
| 44 |
|
| 45 |
-
The server can be specified in
|
| 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#
|
| 58 |
|
| 59 |
```python
|
| 60 |
inspect(server_spec: str) -> None
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `version` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L103" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
version()
|
|
|
|
| 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#L141" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
dev(server_spec: str) -> None
|
|
|
|
| 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#L286" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
run(server_spec: str) -> None
|
|
|
|
| 42 |
|
| 43 |
Run an MCP server or connect to a remote one.
|
| 44 |
|
| 45 |
+
The server can be specified in four 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 |
+
4. MCPConfig file: "mcp.json" - runs as a proxy server for the MCP Servers in the MCPConfig file
|
| 50 |
|
| 51 |
Server arguments can be passed after -- :
|
| 52 |
fastmcp run server.py -- --config config.json --debug
|
| 53 |
|
| 54 |
**Args:**
|
| 55 |
+
- `server_spec`: Python file, object specification (file\:obj), MCPConfig file, or URL
|
| 56 |
|
| 57 |
|
| 58 |
+
### `inspect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L442" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 59 |
|
| 60 |
```python
|
| 61 |
inspect(server_spec: str) -> None
|
docs/python-sdk/fastmcp-cli-install-claude_code.mdx
CHANGED
|
@@ -49,12 +49,15 @@ Install FastMCP 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#
|
| 58 |
|
| 59 |
```python
|
| 60 |
claude_code_command(server_spec: str) -> None
|
|
|
|
| 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 |
+
- `python_version`: Optional Python version to use
|
| 53 |
+
- `with_requirements`: Optional requirements file to install from
|
| 54 |
+
- `project`: Optional project directory to run within
|
| 55 |
|
| 56 |
**Returns:**
|
| 57 |
- True if installation was successful, False otherwise
|
| 58 |
|
| 59 |
|
| 60 |
+
### `claude_code_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_code.py#L170" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 61 |
|
| 62 |
```python
|
| 63 |
claude_code_command(server_spec: str) -> None
|
docs/python-sdk/fastmcp-cli-install-claude_desktop.mdx
CHANGED
|
@@ -36,12 +36,15 @@ Install FastMCP server in Claude Desktop.
|
|
| 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#
|
| 45 |
|
| 46 |
```python
|
| 47 |
claude_desktop_command(server_spec: str) -> None
|
|
|
|
| 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 |
+
- `python_version`: Optional Python version to use
|
| 40 |
+
- `with_requirements`: Optional requirements file to install from
|
| 41 |
+
- `project`: Optional project directory to run within
|
| 42 |
|
| 43 |
**Returns:**
|
| 44 |
- True if installation was successful, False otherwise
|
| 45 |
|
| 46 |
|
| 47 |
+
### `claude_desktop_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/claude_desktop.py#L143" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 48 |
|
| 49 |
```python
|
| 50 |
claude_desktop_command(server_spec: str) -> None
|
docs/python-sdk/fastmcp-cli-install-cursor.mdx
CHANGED
|
@@ -59,12 +59,15 @@ Install FastMCP 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#
|
| 68 |
|
| 69 |
```python
|
| 70 |
cursor_command(server_spec: str) -> None
|
|
|
|
| 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 |
+
- `python_version`: Optional Python version to use
|
| 63 |
+
- `with_requirements`: Optional requirements file to install from
|
| 64 |
+
- `project`: Optional project directory to run within
|
| 65 |
|
| 66 |
**Returns:**
|
| 67 |
- True if installation was successful, False otherwise
|
| 68 |
|
| 69 |
|
| 70 |
+
### `cursor_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/cursor.py#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 71 |
|
| 72 |
```python
|
| 73 |
cursor_command(server_spec: str) -> None
|
docs/python-sdk/{fastmcp-cli-install-mcp_config.mdx → fastmcp-cli-install-mcp_json.mdx}
RENAMED
|
@@ -1,19 +1,19 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
sidebarTitle:
|
| 4 |
---
|
| 5 |
|
| 6 |
-
# `fastmcp.cli.install.
|
| 7 |
|
| 8 |
|
| 9 |
MCP configuration JSON generation for FastMCP install using Cyclopts.
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `
|
| 14 |
|
| 15 |
```python
|
| 16 |
-
|
| 17 |
```
|
| 18 |
|
| 19 |
|
|
@@ -27,15 +27,18 @@ Generate MCP configuration JSON for manual installation.
|
|
| 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 |
-
### `
|
| 36 |
|
| 37 |
```python
|
| 38 |
-
|
| 39 |
```
|
| 40 |
|
| 41 |
|
|
|
|
| 1 |
---
|
| 2 |
+
title: mcp_json
|
| 3 |
+
sidebarTitle: mcp_json
|
| 4 |
---
|
| 5 |
|
| 6 |
+
# `fastmcp.cli.install.mcp_json`
|
| 7 |
|
| 8 |
|
| 9 |
MCP configuration JSON generation for FastMCP install using Cyclopts.
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `install_mcp_json` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/mcp_json.py#L19" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
+
install_mcp_json(file: Path, server_object: str | None, name: str) -> bool
|
| 17 |
```
|
| 18 |
|
| 19 |
|
|
|
|
| 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 |
+
- `python_version`: Optional Python version to use
|
| 31 |
+
- `with_requirements`: Optional requirements file to install from
|
| 32 |
+
- `project`: Optional project directory to run within
|
| 33 |
|
| 34 |
**Returns:**
|
| 35 |
- True if generation was successful, False otherwise
|
| 36 |
|
| 37 |
|
| 38 |
+
### `mcp_json_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/install/mcp_json.py#L116" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 39 |
|
| 40 |
```python
|
| 41 |
+
mcp_json_command(server_spec: str) -> None
|
| 42 |
```
|
| 43 |
|
| 44 |
|
docs/python-sdk/fastmcp-cli-run.mdx
CHANGED
|
@@ -10,7 +10,7 @@ FastMCP run command implementation with enhanced type hints.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `is_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
is_url(path: str) -> bool
|
|
@@ -20,7 +20,7 @@ is_url(path: str) -> bool
|
|
| 20 |
Check if a string is a URL.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `parse_file_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 24 |
|
| 25 |
```python
|
| 26 |
parse_file_path(server_spec: str) -> tuple[Path, str | None]
|
|
@@ -36,7 +36,7 @@ Parse a file path that may include a server object specification.
|
|
| 36 |
- Tuple of (file_path, server_object)
|
| 37 |
|
| 38 |
|
| 39 |
-
### `import_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#
|
| 40 |
|
| 41 |
```python
|
| 42 |
import_server(file: Path, server_object: str | None = None) -> Any
|
|
@@ -53,7 +53,30 @@ Import a MCP server from a file.
|
|
| 53 |
- The server object
|
| 54 |
|
| 55 |
|
| 56 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
```python
|
| 59 |
create_client_server(url: str) -> Any
|
|
@@ -69,7 +92,17 @@ Create a FastMCP server from a client URL.
|
|
| 69 |
- A FastMCP server instance
|
| 70 |
|
| 71 |
|
| 72 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
```python
|
| 75 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
@@ -87,17 +120,17 @@ 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: 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 |
|
| 97 |
Run a MCP server or connect to a remote one.
|
| 98 |
|
| 99 |
**Args:**
|
| 100 |
-
- `server_spec`: Python file, object specification (file\:obj), or URL
|
| 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
|
|
@@ -105,4 +138,5 @@ Run a MCP server or connect to a remote one.
|
|
| 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 |
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `is_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L21" 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#L27" 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#L58" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
import_server(file: Path, server_object: str | None = None) -> Any
|
|
|
|
| 53 |
- The server object
|
| 54 |
|
| 55 |
|
| 56 |
+
### `run_with_uv` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L128" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
run_with_uv(server_spec: str, python_version: str | None = None, with_packages: list[str] | None = None, with_requirements: Path | None = None, project: Path | None = None, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, show_banner: bool = True) -> None
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Run a MCP server using uv run subprocess.
|
| 64 |
+
|
| 65 |
+
**Args:**
|
| 66 |
+
- `server_spec`: Python file, object specification (file\:obj), or URL
|
| 67 |
+
- `python_version`: Python version to use (e.g. "3.10")
|
| 68 |
+
- `with_packages`: Additional packages to install
|
| 69 |
+
- `with_requirements`: Requirements file to use
|
| 70 |
+
- `project`: Run the command within the given project directory
|
| 71 |
+
- `transport`: Transport protocol to use
|
| 72 |
+
- `host`: Host to bind to when using http transport
|
| 73 |
+
- `port`: Port to bind to when using http transport
|
| 74 |
+
- `path`: Path to bind to when using http transport
|
| 75 |
+
- `log_level`: Log level
|
| 76 |
+
- `show_banner`: Whether to show the server banner
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L206" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 80 |
|
| 81 |
```python
|
| 82 |
create_client_server(url: str) -> Any
|
|
|
|
| 92 |
- A FastMCP server instance
|
| 93 |
|
| 94 |
|
| 95 |
+
### `create_mcp_config_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L226" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 96 |
+
|
| 97 |
+
```python
|
| 98 |
+
create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
Create a FastMCP server from a MCPConfig.
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L237" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 106 |
|
| 107 |
```python
|
| 108 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
|
|
| 120 |
- The imported server object
|
| 121 |
|
| 122 |
|
| 123 |
+
### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L261" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 124 |
|
| 125 |
```python
|
| 126 |
+
run_command(server_spec: str, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, server_args: list[str] | None = None, show_banner: bool = True, use_direct_import: bool = False) -> None
|
| 127 |
```
|
| 128 |
|
| 129 |
|
| 130 |
Run a MCP server or connect to a remote one.
|
| 131 |
|
| 132 |
**Args:**
|
| 133 |
+
- `server_spec`: Python file, object specification (file\:obj), MCPConfig file, or URL
|
| 134 |
- `transport`: Transport protocol to use
|
| 135 |
- `host`: Host to bind to when using http transport
|
| 136 |
- `port`: Port to bind to when using http transport
|
|
|
|
| 138 |
- `log_level`: Log level
|
| 139 |
- `server_args`: Additional arguments to pass to the server
|
| 140 |
- `show_banner`: Whether to show the server banner
|
| 141 |
+
- `use_direct_import`: Whether to use direct import instead of subprocess
|
| 142 |
|
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
|
|
@@ -238,7 +238,7 @@ object or dictionary matching the MCPConfig schema. It supports two key scenario
|
|
| 238 |
|
| 239 |
1. If the MCPConfig contains exactly one server, it creates a direct transport to that server.
|
| 240 |
2. If the MCPConfig contains multiple servers, it creates a composite client by mounting
|
| 241 |
-
all servers on a single FastMCP instance, with each server's name used as its mounting prefix.
|
| 242 |
|
| 243 |
In the multi-server case, tools are accessible with the prefix pattern `{server_name}_{tool_name}`
|
| 244 |
and resources with the pattern `protocol://{server_name}/path/to/resource`.
|
|
@@ -281,7 +281,7 @@ async with client:
|
|
| 281 |
|
| 282 |
**Methods:**
|
| 283 |
|
| 284 |
-
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#
|
| 285 |
|
| 286 |
```python
|
| 287 |
connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `infer_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L847" 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
|
|
|
|
| 238 |
|
| 239 |
1. If the MCPConfig contains exactly one server, it creates a direct transport to that server.
|
| 240 |
2. If the MCPConfig contains multiple servers, it creates a composite client by mounting
|
| 241 |
+
all servers on a single FastMCP instance, with each server's name, by default, used as its mounting prefix.
|
| 242 |
|
| 243 |
In the multi-server case, tools are accessible with the prefix pattern `{server_name}_{tool_name}`
|
| 244 |
and resources with the pattern `protocol://{server_name}/path/to/resource`.
|
|
|
|
| 281 |
|
| 282 |
**Methods:**
|
| 283 |
|
| 284 |
+
#### `connect_session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L799" 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]
|
docs/python-sdk/fastmcp-mcp_config.mdx
CHANGED
|
@@ -15,22 +15,24 @@ The configuration format supports both stdio and remote (HTTP/SSE) transports, w
|
|
| 15 |
field definitions for server metadata, authentication, and execution parameters.
|
| 16 |
|
| 17 |
Example configuration:
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 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#
|
| 34 |
|
| 35 |
```python
|
| 36 |
infer_transport_type_from_url(url: str | AnyUrl) -> Literal['http', 'sse']
|
|
@@ -40,19 +42,22 @@ infer_transport_type_from_url(url: str | AnyUrl) -> Literal['http', 'sse']
|
|
| 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#
|
| 44 |
|
| 45 |
```python
|
| 46 |
-
update_config_file(file_path: Path, server_name: str, server_config:
|
| 47 |
```
|
| 48 |
|
| 49 |
|
| 50 |
-
Update MCP configuration file
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
## Classes
|
| 54 |
|
| 55 |
-
### `StdioMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#
|
| 56 |
|
| 57 |
|
| 58 |
MCP server configuration for stdio transport.
|
|
@@ -62,13 +67,19 @@ This is the canonical configuration format for MCP servers using stdio transport
|
|
| 62 |
|
| 63 |
**Methods:**
|
| 64 |
|
| 65 |
-
#### `to_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#
|
| 66 |
|
| 67 |
```python
|
| 68 |
to_transport(self) -> StdioTransport
|
| 69 |
```
|
| 70 |
|
| 71 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
MCP server configuration for HTTP/SSE transport.
|
|
@@ -78,33 +89,58 @@ This is the canonical configuration format for MCP servers using remote transpor
|
|
| 78 |
|
| 79 |
**Methods:**
|
| 80 |
|
| 81 |
-
#### `to_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#
|
| 82 |
|
| 83 |
```python
|
| 84 |
to_transport(self) -> StreamableHttpTransport | SSETransport
|
| 85 |
```
|
| 86 |
|
| 87 |
-
### `
|
| 88 |
|
| 89 |
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
**Methods:**
|
| 97 |
|
| 98 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
```python
|
| 101 |
-
from_dict(cls, config: dict[str, Any]) ->
|
| 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#
|
| 108 |
|
| 109 |
```python
|
| 110 |
to_dict(self) -> dict[str, Any]
|
|
@@ -113,7 +149,7 @@ to_dict(self) -> dict[str, Any]
|
|
| 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#
|
| 117 |
|
| 118 |
```python
|
| 119 |
write_to_file(self, file_path: Path) -> None
|
|
@@ -122,29 +158,31 @@ write_to_file(self, file_path: Path) -> None
|
|
| 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#
|
| 126 |
|
| 127 |
```python
|
| 128 |
-
from_file(cls, file_path: Path) ->
|
| 129 |
```
|
| 130 |
|
| 131 |
Load configuration from JSON file.
|
| 132 |
|
| 133 |
|
| 134 |
-
###
|
| 135 |
|
| 136 |
-
```python
|
| 137 |
-
add_server(self, name: str, server: StdioMCPServer | RemoteMCPServer) -> None
|
| 138 |
-
```
|
| 139 |
|
| 140 |
-
|
| 141 |
|
|
|
|
|
|
|
| 142 |
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
```python
|
| 146 |
-
|
| 147 |
```
|
| 148 |
|
| 149 |
-
|
| 150 |
|
|
|
|
| 15 |
field definitions for server metadata, authentication, and execution parameters.
|
| 16 |
|
| 17 |
Example configuration:
|
| 18 |
+
```json
|
| 19 |
+
{
|
| 20 |
+
"mcpServers": {
|
| 21 |
+
"my-server": {
|
| 22 |
+
"command": "npx",
|
| 23 |
+
"args": ["-y", "@my/mcp-server"],
|
| 24 |
+
"env": {"API_KEY": "secret"},
|
| 25 |
+
"timeout": 30000,
|
| 26 |
+
"description": "My MCP server"
|
| 27 |
}
|
| 28 |
}
|
| 29 |
+
}
|
| 30 |
+
```
|
| 31 |
|
| 32 |
|
| 33 |
## Functions
|
| 34 |
|
| 35 |
+
### `infer_transport_type_from_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L57" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 36 |
|
| 37 |
```python
|
| 38 |
infer_transport_type_from_url(url: str | AnyUrl) -> Literal['http', 'sse']
|
|
|
|
| 42 |
Infer the appropriate transport type from the given URL.
|
| 43 |
|
| 44 |
|
| 45 |
+
### `update_config_file` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L293" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 46 |
|
| 47 |
```python
|
| 48 |
+
update_config_file(file_path: Path, server_name: str, server_config: CanonicalMCPServerTypes) -> None
|
| 49 |
```
|
| 50 |
|
| 51 |
|
| 52 |
+
Update an MCP configuration file from a server object, preserving existing fields.
|
| 53 |
+
|
| 54 |
+
This is used for updating the mcpServer configurations of third-party tools so we do not
|
| 55 |
+
worry about transforming server objects here.
|
| 56 |
|
| 57 |
|
| 58 |
## Classes
|
| 59 |
|
| 60 |
+
### `StdioMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 61 |
|
| 62 |
|
| 63 |
MCP server configuration for stdio transport.
|
|
|
|
| 67 |
|
| 68 |
**Methods:**
|
| 69 |
|
| 70 |
+
#### `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>
|
| 71 |
|
| 72 |
```python
|
| 73 |
to_transport(self) -> StdioTransport
|
| 74 |
```
|
| 75 |
|
| 76 |
+
### `TransformingStdioMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L151" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
A Stdio server with tool transforms.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
### `RemoteMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L155" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 83 |
|
| 84 |
|
| 85 |
MCP server configuration for HTTP/SSE transport.
|
|
|
|
| 89 |
|
| 90 |
**Methods:**
|
| 91 |
|
| 92 |
+
#### `to_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L191" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 93 |
|
| 94 |
```python
|
| 95 |
to_transport(self) -> StreamableHttpTransport | SSETransport
|
| 96 |
```
|
| 97 |
|
| 98 |
+
### `TransformingRemoteMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L216" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 99 |
|
| 100 |
|
| 101 |
+
A Remote server with tool transforms.
|
| 102 |
|
| 103 |
+
|
| 104 |
+
### `MCPConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L227" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
A configuration object for MCP Servers that conforms to the canonical MCP configuration format
|
| 108 |
+
while adding additional fields for enabling FastMCP-specific features like tool transformations
|
| 109 |
+
and filtering by tags.
|
| 110 |
+
|
| 111 |
+
For an MCPConfig that is strictly canonical, see the `CanonicalMCPConfig` class.
|
| 112 |
|
| 113 |
|
| 114 |
**Methods:**
|
| 115 |
|
| 116 |
+
#### `validate_mcp_servers` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L240" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 117 |
+
|
| 118 |
+
```python
|
| 119 |
+
validate_mcp_servers(self, info: ValidationInfo) -> dict[str, Any]
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
Validate the MCP servers.
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
#### `add_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L250" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 126 |
+
|
| 127 |
+
```python
|
| 128 |
+
add_server(self, name: str, server: MCPServerTypes) -> None
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Add or update a server in the configuration.
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
#### `from_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L255" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 135 |
|
| 136 |
```python
|
| 137 |
+
from_dict(cls, config: dict[str, Any]) -> Self
|
| 138 |
```
|
| 139 |
|
| 140 |
Parse MCP configuration from dictionary format.
|
| 141 |
|
| 142 |
|
| 143 |
+
#### `to_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L259" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 144 |
|
| 145 |
```python
|
| 146 |
to_dict(self) -> dict[str, Any]
|
|
|
|
| 149 |
Convert MCPConfig to dictionary format, preserving all fields.
|
| 150 |
|
| 151 |
|
| 152 |
+
#### `write_to_file` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L263" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 153 |
|
| 154 |
```python
|
| 155 |
write_to_file(self, file_path: Path) -> None
|
|
|
|
| 158 |
Write configuration to JSON file.
|
| 159 |
|
| 160 |
|
| 161 |
+
#### `from_file` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L269" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 162 |
|
| 163 |
```python
|
| 164 |
+
from_file(cls, file_path: Path) -> Self
|
| 165 |
```
|
| 166 |
|
| 167 |
Load configuration from JSON file.
|
| 168 |
|
| 169 |
|
| 170 |
+
### `CanonicalMCPConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L278" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 171 |
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
Canonical MCP configuration format.
|
| 174 |
|
| 175 |
+
This defines the standard configuration format for Model Context Protocol servers.
|
| 176 |
+
The format is designed to be client-agnostic and extensible for future use cases.
|
| 177 |
|
| 178 |
+
|
| 179 |
+
**Methods:**
|
| 180 |
+
|
| 181 |
+
#### `add_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/mcp_config.py#L288" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 182 |
|
| 183 |
```python
|
| 184 |
+
add_server(self, name: str, server: CanonicalMCPServerTypes) -> None
|
| 185 |
```
|
| 186 |
|
| 187 |
+
Add or update a server in the configuration.
|
| 188 |
|
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.
|
|
@@ -44,16 +44,26 @@ def my_tool(x: int, ctx: Context) -> str:
|
|
| 44 |
request_id = ctx.request_id
|
| 45 |
client_id = ctx.client_id
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return str(x)
|
| 48 |
```
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
The context parameter name can be anything as long as it's annotated with Context.
|
| 51 |
The context is optional - tools that don't need it can omit the parameter.
|
| 52 |
|
| 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 +74,7 @@ Access to the underlying request context.
|
|
| 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#
|
| 68 |
|
| 69 |
```python
|
| 70 |
report_progress(self, progress: float, total: float | None = None, message: str | None = None) -> None
|
|
@@ -77,7 +87,7 @@ Report progress for the current operation.
|
|
| 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#
|
| 81 |
|
| 82 |
```python
|
| 83 |
read_resource(self, uri: str | AnyUrl) -> list[ReadResourceContents]
|
|
@@ -92,7 +102,7 @@ Read a resource by URI.
|
|
| 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#
|
| 96 |
|
| 97 |
```python
|
| 98 |
log(self, message: str, level: LoggingLevel | None = None, logger_name: str | None = None) -> None
|
|
@@ -107,7 +117,7 @@ Send a log message to the client.
|
|
| 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#
|
| 111 |
|
| 112 |
```python
|
| 113 |
client_id(self) -> str | None
|
|
@@ -116,7 +126,7 @@ 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#
|
| 120 |
|
| 121 |
```python
|
| 122 |
request_id(self) -> str
|
|
@@ -125,7 +135,7 @@ 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#
|
| 129 |
|
| 130 |
```python
|
| 131 |
session_id(self) -> str | None
|
|
@@ -142,7 +152,7 @@ the same client session.
|
|
| 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#
|
| 146 |
|
| 147 |
```python
|
| 148 |
session(self) -> ServerSession
|
|
@@ -151,7 +161,7 @@ session(self) -> ServerSession
|
|
| 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#
|
| 155 |
|
| 156 |
```python
|
| 157 |
debug(self, message: str, logger_name: str | None = None) -> None
|
|
@@ -160,7 +170,7 @@ debug(self, message: str, logger_name: str | None = None) -> None
|
|
| 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#
|
| 164 |
|
| 165 |
```python
|
| 166 |
info(self, message: str, logger_name: str | None = None) -> None
|
|
@@ -169,7 +179,7 @@ info(self, message: str, logger_name: str | None = None) -> None
|
|
| 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#
|
| 173 |
|
| 174 |
```python
|
| 175 |
warning(self, message: str, logger_name: str | None = None) -> None
|
|
@@ -178,7 +188,7 @@ warning(self, message: str, logger_name: str | None = None) -> None
|
|
| 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#
|
| 182 |
|
| 183 |
```python
|
| 184 |
error(self, message: str, logger_name: str | None = None) -> None
|
|
@@ -187,7 +197,7 @@ error(self, message: str, logger_name: str | None = None) -> None
|
|
| 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#
|
| 191 |
|
| 192 |
```python
|
| 193 |
list_roots(self) -> list[Root]
|
|
@@ -196,7 +206,7 @@ list_roots(self) -> list[Root]
|
|
| 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#
|
| 200 |
|
| 201 |
```python
|
| 202 |
send_tool_list_changed(self) -> None
|
|
@@ -205,7 +215,7 @@ send_tool_list_changed(self) -> None
|
|
| 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#
|
| 209 |
|
| 210 |
```python
|
| 211 |
send_resource_list_changed(self) -> None
|
|
@@ -214,7 +224,7 @@ send_resource_list_changed(self) -> None
|
|
| 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#
|
| 218 |
|
| 219 |
```python
|
| 220 |
send_prompt_list_changed(self) -> None
|
|
@@ -223,7 +233,7 @@ send_prompt_list_changed(self) -> None
|
|
| 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#
|
| 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
|
|
@@ -236,25 +246,25 @@ 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#
|
| 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#
|
| 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#
|
| 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#
|
| 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
|
|
@@ -283,7 +293,7 @@ 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#
|
| 287 |
|
| 288 |
```python
|
| 289 |
get_http_request(self) -> Request
|
|
@@ -291,3 +301,21 @@ get_http_request(self) -> Request
|
|
| 291 |
|
| 292 |
Get the active starlette request.
|
| 293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `set_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L51" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 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#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 19 |
|
| 20 |
|
| 21 |
Context object providing access to MCP capabilities.
|
|
|
|
| 44 |
request_id = ctx.request_id
|
| 45 |
client_id = ctx.client_id
|
| 46 |
|
| 47 |
+
# Manage state across the request
|
| 48 |
+
ctx.set_state_value("key", "value")
|
| 49 |
+
value = ctx.get_state_value("key")
|
| 50 |
+
|
| 51 |
return str(x)
|
| 52 |
```
|
| 53 |
|
| 54 |
+
State Management:
|
| 55 |
+
Context objects maintain a state dictionary that can be used to store and share
|
| 56 |
+
data across middleware and tool calls within a request. When a new context
|
| 57 |
+
is created (nested contexts), it inherits a copy of its parent's state, ensuring
|
| 58 |
+
that modifications in child contexts don't affect parent contexts.
|
| 59 |
+
|
| 60 |
The context parameter name can be anything as long as it's annotated with Context.
|
| 61 |
The context is optional - tools that don't need it can omit the parameter.
|
| 62 |
|
| 63 |
|
| 64 |
**Methods:**
|
| 65 |
|
| 66 |
+
#### `request_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L133" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 67 |
|
| 68 |
```python
|
| 69 |
request_context(self) -> RequestContext
|
|
|
|
| 74 |
If called outside of a request context, this will raise a ValueError.
|
| 75 |
|
| 76 |
|
| 77 |
+
#### `report_progress` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L143" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 78 |
|
| 79 |
```python
|
| 80 |
report_progress(self, progress: float, total: float | None = None, message: str | None = None) -> None
|
|
|
|
| 87 |
- `total`: Optional total value e.g. 100
|
| 88 |
|
| 89 |
|
| 90 |
+
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L170" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 91 |
|
| 92 |
```python
|
| 93 |
read_resource(self, uri: str | AnyUrl) -> list[ReadResourceContents]
|
|
|
|
| 102 |
- The resource content as either text or bytes
|
| 103 |
|
| 104 |
|
| 105 |
+
#### `log` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L182" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 106 |
|
| 107 |
```python
|
| 108 |
log(self, message: str, level: LoggingLevel | None = None, logger_name: str | None = None) -> None
|
|
|
|
| 117 |
- `logger_name`: Optional logger name
|
| 118 |
|
| 119 |
|
| 120 |
+
#### `client_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L206" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 121 |
|
| 122 |
```python
|
| 123 |
client_id(self) -> str | None
|
|
|
|
| 126 |
Get the client ID if available.
|
| 127 |
|
| 128 |
|
| 129 |
+
#### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L215" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 130 |
|
| 131 |
```python
|
| 132 |
request_id(self) -> str
|
|
|
|
| 135 |
Get the unique ID for this request.
|
| 136 |
|
| 137 |
|
| 138 |
+
#### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L220" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 139 |
|
| 140 |
```python
|
| 141 |
session_id(self) -> str | None
|
|
|
|
| 152 |
- for stdio and in-memory transports which don't use session IDs.
|
| 153 |
|
| 154 |
|
| 155 |
+
#### `session` <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>
|
| 156 |
|
| 157 |
```python
|
| 158 |
session(self) -> ServerSession
|
|
|
|
| 161 |
Access to the underlying session for advanced usage.
|
| 162 |
|
| 163 |
|
| 164 |
+
#### `debug` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L256" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 165 |
|
| 166 |
```python
|
| 167 |
debug(self, message: str, logger_name: str | None = None) -> None
|
|
|
|
| 170 |
Send a debug log message.
|
| 171 |
|
| 172 |
|
| 173 |
+
#### `info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L260" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 174 |
|
| 175 |
```python
|
| 176 |
info(self, message: str, logger_name: str | None = None) -> None
|
|
|
|
| 179 |
Send an info log message.
|
| 180 |
|
| 181 |
|
| 182 |
+
#### `warning` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L264" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 183 |
|
| 184 |
```python
|
| 185 |
warning(self, message: str, logger_name: str | None = None) -> None
|
|
|
|
| 188 |
Send a warning log message.
|
| 189 |
|
| 190 |
|
| 191 |
+
#### `error` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L268" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 192 |
|
| 193 |
```python
|
| 194 |
error(self, message: str, logger_name: str | None = None) -> None
|
|
|
|
| 197 |
Send an error log message.
|
| 198 |
|
| 199 |
|
| 200 |
+
#### `list_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L272" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 201 |
|
| 202 |
```python
|
| 203 |
list_roots(self) -> list[Root]
|
|
|
|
| 206 |
List the roots available to the server, as indicated by the client.
|
| 207 |
|
| 208 |
|
| 209 |
+
#### `send_tool_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L277" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 210 |
|
| 211 |
```python
|
| 212 |
send_tool_list_changed(self) -> None
|
|
|
|
| 215 |
Send a tool list changed notification to the client.
|
| 216 |
|
| 217 |
|
| 218 |
+
#### `send_resource_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L281" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 219 |
|
| 220 |
```python
|
| 221 |
send_resource_list_changed(self) -> None
|
|
|
|
| 224 |
Send a resource list changed notification to the client.
|
| 225 |
|
| 226 |
|
| 227 |
+
#### `send_prompt_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L285" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 228 |
|
| 229 |
```python
|
| 230 |
send_prompt_list_changed(self) -> None
|
|
|
|
| 233 |
Send a prompt list changed notification to the client.
|
| 234 |
|
| 235 |
|
| 236 |
+
#### `sample` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L289" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 237 |
|
| 238 |
```python
|
| 239 |
sample(self, messages: str | list[str | SamplingMessage], system_prompt: str | None = None, include_context: IncludeContext | None = None, temperature: float | None = None, max_tokens: int | None = None, model_preferences: ModelPreferences | str | list[str] | None = None) -> ContentBlock
|
|
|
|
| 246 |
or the request will error.
|
| 247 |
|
| 248 |
|
| 249 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L336" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 250 |
|
| 251 |
```python
|
| 252 |
elicit(self, message: str, response_type: None) -> AcceptedElicitation[dict[str, Any]] | DeclinedElicitation | CancelledElicitation
|
| 253 |
```
|
| 254 |
|
| 255 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L348" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 256 |
|
| 257 |
```python
|
| 258 |
elicit(self, message: str, response_type: type[T]) -> AcceptedElicitation[T] | DeclinedElicitation | CancelledElicitation
|
| 259 |
```
|
| 260 |
|
| 261 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L358" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 262 |
|
| 263 |
```python
|
| 264 |
elicit(self, message: str, response_type: list[str]) -> AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
| 265 |
```
|
| 266 |
|
| 267 |
+
#### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L367" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 268 |
|
| 269 |
```python
|
| 270 |
elicit(self, message: str, response_type: type[T] | list[str] | None = None) -> AcceptedElicitation[T] | AcceptedElicitation[dict[str, Any]] | AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
|
|
|
|
| 293 |
object schema with a single "value" field will be generated.
|
| 294 |
|
| 295 |
|
| 296 |
+
#### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L460" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 297 |
|
| 298 |
```python
|
| 299 |
get_http_request(self) -> Request
|
|
|
|
| 301 |
|
| 302 |
Get the active starlette request.
|
| 303 |
|
| 304 |
+
|
| 305 |
+
#### `set_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L475" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 306 |
+
|
| 307 |
+
```python
|
| 308 |
+
set_state(self, key: str, value: Any) -> None
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
Set a value in the context state.
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
#### `get_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L479" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 315 |
+
|
| 316 |
+
```python
|
| 317 |
+
get_state(self, key: str) -> Any
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
Get a value from the context state. Returns None if the key is not found.
|
| 321 |
+
|
docs/python-sdk/fastmcp-server-middleware.mdx
DELETED
|
@@ -1,56 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: middleware
|
| 3 |
-
sidebarTitle: middleware
|
| 4 |
-
---
|
| 5 |
-
|
| 6 |
-
# `fastmcp.server.middleware`
|
| 7 |
-
|
| 8 |
-
## Functions
|
| 9 |
-
|
| 10 |
-
### `make_middleware_wrapper`
|
| 11 |
-
|
| 12 |
-
```python
|
| 13 |
-
make_middleware_wrapper(middleware: Middleware, call_next: CallNext[T, R]) -> CallNext[T, R]
|
| 14 |
-
```
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
Create a wrapper that applies a single middleware to a context. The
|
| 18 |
-
closure bakes in the middleware and call_next function, so it can be
|
| 19 |
-
passed to other functions that expect a call_next function.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
## Classes
|
| 23 |
-
|
| 24 |
-
### `CallNext`
|
| 25 |
-
|
| 26 |
-
### `CallToolResult`
|
| 27 |
-
|
| 28 |
-
### `ListToolsResult`
|
| 29 |
-
|
| 30 |
-
### `ListResourcesResult`
|
| 31 |
-
|
| 32 |
-
### `ListResourceTemplatesResult`
|
| 33 |
-
|
| 34 |
-
### `ListPromptsResult`
|
| 35 |
-
|
| 36 |
-
### `ServerResultProtocol`
|
| 37 |
-
|
| 38 |
-
### `MiddlewareContext`
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
Unified context for all middleware operations.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
**Methods:**
|
| 45 |
-
|
| 46 |
-
#### `copy`
|
| 47 |
-
|
| 48 |
-
```python
|
| 49 |
-
copy(self, **kwargs: Any) -> MiddlewareContext[T]
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
### `Middleware`
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
Base class for FastMCP middleware with dispatching hooks.
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/python-sdk/fastmcp-server-proxy.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: proxy
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `default_proxy_roots_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_proxy_roots_handler(context: RequestContext[ClientSession, LifespanContextT]) -> RootsList
|
|
@@ -19,7 +19,7 @@ A handler that forwards the list roots request from the remote server to the pro
|
|
| 19 |
|
| 20 |
## Classes
|
| 21 |
|
| 22 |
-
### `ProxyToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 23 |
|
| 24 |
|
| 25 |
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
|
@@ -27,7 +27,7 @@ A ToolManager that sources its tools from a remote client in addition to local a
|
|
| 27 |
|
| 28 |
**Methods:**
|
| 29 |
|
| 30 |
-
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 31 |
|
| 32 |
```python
|
| 33 |
get_tools(self) -> dict[str, Tool]
|
|
@@ -36,7 +36,7 @@ get_tools(self) -> dict[str, Tool]
|
|
| 36 |
Gets the unfiltered tool inventory including local, mounted, and proxy tools.
|
| 37 |
|
| 38 |
|
| 39 |
-
#### `list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 40 |
|
| 41 |
```python
|
| 42 |
list_tools(self) -> list[Tool]
|
|
@@ -45,7 +45,7 @@ list_tools(self) -> list[Tool]
|
|
| 45 |
Gets the filtered list of tools including local, mounted, and proxy tools.
|
| 46 |
|
| 47 |
|
| 48 |
-
#### `call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 49 |
|
| 50 |
```python
|
| 51 |
call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -54,7 +54,7 @@ call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
|
| 54 |
Calls a tool, trying local/mounted first, then proxy if not found.
|
| 55 |
|
| 56 |
|
| 57 |
-
### `ProxyResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 58 |
|
| 59 |
|
| 60 |
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
|
@@ -62,7 +62,7 @@ A ResourceManager that sources its resources from a remote client in addition to
|
|
| 62 |
|
| 63 |
**Methods:**
|
| 64 |
|
| 65 |
-
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 66 |
|
| 67 |
```python
|
| 68 |
get_resources(self) -> dict[str, Resource]
|
|
@@ -71,7 +71,7 @@ get_resources(self) -> dict[str, Resource]
|
|
| 71 |
Gets the unfiltered resource inventory including local, mounted, and proxy resources.
|
| 72 |
|
| 73 |
|
| 74 |
-
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 75 |
|
| 76 |
```python
|
| 77 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
@@ -80,7 +80,7 @@ get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
| 80 |
Gets the unfiltered template inventory including local, mounted, and proxy templates.
|
| 81 |
|
| 82 |
|
| 83 |
-
#### `list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 84 |
|
| 85 |
```python
|
| 86 |
list_resources(self) -> list[Resource]
|
|
@@ -89,7 +89,7 @@ list_resources(self) -> list[Resource]
|
|
| 89 |
Gets the filtered list of resources including local, mounted, and proxy resources.
|
| 90 |
|
| 91 |
|
| 92 |
-
#### `list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 93 |
|
| 94 |
```python
|
| 95 |
list_resource_templates(self) -> list[ResourceTemplate]
|
|
@@ -98,7 +98,7 @@ list_resource_templates(self) -> list[ResourceTemplate]
|
|
| 98 |
Gets the filtered list of templates including local, mounted, and proxy templates.
|
| 99 |
|
| 100 |
|
| 101 |
-
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 102 |
|
| 103 |
```python
|
| 104 |
read_resource(self, uri: AnyUrl | str) -> str | bytes
|
|
@@ -107,7 +107,7 @@ read_resource(self, uri: AnyUrl | str) -> str | bytes
|
|
| 107 |
Reads a resource, trying local/mounted first, then proxy if not found.
|
| 108 |
|
| 109 |
|
| 110 |
-
### `ProxyPromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 111 |
|
| 112 |
|
| 113 |
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
|
@@ -115,7 +115,7 @@ A PromptManager that sources its prompts from a remote client in addition to loc
|
|
| 115 |
|
| 116 |
**Methods:**
|
| 117 |
|
| 118 |
-
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 119 |
|
| 120 |
```python
|
| 121 |
get_prompts(self) -> dict[str, Prompt]
|
|
@@ -124,7 +124,7 @@ get_prompts(self) -> dict[str, Prompt]
|
|
| 124 |
Gets the unfiltered prompt inventory including local, mounted, and proxy prompts.
|
| 125 |
|
| 126 |
|
| 127 |
-
#### `list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 128 |
|
| 129 |
```python
|
| 130 |
list_prompts(self) -> list[Prompt]
|
|
@@ -133,7 +133,7 @@ list_prompts(self) -> list[Prompt]
|
|
| 133 |
Gets the filtered list of prompts including local, mounted, and proxy prompts.
|
| 134 |
|
| 135 |
|
| 136 |
-
#### `render_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 137 |
|
| 138 |
```python
|
| 139 |
render_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> GetPromptResult
|
|
@@ -142,7 +142,7 @@ render_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> GetPr
|
|
| 142 |
Renders a prompt, trying local/mounted first, then proxy if not found.
|
| 143 |
|
| 144 |
|
| 145 |
-
### `ProxyTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 146 |
|
| 147 |
|
| 148 |
A Tool that represents and executes a tool on a remote server.
|
|
@@ -150,7 +150,7 @@ A Tool that represents and executes a tool on a remote server.
|
|
| 150 |
|
| 151 |
**Methods:**
|
| 152 |
|
| 153 |
-
#### `from_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 154 |
|
| 155 |
```python
|
| 156 |
from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
@@ -159,7 +159,7 @@ from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
| 159 |
Factory method to create a ProxyTool from a raw MCP tool schema.
|
| 160 |
|
| 161 |
|
| 162 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 163 |
|
| 164 |
```python
|
| 165 |
run(self, arguments: dict[str, Any], context: Context | None = None) -> ToolResult
|
|
@@ -168,7 +168,7 @@ run(self, arguments: dict[str, Any], context: Context | None = None) -> ToolResu
|
|
| 168 |
Executes the tool by making a call through the client.
|
| 169 |
|
| 170 |
|
| 171 |
-
### `ProxyResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 172 |
|
| 173 |
|
| 174 |
A Resource that represents and reads a resource from a remote server.
|
|
@@ -176,7 +176,7 @@ A Resource that represents and reads a resource from a remote server.
|
|
| 176 |
|
| 177 |
**Methods:**
|
| 178 |
|
| 179 |
-
#### `from_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 180 |
|
| 181 |
```python
|
| 182 |
from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> ProxyResource
|
|
@@ -185,7 +185,7 @@ from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> Prox
|
|
| 185 |
Factory method to create a ProxyResource from a raw MCP resource schema.
|
| 186 |
|
| 187 |
|
| 188 |
-
#### `read` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 189 |
|
| 190 |
```python
|
| 191 |
read(self) -> str | bytes
|
|
@@ -194,7 +194,7 @@ read(self) -> str | bytes
|
|
| 194 |
Read the resource content from the remote server.
|
| 195 |
|
| 196 |
|
| 197 |
-
### `ProxyTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 198 |
|
| 199 |
|
| 200 |
A ResourceTemplate that represents and creates resources from a remote server template.
|
|
@@ -202,7 +202,7 @@ A ResourceTemplate that represents and creates resources from a remote server te
|
|
| 202 |
|
| 203 |
**Methods:**
|
| 204 |
|
| 205 |
-
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 206 |
|
| 207 |
```python
|
| 208 |
from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate) -> ProxyTemplate
|
|
@@ -211,7 +211,7 @@ from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate)
|
|
| 211 |
Factory method to create a ProxyTemplate from a raw MCP template schema.
|
| 212 |
|
| 213 |
|
| 214 |
-
#### `create_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 215 |
|
| 216 |
```python
|
| 217 |
create_resource(self, uri: str, params: dict[str, Any], context: Context | None = None) -> ProxyResource
|
|
@@ -220,7 +220,7 @@ create_resource(self, uri: str, params: dict[str, Any], context: Context | None
|
|
| 220 |
Create a resource from the template by calling the remote server.
|
| 221 |
|
| 222 |
|
| 223 |
-
### `ProxyPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 224 |
|
| 225 |
|
| 226 |
A Prompt that represents and renders a prompt from a remote server.
|
|
@@ -228,7 +228,7 @@ A Prompt that represents and renders a prompt from a remote server.
|
|
| 228 |
|
| 229 |
**Methods:**
|
| 230 |
|
| 231 |
-
#### `from_mcp_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 232 |
|
| 233 |
```python
|
| 234 |
from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPrompt
|
|
@@ -237,7 +237,7 @@ from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPromp
|
|
| 237 |
Factory method to create a ProxyPrompt from a raw MCP prompt schema.
|
| 238 |
|
| 239 |
|
| 240 |
-
#### `render` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 241 |
|
| 242 |
```python
|
| 243 |
render(self, arguments: dict[str, Any]) -> list[PromptMessage]
|
|
@@ -246,14 +246,14 @@ render(self, arguments: dict[str, Any]) -> list[PromptMessage]
|
|
| 246 |
Render the prompt by making a call through the client.
|
| 247 |
|
| 248 |
|
| 249 |
-
### `FastMCPProxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 250 |
|
| 251 |
|
| 252 |
A FastMCP server that acts as a proxy to a remote MCP-compliant server.
|
| 253 |
It uses specialized managers that fulfill requests via a client factory.
|
| 254 |
|
| 255 |
|
| 256 |
-
### `ProxyClient` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 257 |
|
| 258 |
|
| 259 |
A proxy client that forwards advanced interactions between a remote MCP server and the proxy's connected clients.
|
|
@@ -262,7 +262,7 @@ Supports forwarding roots, sampling, elicitation, logging, and progress.
|
|
| 262 |
|
| 263 |
**Methods:**
|
| 264 |
|
| 265 |
-
#### `default_sampling_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 266 |
|
| 267 |
```python
|
| 268 |
default_sampling_handler(cls, messages: list[mcp.types.SamplingMessage], params: mcp.types.CreateMessageRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> mcp.types.CreateMessageResult
|
|
@@ -271,7 +271,7 @@ default_sampling_handler(cls, messages: list[mcp.types.SamplingMessage], params:
|
|
| 271 |
A handler that forwards the sampling request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 272 |
|
| 273 |
|
| 274 |
-
#### `default_elicitation_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 275 |
|
| 276 |
```python
|
| 277 |
default_elicitation_handler(cls, message: str, response_type: type, params: mcp.types.ElicitRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> ElicitResult
|
|
@@ -280,7 +280,7 @@ default_elicitation_handler(cls, message: str, response_type: type, params: mcp.
|
|
| 280 |
A handler that forwards the elicitation request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 281 |
|
| 282 |
|
| 283 |
-
#### `default_log_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 284 |
|
| 285 |
```python
|
| 286 |
default_log_handler(cls, message: LogMessage) -> None
|
|
@@ -289,7 +289,7 @@ default_log_handler(cls, message: LogMessage) -> None
|
|
| 289 |
A handler that forwards the log notification from the remote server to the proxy's connected clients.
|
| 290 |
|
| 291 |
|
| 292 |
-
#### `default_progress_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#
|
| 293 |
|
| 294 |
```python
|
| 295 |
default_progress_handler(cls, progress: float, total: float | None, message: str | None) -> None
|
|
@@ -297,3 +297,28 @@ default_progress_handler(cls, progress: float, total: float | None, message: str
|
|
| 297 |
|
| 298 |
A handler that forwards the progress notification from the remote server to the proxy's connected clients.
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_proxy_roots_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L491" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_proxy_roots_handler(context: RequestContext[ClientSession, LifespanContextT]) -> RootsList
|
|
|
|
| 19 |
|
| 20 |
## Classes
|
| 21 |
|
| 22 |
+
### `ProxyToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L51" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 23 |
|
| 24 |
|
| 25 |
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
|
|
|
| 27 |
|
| 28 |
**Methods:**
|
| 29 |
|
| 30 |
+
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L58" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 31 |
|
| 32 |
```python
|
| 33 |
get_tools(self) -> dict[str, Tool]
|
|
|
|
| 36 |
Gets the unfiltered tool inventory including local, mounted, and proxy tools.
|
| 37 |
|
| 38 |
|
| 39 |
+
#### `list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L84" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
list_tools(self) -> list[Tool]
|
|
|
|
| 45 |
Gets the filtered list of tools including local, mounted, and proxy tools.
|
| 46 |
|
| 47 |
|
| 48 |
+
#### `call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L89" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
|
| 50 |
```python
|
| 51 |
call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 54 |
Calls a tool, trying local/mounted first, then proxy if not found.
|
| 55 |
|
| 56 |
|
| 57 |
+
### `ProxyResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L105" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 58 |
|
| 59 |
|
| 60 |
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
|
|
|
| 62 |
|
| 63 |
**Methods:**
|
| 64 |
|
| 65 |
+
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L112" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 66 |
|
| 67 |
```python
|
| 68 |
get_resources(self) -> dict[str, Resource]
|
|
|
|
| 71 |
Gets the unfiltered resource inventory including local, mounted, and proxy resources.
|
| 72 |
|
| 73 |
|
| 74 |
+
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L135" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 75 |
|
| 76 |
```python
|
| 77 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
|
|
| 80 |
Gets the unfiltered template inventory including local, mounted, and proxy templates.
|
| 81 |
|
| 82 |
|
| 83 |
+
#### `list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L158" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 84 |
|
| 85 |
```python
|
| 86 |
list_resources(self) -> list[Resource]
|
|
|
|
| 89 |
Gets the filtered list of resources including local, mounted, and proxy resources.
|
| 90 |
|
| 91 |
|
| 92 |
+
#### `list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L163" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 93 |
|
| 94 |
```python
|
| 95 |
list_resource_templates(self) -> list[ResourceTemplate]
|
|
|
|
| 98 |
Gets the filtered list of templates including local, mounted, and proxy templates.
|
| 99 |
|
| 100 |
|
| 101 |
+
#### `read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L168" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 102 |
|
| 103 |
```python
|
| 104 |
read_resource(self, uri: AnyUrl | str) -> str | bytes
|
|
|
|
| 107 |
Reads a resource, trying local/mounted first, then proxy if not found.
|
| 108 |
|
| 109 |
|
| 110 |
+
### `ProxyPromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L186" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 111 |
|
| 112 |
|
| 113 |
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
|
|
|
| 115 |
|
| 116 |
**Methods:**
|
| 117 |
|
| 118 |
+
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L193" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 119 |
|
| 120 |
```python
|
| 121 |
get_prompts(self) -> dict[str, Prompt]
|
|
|
|
| 124 |
Gets the unfiltered prompt inventory including local, mounted, and proxy prompts.
|
| 125 |
|
| 126 |
|
| 127 |
+
#### `list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L216" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
|
| 129 |
```python
|
| 130 |
list_prompts(self) -> list[Prompt]
|
|
|
|
| 133 |
Gets the filtered list of prompts including local, mounted, and proxy prompts.
|
| 134 |
|
| 135 |
|
| 136 |
+
#### `render_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L221" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 137 |
|
| 138 |
```python
|
| 139 |
render_prompt(self, name: str, arguments: dict[str, Any] | None = None) -> GetPromptResult
|
|
|
|
| 142 |
Renders a prompt, trying local/mounted first, then proxy if not found.
|
| 143 |
|
| 144 |
|
| 145 |
+
### `ProxyTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L238" 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#L248" 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#L260" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 163 |
|
| 164 |
```python
|
| 165 |
run(self, arguments: dict[str, Any], context: Context | None = None) -> ToolResult
|
|
|
|
| 168 |
Executes the tool by making a call through the client.
|
| 169 |
|
| 170 |
|
| 171 |
+
### `ProxyResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L279" 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#L299" 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#L314" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 189 |
|
| 190 |
```python
|
| 191 |
read(self) -> str | bytes
|
|
|
|
| 194 |
Read the resource content from the remote server.
|
| 195 |
|
| 196 |
|
| 197 |
+
### `ProxyTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L329" 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#L339" 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#L353" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 215 |
|
| 216 |
```python
|
| 217 |
create_resource(self, uri: str, params: dict[str, Any], context: Context | None = None) -> ProxyResource
|
|
|
|
| 220 |
Create a resource from the template by calling the remote server.
|
| 221 |
|
| 222 |
|
| 223 |
+
### `ProxyPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L386" 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#L398" 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#L418" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 241 |
|
| 242 |
```python
|
| 243 |
render(self, arguments: dict[str, Any]) -> list[PromptMessage]
|
|
|
|
| 246 |
Render the prompt by making a call through the client.
|
| 247 |
|
| 248 |
|
| 249 |
+
### `FastMCPProxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L425" 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#L501" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 257 |
|
| 258 |
|
| 259 |
A proxy client that forwards advanced interactions between a remote MCP server and the proxy's connected clients.
|
|
|
|
| 262 |
|
| 263 |
**Methods:**
|
| 264 |
|
| 265 |
+
#### `default_sampling_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L532" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 266 |
|
| 267 |
```python
|
| 268 |
default_sampling_handler(cls, messages: list[mcp.types.SamplingMessage], params: mcp.types.CreateMessageRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> mcp.types.CreateMessageResult
|
|
|
|
| 271 |
A handler that forwards the sampling request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 272 |
|
| 273 |
|
| 274 |
+
#### `default_elicitation_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L558" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 275 |
|
| 276 |
```python
|
| 277 |
default_elicitation_handler(cls, message: str, response_type: type, params: mcp.types.ElicitRequestParams, context: RequestContext[ClientSession, LifespanContextT]) -> ElicitResult
|
|
|
|
| 280 |
A handler that forwards the elicitation request from the remote server to the proxy's connected clients and relays the response back to the remote server.
|
| 281 |
|
| 282 |
|
| 283 |
+
#### `default_log_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L577" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 284 |
|
| 285 |
```python
|
| 286 |
default_log_handler(cls, message: LogMessage) -> None
|
|
|
|
| 289 |
A handler that forwards the log notification from the remote server to the proxy's connected clients.
|
| 290 |
|
| 291 |
|
| 292 |
+
#### `default_progress_handler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L585" 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
|
|
|
|
| 297 |
|
| 298 |
A handler that forwards the progress notification from the remote server to the proxy's connected clients.
|
| 299 |
|
| 300 |
+
|
| 301 |
+
### `StatefulProxyClient` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L598" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
A proxy client that provides a stateful client factory for the proxy server.
|
| 305 |
+
|
| 306 |
+
The stateful proxy client bound its copy to the server session.
|
| 307 |
+
And it will be disconnected when the session is exited.
|
| 308 |
+
|
| 309 |
+
This is useful to proxy a stateful mcp server such as the Playwright MCP server.
|
| 310 |
+
Note that it is essential to ensure that the proxy server itself is also stateful.
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
**Methods:**
|
| 314 |
+
|
| 315 |
+
#### `new_stateful` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L616" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 316 |
+
|
| 317 |
+
```python
|
| 318 |
+
new_stateful(self) -> Client[ClientTransportT]
|
| 319 |
+
```
|
| 320 |
+
|
| 321 |
+
Create a new stateful proxy client instance with the same configuration.
|
| 322 |
+
|
| 323 |
+
Use this method as the client factory for stateful proxy server.
|
| 324 |
+
|
docs/python-sdk/fastmcp-server-server.mdx
CHANGED
|
@@ -10,7 +10,7 @@ FastMCP - A more ergonomic interface for MCP servers.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `default_lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]
|
|
@@ -26,7 +26,7 @@ Default lifespan context manager that does nothing.
|
|
| 26 |
- An empty context object
|
| 27 |
|
| 28 |
|
| 29 |
-
### `add_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 30 |
|
| 31 |
```python
|
| 32 |
add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -64,7 +64,7 @@ add_resource_prefix("resource:///absolute/path", "prefix")
|
|
| 64 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 65 |
|
| 66 |
|
| 67 |
-
### `remove_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 68 |
|
| 69 |
```python
|
| 70 |
remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -103,7 +103,7 @@ remove_resource_prefix("resource://prefix//absolute/path", "prefix")
|
|
| 103 |
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 104 |
|
| 105 |
|
| 106 |
-
### `has_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 107 |
|
| 108 |
```python
|
| 109 |
has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> bool
|
|
@@ -143,29 +143,29 @@ False
|
|
| 143 |
|
| 144 |
## Classes
|
| 145 |
|
| 146 |
-
### `FastMCP` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 147 |
|
| 148 |
**Methods:**
|
| 149 |
|
| 150 |
-
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 151 |
|
| 152 |
```python
|
| 153 |
settings(self) -> Settings
|
| 154 |
```
|
| 155 |
|
| 156 |
-
#### `name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 157 |
|
| 158 |
```python
|
| 159 |
name(self) -> str
|
| 160 |
```
|
| 161 |
|
| 162 |
-
#### `instructions` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 163 |
|
| 164 |
```python
|
| 165 |
instructions(self) -> str | None
|
| 166 |
```
|
| 167 |
|
| 168 |
-
#### `run_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 169 |
|
| 170 |
```python
|
| 171 |
run_async(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
@@ -177,7 +177,7 @@ Run the FastMCP server asynchronously.
|
|
| 177 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 178 |
|
| 179 |
|
| 180 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 181 |
|
| 182 |
```python
|
| 183 |
run(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
@@ -189,13 +189,13 @@ Run the FastMCP server. Note this is a synchronous function.
|
|
| 189 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 190 |
|
| 191 |
|
| 192 |
-
#### `add_middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 193 |
|
| 194 |
```python
|
| 195 |
add_middleware(self, middleware: Middleware) -> None
|
| 196 |
```
|
| 197 |
|
| 198 |
-
#### `get_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 199 |
|
| 200 |
```python
|
| 201 |
get_tools(self) -> dict[str, Tool]
|
|
@@ -204,13 +204,13 @@ get_tools(self) -> dict[str, Tool]
|
|
| 204 |
Get all registered tools, indexed by registered key.
|
| 205 |
|
| 206 |
|
| 207 |
-
#### `get_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 208 |
|
| 209 |
```python
|
| 210 |
get_tool(self, key: str) -> Tool
|
| 211 |
```
|
| 212 |
|
| 213 |
-
#### `get_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 214 |
|
| 215 |
```python
|
| 216 |
get_resources(self) -> dict[str, Resource]
|
|
@@ -219,13 +219,13 @@ get_resources(self) -> dict[str, Resource]
|
|
| 219 |
Get all registered resources, indexed by registered key.
|
| 220 |
|
| 221 |
|
| 222 |
-
#### `get_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 223 |
|
| 224 |
```python
|
| 225 |
get_resource(self, key: str) -> Resource
|
| 226 |
```
|
| 227 |
|
| 228 |
-
#### `get_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 229 |
|
| 230 |
```python
|
| 231 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
@@ -234,7 +234,7 @@ get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
| 234 |
Get all registered resource templates, indexed by registered key.
|
| 235 |
|
| 236 |
|
| 237 |
-
#### `get_resource_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 238 |
|
| 239 |
```python
|
| 240 |
get_resource_template(self, key: str) -> ResourceTemplate
|
|
@@ -243,7 +243,7 @@ get_resource_template(self, key: str) -> ResourceTemplate
|
|
| 243 |
Get a registered resource template by key.
|
| 244 |
|
| 245 |
|
| 246 |
-
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 247 |
|
| 248 |
```python
|
| 249 |
get_prompts(self) -> dict[str, Prompt]
|
|
@@ -252,16 +252,16 @@ get_prompts(self) -> dict[str, Prompt]
|
|
| 252 |
List all available prompts.
|
| 253 |
|
| 254 |
|
| 255 |
-
#### `get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 256 |
|
| 257 |
```python
|
| 258 |
get_prompt(self, key: str) -> Prompt
|
| 259 |
```
|
| 260 |
|
| 261 |
-
#### `custom_route` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 262 |
|
| 263 |
```python
|
| 264 |
-
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True)
|
| 265 |
```
|
| 266 |
|
| 267 |
Decorator to register a custom HTTP route on the FastMCP server.
|
|
@@ -279,7 +279,7 @@ Starlette's reverse URL lookup feature)
|
|
| 279 |
- `include_in_schema`: Whether to include in OpenAPI schema, defaults to True
|
| 280 |
|
| 281 |
|
| 282 |
-
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 283 |
|
| 284 |
```python
|
| 285 |
add_tool(self, tool: Tool) -> Tool
|
|
@@ -297,7 +297,7 @@ with the Context type annotation. See the @tool decorator for examples.
|
|
| 297 |
- The tool instance that was added to the server.
|
| 298 |
|
| 299 |
|
| 300 |
-
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 301 |
|
| 302 |
```python
|
| 303 |
remove_tool(self, name: str) -> None
|
|
@@ -312,19 +312,37 @@ Remove a tool from the server.
|
|
| 312 |
- `NotFoundError`: If the tool is not found
|
| 313 |
|
| 314 |
|
| 315 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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#
|
| 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#
|
| 328 |
|
| 329 |
```python
|
| 330 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
@@ -379,7 +397,7 @@ server.tool(my_function, name="custom_name")
|
|
| 379 |
```
|
| 380 |
|
| 381 |
|
| 382 |
-
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 383 |
|
| 384 |
```python
|
| 385 |
add_resource(self, resource: Resource) -> Resource
|
|
@@ -394,7 +412,7 @@ Add a resource to the server.
|
|
| 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#
|
| 398 |
|
| 399 |
```python
|
| 400 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
|
@@ -409,7 +427,7 @@ Add a resource template to the server.
|
|
| 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#
|
| 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,7 +447,7 @@ has parameters, it will be registered as a template resource.
|
|
| 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#
|
| 433 |
|
| 434 |
```python
|
| 435 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
@@ -487,7 +505,7 @@ async def get_weather(city: str) -> str:
|
|
| 487 |
```
|
| 488 |
|
| 489 |
|
| 490 |
-
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 491 |
|
| 492 |
```python
|
| 493 |
add_prompt(self, prompt: Prompt) -> Prompt
|
|
@@ -502,19 +520,19 @@ Add a prompt to the server.
|
|
| 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#
|
| 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#
|
| 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#
|
| 518 |
|
| 519 |
```python
|
| 520 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
@@ -591,7 +609,7 @@ Decorator to register a prompt.
|
|
| 591 |
```
|
| 592 |
|
| 593 |
|
| 594 |
-
#### `run_stdio_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#
|
| 595 |
|
| 596 |
```python
|
| 597 |
run_stdio_async(self, show_banner: bool = True) -> None
|
|
@@ -600,7 +618,7 @@ run_stdio_async(self, show_banner: bool = True) -> None
|
|
| 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#
|
| 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
|
|
@@ -619,7 +637,7 @@ Run the server using HTTP transport.
|
|
| 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#
|
| 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
|
|
@@ -628,7 +646,7 @@ run_sse_async(self, host: str | None = None, port: int | None = None, log_level:
|
|
| 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#
|
| 632 |
|
| 633 |
```python
|
| 634 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -642,7 +660,7 @@ Create a Starlette app for the SSE server.
|
|
| 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#
|
| 646 |
|
| 647 |
```python
|
| 648 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -655,7 +673,7 @@ Create a Starlette app for the StreamableHTTP server.
|
|
| 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#
|
| 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,13 +690,13 @@ Create a Starlette app using the specified HTTP transport.
|
|
| 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#
|
| 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#
|
| 682 |
|
| 683 |
```python
|
| 684 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
@@ -732,7 +750,7 @@ automatically determined based on whether the server has a custom lifespan
|
|
| 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#
|
| 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
|
|
@@ -773,25 +791,25 @@ 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#
|
| 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
|
| 780 |
```
|
| 781 |
|
| 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#
|
| 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
|
| 789 |
```
|
| 790 |
|
| 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#
|
| 795 |
|
| 796 |
```python
|
| 797 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
@@ -805,7 +823,7 @@ instance or any value accepted as the `transport` argument of
|
|
| 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#
|
| 809 |
|
| 810 |
```python
|
| 811 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
@@ -814,4 +832,4 @@ from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPPr
|
|
| 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#
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `default_lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L97" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]
|
|
|
|
| 26 |
- An empty context object
|
| 27 |
|
| 28 |
|
| 29 |
+
### `add_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2114" 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#L2174" 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#L2241" 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#L128" 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#L281" 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#L292" 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#L296" 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#L299" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 169 |
|
| 170 |
```python
|
| 171 |
run_async(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
|
|
| 177 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 178 |
|
| 179 |
|
| 180 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L329" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 181 |
|
| 182 |
```python
|
| 183 |
run(self, transport: Transport | None = None, show_banner: bool = True, **transport_kwargs: Any) -> None
|
|
|
|
| 189 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 190 |
|
| 191 |
|
| 192 |
+
#### `add_middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L371" 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#L374" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 199 |
|
| 200 |
```python
|
| 201 |
get_tools(self) -> dict[str, Tool]
|
|
|
|
| 204 |
Get all registered tools, indexed by registered key.
|
| 205 |
|
| 206 |
|
| 207 |
+
#### `get_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L378" 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#L384" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 214 |
|
| 215 |
```python
|
| 216 |
get_resources(self) -> dict[str, Resource]
|
|
|
|
| 219 |
Get all registered resources, indexed by registered key.
|
| 220 |
|
| 221 |
|
| 222 |
+
#### `get_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L388" 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#L394" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 229 |
|
| 230 |
```python
|
| 231 |
get_resource_templates(self) -> dict[str, ResourceTemplate]
|
|
|
|
| 234 |
Get all registered resource templates, indexed by registered key.
|
| 235 |
|
| 236 |
|
| 237 |
+
#### `get_resource_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L398" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 238 |
|
| 239 |
```python
|
| 240 |
get_resource_template(self, key: str) -> ResourceTemplate
|
|
|
|
| 243 |
Get a registered resource template by key.
|
| 244 |
|
| 245 |
|
| 246 |
+
#### `get_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L405" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 247 |
|
| 248 |
```python
|
| 249 |
get_prompts(self) -> dict[str, Prompt]
|
|
|
|
| 252 |
List all available prompts.
|
| 253 |
|
| 254 |
|
| 255 |
+
#### `get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L411" 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#L417" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 262 |
|
| 263 |
```python
|
| 264 |
+
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True) -> Callable[[Callable[[Request], Awaitable[Response]]], Callable[[Request], Awaitable[Response]]]
|
| 265 |
```
|
| 266 |
|
| 267 |
Decorator to register a custom HTTP route on the FastMCP server.
|
|
|
|
| 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#L778" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 283 |
|
| 284 |
```python
|
| 285 |
add_tool(self, tool: Tool) -> Tool
|
|
|
|
| 297 |
- The tool instance that was added to the server.
|
| 298 |
|
| 299 |
|
| 300 |
+
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L804" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 301 |
|
| 302 |
```python
|
| 303 |
remove_tool(self, name: str) -> None
|
|
|
|
| 312 |
- `NotFoundError`: If the tool is not found
|
| 313 |
|
| 314 |
|
| 315 |
+
#### `add_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L825" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 316 |
+
|
| 317 |
+
```python
|
| 318 |
+
add_tool_transformation(self, tool_name: str, transformation: ToolTransformConfig) -> None
|
| 319 |
+
```
|
| 320 |
+
|
| 321 |
+
Add a tool transformation.
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
#### `remove_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L831" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 325 |
+
|
| 326 |
+
```python
|
| 327 |
+
remove_tool_transformation(self, tool_name: str) -> None
|
| 328 |
+
```
|
| 329 |
+
|
| 330 |
+
Remove a tool transformation.
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L836" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 334 |
|
| 335 |
```python
|
| 336 |
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 337 |
```
|
| 338 |
|
| 339 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L851" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 340 |
|
| 341 |
```python
|
| 342 |
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 343 |
```
|
| 344 |
|
| 345 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L865" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 346 |
|
| 347 |
```python
|
| 348 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
|
|
| 397 |
```
|
| 398 |
|
| 399 |
|
| 400 |
+
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L992" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 401 |
|
| 402 |
```python
|
| 403 |
add_resource(self, resource: Resource) -> Resource
|
|
|
|
| 412 |
- The resource instance that was added to the server.
|
| 413 |
|
| 414 |
|
| 415 |
+
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1015" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 416 |
|
| 417 |
```python
|
| 418 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
|
|
|
| 427 |
- The template instance that was added to the server.
|
| 428 |
|
| 429 |
|
| 430 |
+
#### `add_resource_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1037" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 431 |
|
| 432 |
```python
|
| 433 |
add_resource_fn(self, fn: AnyFunction, uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> None
|
|
|
|
| 447 |
- `tags`: Optional set of tags for categorizing the resource
|
| 448 |
|
| 449 |
|
| 450 |
+
#### `resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1076" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 451 |
|
| 452 |
```python
|
| 453 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
|
|
| 505 |
```
|
| 506 |
|
| 507 |
|
| 508 |
+
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1202" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 509 |
|
| 510 |
```python
|
| 511 |
add_prompt(self, prompt: Prompt) -> Prompt
|
|
|
|
| 520 |
- The prompt instance that was added to the server.
|
| 521 |
|
| 522 |
|
| 523 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1226" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 524 |
|
| 525 |
```python
|
| 526 |
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 527 |
```
|
| 528 |
|
| 529 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1238" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 530 |
|
| 531 |
```python
|
| 532 |
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 533 |
```
|
| 534 |
|
| 535 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1249" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 536 |
|
| 537 |
```python
|
| 538 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
|
|
| 609 |
```
|
| 610 |
|
| 611 |
|
| 612 |
+
#### `run_stdio_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1386" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 613 |
|
| 614 |
```python
|
| 615 |
run_stdio_async(self, show_banner: bool = True) -> None
|
|
|
|
| 618 |
Run the server using stdio transport.
|
| 619 |
|
| 620 |
|
| 621 |
+
#### `run_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1406" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 622 |
|
| 623 |
```python
|
| 624 |
run_http_async(self, show_banner: bool = True, transport: Literal['http', 'streamable-http', 'sse'] = 'http', host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None, middleware: list[ASGIMiddleware] | None = None, stateless_http: bool | None = None) -> None
|
|
|
|
| 637 |
- `stateless_http`: Whether to use stateless HTTP (defaults to settings.stateless_http)
|
| 638 |
|
| 639 |
|
| 640 |
+
#### `run_sse_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1480" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 641 |
|
| 642 |
```python
|
| 643 |
run_sse_async(self, host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None) -> None
|
|
|
|
| 646 |
Run the server using SSE transport.
|
| 647 |
|
| 648 |
|
| 649 |
+
#### `sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1508" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 650 |
|
| 651 |
```python
|
| 652 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 660 |
- `middleware`: A list of middleware to apply to the app
|
| 661 |
|
| 662 |
|
| 663 |
+
#### `streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1539" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 664 |
|
| 665 |
```python
|
| 666 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 673 |
- `middleware`: A list of middleware to apply to the app
|
| 674 |
|
| 675 |
|
| 676 |
+
#### `http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1560" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 677 |
|
| 678 |
```python
|
| 679 |
http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None, json_response: bool | None = None, stateless_http: bool | None = None, transport: Literal['http', 'streamable-http', 'sse'] = 'http') -> StarletteWithLifespan
|
|
|
|
| 690 |
- A Starlette application configured with the specified transport
|
| 691 |
|
| 692 |
|
| 693 |
+
#### `run_streamable_http_async` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1609" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 694 |
|
| 695 |
```python
|
| 696 |
run_streamable_http_async(self, host: str | None = None, port: int | None = None, log_level: str | None = None, path: str | None = None, uvicorn_config: dict[str, Any] | None = None) -> None
|
| 697 |
```
|
| 698 |
|
| 699 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1634" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 700 |
|
| 701 |
```python
|
| 702 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
|
|
| 750 |
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 751 |
|
| 752 |
|
| 753 |
+
#### `import_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1757" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 754 |
|
| 755 |
```python
|
| 756 |
import_server(self, server: FastMCP[LifespanResultT], prefix: str | None = None, tool_separator: str | None = None, resource_separator: str | None = None, prompt_separator: str | None = None) -> None
|
|
|
|
| 791 |
- `prompt_separator`: Deprecated. Separator for prompt names.
|
| 792 |
|
| 793 |
|
| 794 |
+
#### `from_openapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1882" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 795 |
|
| 796 |
```python
|
| 797 |
+
from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route_maps: list[RouteMap] | list[RouteMapNew] | None = None, route_map_fn: OpenAPIRouteMapFn | OpenAPIRouteMapFnNew | None = None, mcp_component_fn: OpenAPIComponentFn | OpenAPIComponentFnNew | None = None, mcp_names: dict[str, str] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI | FastMCPOpenAPINew
|
| 798 |
```
|
| 799 |
|
| 800 |
Create a FastMCP server from an OpenAPI specification.
|
| 801 |
|
| 802 |
|
| 803 |
+
#### `from_fastapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1931" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 804 |
|
| 805 |
```python
|
| 806 |
+
from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap] | list[RouteMapNew] | None = None, route_map_fn: OpenAPIRouteMapFn | OpenAPIRouteMapFnNew | None = None, mcp_component_fn: OpenAPIComponentFn | OpenAPIComponentFnNew | None = None, mcp_names: dict[str, str] | None = None, httpx_client_kwargs: dict[str, Any] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI | FastMCPOpenAPINew
|
| 807 |
```
|
| 808 |
|
| 809 |
Create a FastMCP server from a FastAPI application.
|
| 810 |
|
| 811 |
|
| 812 |
+
#### `as_proxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1994" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 813 |
|
| 814 |
```python
|
| 815 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
|
|
| 823 |
`fastmcp.client.Client` constructor.
|
| 824 |
|
| 825 |
|
| 826 |
+
#### `from_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2055" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 827 |
|
| 828 |
```python
|
| 829 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
|
|
| 832 |
Create a FastMCP proxy server from a FastMCP client.
|
| 833 |
|
| 834 |
|
| 835 |
+
### `MountedServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L2108" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
docs/python-sdk/fastmcp-settings.mdx
CHANGED
|
@@ -25,7 +25,9 @@ get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool
|
|
| 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 |
-
### `
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
FastMCP settings.
|
|
@@ -33,33 +35,44 @@ FastMCP settings.
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
-
#### `
|
| 37 |
|
| 38 |
```python
|
| 39 |
-
|
| 40 |
```
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
```python
|
| 45 |
-
|
| 46 |
```
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
|
| 52 |
-
#### `
|
| 53 |
|
| 54 |
```python
|
| 55 |
-
|
| 56 |
```
|
| 57 |
|
| 58 |
-
#### `
|
| 59 |
|
| 60 |
```python
|
| 61 |
-
|
| 62 |
```
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
### `ExperimentalSettings` <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 |
+
### `Settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L77" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 31 |
|
| 32 |
|
| 33 |
FastMCP settings.
|
|
|
|
| 35 |
|
| 36 |
**Methods:**
|
| 37 |
|
| 38 |
+
#### `get_setting` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L89" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 39 |
|
| 40 |
```python
|
| 41 |
+
get_setting(self, attr: str) -> Any
|
| 42 |
```
|
| 43 |
|
| 44 |
+
Get a setting. If the setting contains one or more `__`, it will be
|
| 45 |
+
treated as a nested setting.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
#### `set_setting` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L102" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 49 |
|
| 50 |
```python
|
| 51 |
+
set_setting(self, attr: str, value: Any) -> None
|
| 52 |
```
|
| 53 |
|
| 54 |
+
Set a setting. If the setting contains one or more `__`, it will be
|
| 55 |
+
treated as a nested setting.
|
| 56 |
|
| 57 |
|
| 58 |
+
#### `settings_customise_sources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L116" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 59 |
|
| 60 |
```python
|
| 61 |
+
settings_customise_sources(cls, settings_cls: type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> tuple[PydanticBaseSettingsSource, ...]
|
| 62 |
```
|
| 63 |
|
| 64 |
+
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 65 |
|
| 66 |
```python
|
| 67 |
+
settings(self) -> Self
|
| 68 |
```
|
| 69 |
|
| 70 |
+
This property is for backwards compatibility with FastMCP < 2.8.0,
|
| 71 |
+
which accessed fastmcp.settings.settings
|
| 72 |
+
|
| 73 |
|
| 74 |
+
#### `normalize_log_level` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
normalize_log_level(cls, v)
|
| 78 |
+
```
|
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,17 +15,17 @@ 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#
|
| 19 |
|
| 20 |
**Methods:**
|
| 21 |
|
| 22 |
-
#### `to_mcp_result` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 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#
|
| 29 |
|
| 30 |
|
| 31 |
Internal tool registration info.
|
|
@@ -33,25 +33,25 @@ 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#
|
| 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#
|
| 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#
|
| 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#
|
| 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
|
|
@@ -60,7 +60,7 @@ from_function(fn: Callable[..., Any], name: str | None = None, title: str | None
|
|
| 60 |
Create a Tool from a function.
|
| 61 |
|
| 62 |
|
| 63 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 64 |
|
| 65 |
```python
|
| 66 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -75,17 +75,17 @@ implemented by subclasses.
|
|
| 75 |
(list of ContentBlocks, dict of structured output).
|
| 76 |
|
| 77 |
|
| 78 |
-
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 79 |
|
| 80 |
```python
|
| 81 |
from_tool(cls, tool: Tool, transform_fn: Callable[..., Any] | None = None, name: str | None = None, title: str | None | NotSetT = NotSet, transform_args: dict[str, ArgTransform] | None = None, description: str | None | NotSetT = NotSet, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, output_schema: dict[str, Any] | None | Literal[False] = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
| 82 |
```
|
| 83 |
|
| 84 |
-
### `FunctionTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 85 |
|
| 86 |
**Methods:**
|
| 87 |
|
| 88 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 89 |
|
| 90 |
```python
|
| 91 |
from_function(cls, fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | None | NotSetT | Literal[False] = NotSet, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
|
@@ -94,7 +94,7 @@ from_function(cls, fn: Callable[..., Any], name: str | None = None, title: str |
|
|
| 94 |
Create a Tool from a function.
|
| 95 |
|
| 96 |
|
| 97 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 98 |
|
| 99 |
```python
|
| 100 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -103,11 +103,11 @@ run(self, arguments: dict[str, Any]) -> ToolResult
|
|
| 103 |
Run the tool with arguments.
|
| 104 |
|
| 105 |
|
| 106 |
-
### `ParsedFunction` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 107 |
|
| 108 |
**Methods:**
|
| 109 |
|
| 110 |
-
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#
|
| 111 |
|
| 112 |
```python
|
| 113 |
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True, wrap_non_object_output_schema: bool = True) -> ParsedFunction
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_serializer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L56" 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#L60" 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#L91" 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#L99" 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#L117" 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#L125" 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#L133" 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#L152" 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
|
|
|
|
| 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#L178" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
|
| 65 |
```python
|
| 66 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 75 |
(list of ContentBlocks, dict of structured output).
|
| 76 |
|
| 77 |
|
| 78 |
+
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L191" 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#L222" 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#L226" 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
|
|
|
|
| 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#L272" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 98 |
|
| 99 |
```python
|
| 100 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 103 |
Run the tool with arguments.
|
| 104 |
|
| 105 |
|
| 106 |
+
### `ParsedFunction` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L318" 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#L326" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 111 |
|
| 112 |
```python
|
| 113 |
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True, wrap_non_object_output_schema: bool = True) -> ParsedFunction
|
docs/python-sdk/fastmcp-tools-tool_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,7 @@ 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#
|
| 28 |
|
| 29 |
```python
|
| 30 |
has_tool(self, key: str) -> bool
|
|
@@ -33,7 +33,7 @@ has_tool(self, key: str) -> bool
|
|
| 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#
|
| 37 |
|
| 38 |
```python
|
| 39 |
get_tool(self, key: str) -> Tool
|
|
@@ -42,7 +42,7 @@ get_tool(self, key: str) -> Tool
|
|
| 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#
|
| 46 |
|
| 47 |
```python
|
| 48 |
get_tools(self) -> dict[str, Tool]
|
|
@@ -51,7 +51,7 @@ get_tools(self) -> dict[str, Tool]
|
|
| 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#
|
| 55 |
|
| 56 |
```python
|
| 57 |
list_tools(self) -> list[Tool]
|
|
@@ -60,7 +60,7 @@ list_tools(self) -> list[Tool]
|
|
| 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#
|
| 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,7 +69,7 @@ add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, descript
|
|
| 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#
|
| 73 |
|
| 74 |
```python
|
| 75 |
add_tool(self, tool: Tool) -> Tool
|
|
@@ -78,7 +78,34 @@ add_tool(self, tool: Tool) -> Tool
|
|
| 78 |
Register a tool with the server.
|
| 79 |
|
| 80 |
|
| 81 |
-
#### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
```python
|
| 84 |
remove_tool(self, key: str) -> None
|
|
@@ -93,7 +120,7 @@ Remove a tool from the server.
|
|
| 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#
|
| 97 |
|
| 98 |
```python
|
| 99 |
call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L25" 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#L51" 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#L99" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 28 |
|
| 29 |
```python
|
| 30 |
has_tool(self, key: str) -> bool
|
|
|
|
| 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#L104" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
get_tool(self, key: str) -> Tool
|
|
|
|
| 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#L111" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 46 |
|
| 47 |
```python
|
| 48 |
get_tools(self) -> dict[str, Tool]
|
|
|
|
| 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#L117" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 55 |
|
| 56 |
```python
|
| 57 |
list_tools(self) -> list[Tool]
|
|
|
|
| 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#L133" 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#L162" 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 |
+
#### `add_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L179" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
add_tool_transformation(self, tool_name: str, transformation: ToolTransformConfig) -> None
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
Add a tool transformation.
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
#### `get_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L185" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
get_tool_transformation(self, tool_name: str) -> ToolTransformConfig | None
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
Get a tool transformation.
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
#### `remove_tool_transformation` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L189" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
remove_tool_transformation(self, tool_name: str) -> None
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
Remove a tool transformation.
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L194" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 109 |
|
| 110 |
```python
|
| 111 |
remove_tool(self, key: str) -> None
|
|
|
|
| 120 |
- `NotFoundError`: If the tool is not found
|
| 121 |
|
| 122 |
|
| 123 |
+
#### `call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L208" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 124 |
|
| 125 |
```python
|
| 126 |
call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult
|
docs/python-sdk/fastmcp-tools-tool_transform.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: tool_transform
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `forward` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
forward(**kwargs) -> ToolResult
|
|
@@ -36,7 +36,7 @@ tool has args `a` and `b`, and an `transform_args` was provided that maps `x` to
|
|
| 36 |
- `TypeError`: If provided arguments don't match the transformed schema.
|
| 37 |
|
| 38 |
|
| 39 |
-
### `forward_raw` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 40 |
|
| 41 |
```python
|
| 42 |
forward_raw(**kwargs) -> ToolResult
|
|
@@ -62,9 +62,20 @@ y=2)` will call the parent tool with `x=1` and `y=2`.
|
|
| 62 |
- `RuntimeError`: If called outside a transformed tool context.
|
| 63 |
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
## Classes
|
| 66 |
|
| 67 |
-
### `ArgTransform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 68 |
|
| 69 |
|
| 70 |
Configuration for transforming a parent tool's argument.
|
|
@@ -126,7 +137,24 @@ ArgTransform(name="new_name", description="New desc", default=None, type=int)
|
|
| 126 |
```
|
| 127 |
|
| 128 |
|
| 129 |
-
### `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
A tool that is transformed from another tool.
|
|
@@ -143,7 +171,7 @@ inherited from the parent tool but can be overridden or disabled.
|
|
| 143 |
|
| 144 |
**Methods:**
|
| 145 |
|
| 146 |
-
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#
|
| 147 |
|
| 148 |
```python
|
| 149 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
@@ -162,7 +190,7 @@ functions.
|
|
| 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#
|
| 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
|
|
@@ -239,3 +267,20 @@ async def custom_output(**kwargs) -> ToolResult:
|
|
| 239 |
)
|
| 240 |
```
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `forward` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L33" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
forward(**kwargs) -> ToolResult
|
|
|
|
| 36 |
- `TypeError`: If provided arguments don't match the transformed schema.
|
| 37 |
|
| 38 |
|
| 39 |
+
### `forward_raw` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L63" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
forward_raw(**kwargs) -> ToolResult
|
|
|
|
| 62 |
- `RuntimeError`: If called outside a transformed tool context.
|
| 63 |
|
| 64 |
|
| 65 |
+
### `apply_transformations_to_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L875" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
apply_transformations_to_tools(tools: dict[str, Tool], transformations: dict[str, ToolTransformConfig]) -> dict[str, Tool]
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
Apply a list of transformations to a list of tools. Tools that do not have any transforamtions
|
| 73 |
+
are left unchanged.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
## Classes
|
| 77 |
|
| 78 |
+
### `ArgTransform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L90" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 79 |
|
| 80 |
|
| 81 |
Configuration for transforming a parent tool's argument.
|
|
|
|
| 137 |
```
|
| 138 |
|
| 139 |
|
| 140 |
+
### `ArgTransformConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L204" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
A model for requesting a single argument transform.
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
**Methods:**
|
| 147 |
+
|
| 148 |
+
#### `to_arg_transform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L222" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 149 |
+
|
| 150 |
+
```python
|
| 151 |
+
to_arg_transform(self) -> ArgTransform
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
Convert the argument transform to a FastMCP argument transform.
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
### `TransformedTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L228" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 158 |
|
| 159 |
|
| 160 |
A tool that is transformed from another tool.
|
|
|
|
| 171 |
|
| 172 |
**Methods:**
|
| 173 |
|
| 174 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L255" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 175 |
|
| 176 |
```python
|
| 177 |
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
|
|
| 190 |
- ToolResult object containing content and optional structured output.
|
| 191 |
|
| 192 |
|
| 193 |
+
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L356" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 194 |
|
| 195 |
```python
|
| 196 |
from_tool(cls, tool: Tool, name: str | None = None, title: str | None | NotSetT = NotSet, description: str | None | NotSetT = NotSet, tags: set[str] | None = None, transform_fn: Callable[..., Any] | None = None, transform_args: dict[str, ArgTransform] | None = None, annotations: ToolAnnotations | None = None, output_schema: dict[str, Any] | None | Literal[False] = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
|
|
|
| 267 |
)
|
| 268 |
```
|
| 269 |
|
| 270 |
+
|
| 271 |
+
### `ToolTransformConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L835" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
Provides a way to transform a tool.
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
**Methods:**
|
| 278 |
+
|
| 279 |
+
#### `apply` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L863" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 280 |
+
|
| 281 |
+
```python
|
| 282 |
+
apply(self, tool: Tool) -> TransformedTool
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
Create a TransformedTool from a provided tool and this transformation configuration.
|
| 286 |
+
|
docs/python-sdk/fastmcp-utilities-json_schema.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: json_schema
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `compress_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/json_schema.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
compress_schema(schema: dict, prune_params: list[str] | None = None, prune_defs: bool = True, prune_additional_properties: bool = True, prune_titles: bool = False) -> dict
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `compress_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/json_schema.py#L183" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
compress_schema(schema: dict, prune_params: list[str] | None = None, prune_defs: bool = True, prune_additional_properties: bool = True, prune_titles: bool = False) -> dict
|
docs/python-sdk/fastmcp-utilities-mcp_config.mdx
CHANGED
|
@@ -7,44 +7,22 @@ sidebarTitle: mcp_config
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `
|
| 11 |
|
| 12 |
```python
|
| 13 |
-
|
| 14 |
```
|
| 15 |
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
|
| 20 |
-
##
|
| 21 |
-
|
| 22 |
-
### `StdioMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L40"><Icon icon="github" size="14" /></a></sup>
|
| 23 |
-
|
| 24 |
-
**Methods:**
|
| 25 |
-
|
| 26 |
-
#### `to_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L47"><Icon icon="github" size="14" /></a></sup>
|
| 27 |
-
|
| 28 |
-
```python
|
| 29 |
-
to_transport(self) -> StdioTransport
|
| 30 |
-
```
|
| 31 |
-
|
| 32 |
-
### `RemoteMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L58"><Icon icon="github" size="14" /></a></sup>
|
| 33 |
-
|
| 34 |
-
**Methods:**
|
| 35 |
-
|
| 36 |
-
#### `to_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L71"><Icon icon="github" size="14" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
-
|
| 40 |
```
|
| 41 |
|
| 42 |
-
### `MCPConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L88"><Icon icon="github" size="14" /></a></sup>
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
#### `from_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L92"><Icon icon="github" size="14" /></a></sup>
|
| 47 |
-
|
| 48 |
-
```python
|
| 49 |
-
from_dict(cls, config: dict[str, Any]) -> MCPConfig
|
| 50 |
-
```
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `composite_server_from_mcp_config` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L5" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
+
composite_server_from_mcp_config(config: MCPConfig, name_as_prefix: bool = True) -> FastMCP
|
| 14 |
```
|
| 15 |
|
| 16 |
|
| 17 |
+
A utility function to create a composite server from an MCPConfig.
|
| 18 |
|
| 19 |
|
| 20 |
+
### `mount_mcp_config_into_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L16" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
```python
|
| 23 |
+
mount_mcp_config_into_server(config: MCPConfig, server: FastMCP, name_as_prefix: bool = True) -> None
|
| 24 |
```
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
+
A utility function to mount the servers from an MCPConfig into a FastMCP server.
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/python-sdk/fastmcp-utilities-openapi.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: openapi
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `format_array_parameter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 11 |
|
| 12 |
```python
|
| 13 |
format_array_parameter(values: list, parameter_name: str, is_query_parameter: bool = False) -> str | list
|
|
@@ -25,7 +25,7 @@ Format an array parameter according to OpenAPI specifications.
|
|
| 25 |
- String (comma-separated) or list (for query params with explode=True)
|
| 26 |
|
| 27 |
|
| 28 |
-
### `format_deep_object_parameter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 29 |
|
| 30 |
```python
|
| 31 |
format_deep_object_parameter(param_value: dict, parameter_name: str) -> dict[str, str]
|
|
@@ -37,8 +37,7 @@ Format a dictionary parameter for deepObject style serialization.
|
|
| 37 |
According to OpenAPI 3.0 spec, deepObject style with explode=true serializes
|
| 38 |
object properties as separate query parameters with bracket notation.
|
| 39 |
|
| 40 |
-
For example: {"id": "123", "type": "user"} becomes
|
| 41 |
-
param[id]=123¶m[type]=user
|
| 42 |
|
| 43 |
**Args:**
|
| 44 |
- `param_value`: Dictionary value to format
|
|
@@ -48,7 +47,7 @@ param[id]=123¶m[type]=user
|
|
| 48 |
- Dictionary with bracketed parameter names as keys
|
| 49 |
|
| 50 |
|
| 51 |
-
### `parse_openapi_to_http_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 52 |
|
| 53 |
```python
|
| 54 |
parse_openapi_to_http_routes(openapi_dict: dict[str, Any]) -> list[HTTPRoute]
|
|
@@ -61,7 +60,7 @@ using the openapi-pydantic library.
|
|
| 61 |
Supports both OpenAPI 3.0.x and 3.1.x versions.
|
| 62 |
|
| 63 |
|
| 64 |
-
### `clean_schema_for_display` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 65 |
|
| 66 |
```python
|
| 67 |
clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
@@ -71,7 +70,7 @@ clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
| 71 |
Clean up a schema dictionary for display by removing internal/complex fields.
|
| 72 |
|
| 73 |
|
| 74 |
-
### `generate_example_from_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 75 |
|
| 76 |
```python
|
| 77 |
generate_example_from_schema(schema: JsonSchema | None) -> Any
|
|
@@ -82,7 +81,7 @@ Generate a simple example value from a JSON schema dictionary.
|
|
| 82 |
Very basic implementation focusing on types.
|
| 83 |
|
| 84 |
|
| 85 |
-
### `format_json_for_description` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 86 |
|
| 87 |
```python
|
| 88 |
format_json_for_description(data: Any, indent: int = 2) -> str
|
|
@@ -92,7 +91,7 @@ format_json_for_description(data: Any, indent: int = 2) -> str
|
|
| 92 |
Formats Python data as a JSON string block for markdown.
|
| 93 |
|
| 94 |
|
| 95 |
-
### `format_description_with_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 96 |
|
| 97 |
```python
|
| 98 |
format_description_with_responses(base_description: str, responses: dict[str, Any], parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
|
|
@@ -115,7 +114,7 @@ including its description, whether it is required, and its content schema.
|
|
| 115 |
- and the request body.
|
| 116 |
|
| 117 |
|
| 118 |
-
### `extract_output_schema_from_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 119 |
|
| 120 |
```python
|
| 121 |
extract_output_schema_from_responses(responses: dict[str, ResponseInfo], schema_definitions: dict[str, Any] | None = None) -> dict[str, Any] | None
|
|
@@ -138,31 +137,31 @@ object type, it wraps it to comply with MCP requirements.
|
|
| 138 |
|
| 139 |
## Classes
|
| 140 |
|
| 141 |
-
### `ParameterInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 142 |
|
| 143 |
|
| 144 |
Represents a single parameter for an HTTP operation in our IR.
|
| 145 |
|
| 146 |
|
| 147 |
-
### `RequestBodyInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 148 |
|
| 149 |
|
| 150 |
Represents the request body for an HTTP operation in our IR.
|
| 151 |
|
| 152 |
|
| 153 |
-
### `ResponseInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 154 |
|
| 155 |
|
| 156 |
Represents response information in our IR.
|
| 157 |
|
| 158 |
|
| 159 |
-
### `HTTPRoute` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 160 |
|
| 161 |
|
| 162 |
Intermediate Representation for a single OpenAPI operation.
|
| 163 |
|
| 164 |
|
| 165 |
-
### `OpenAPIParser` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 166 |
|
| 167 |
|
| 168 |
Unified parser for OpenAPI schemas with generic type parameters to handle both 3.0 and 3.1.
|
|
@@ -170,7 +169,7 @@ Unified parser for OpenAPI schemas with generic type parameters to handle both 3
|
|
| 170 |
|
| 171 |
**Methods:**
|
| 172 |
|
| 173 |
-
#### `parse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#
|
| 174 |
|
| 175 |
```python
|
| 176 |
parse(self) -> list[HTTPRoute]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `format_array_parameter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L41" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
format_array_parameter(values: list, parameter_name: str, is_query_parameter: bool = False) -> str | list
|
|
|
|
| 25 |
- String (comma-separated) or list (for query params with explode=True)
|
| 26 |
|
| 27 |
|
| 28 |
+
### `format_deep_object_parameter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L95" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 29 |
|
| 30 |
```python
|
| 31 |
format_deep_object_parameter(param_value: dict, parameter_name: str) -> dict[str, str]
|
|
|
|
| 37 |
According to OpenAPI 3.0 spec, deepObject style with explode=true serializes
|
| 38 |
object properties as separate query parameters with bracket notation.
|
| 39 |
|
| 40 |
+
For example: `{"id": "123", "type": "user"}` becomes `param[id]=123¶m[type]=user`.
|
|
|
|
| 41 |
|
| 42 |
**Args:**
|
| 43 |
- `param_value`: Dictionary value to format
|
|
|
|
| 47 |
- Dictionary with bracketed parameter names as keys
|
| 48 |
|
| 49 |
|
| 50 |
+
### `parse_openapi_to_http_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L203" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 51 |
|
| 52 |
```python
|
| 53 |
parse_openapi_to_http_routes(openapi_dict: dict[str, Any]) -> list[HTTPRoute]
|
|
|
|
| 60 |
Supports both OpenAPI 3.0.x and 3.1.x versions.
|
| 61 |
|
| 62 |
|
| 63 |
+
### `clean_schema_for_display` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L738" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 64 |
|
| 65 |
```python
|
| 66 |
clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
|
|
| 70 |
Clean up a schema dictionary for display by removing internal/complex fields.
|
| 71 |
|
| 72 |
|
| 73 |
+
### `generate_example_from_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L798" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 74 |
|
| 75 |
```python
|
| 76 |
generate_example_from_schema(schema: JsonSchema | None) -> Any
|
|
|
|
| 81 |
Very basic implementation focusing on types.
|
| 82 |
|
| 83 |
|
| 84 |
+
### `format_json_for_description` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L881" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 85 |
|
| 86 |
```python
|
| 87 |
format_json_for_description(data: Any, indent: int = 2) -> str
|
|
|
|
| 91 |
Formats Python data as a JSON string block for markdown.
|
| 92 |
|
| 93 |
|
| 94 |
+
### `format_description_with_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L890" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 95 |
|
| 96 |
```python
|
| 97 |
format_description_with_responses(base_description: str, responses: dict[str, Any], parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
|
|
|
|
| 114 |
- and the request body.
|
| 115 |
|
| 116 |
|
| 117 |
+
### `extract_output_schema_from_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L1322" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 118 |
|
| 119 |
```python
|
| 120 |
extract_output_schema_from_responses(responses: dict[str, ResponseInfo], schema_definitions: dict[str, Any] | None = None) -> dict[str, Any] | None
|
|
|
|
| 137 |
|
| 138 |
## Classes
|
| 139 |
|
| 140 |
+
### `ParameterInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L128" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 141 |
|
| 142 |
|
| 143 |
Represents a single parameter for an HTTP operation in our IR.
|
| 144 |
|
| 145 |
|
| 146 |
+
### `RequestBodyInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 147 |
|
| 148 |
|
| 149 |
Represents the request body for an HTTP operation in our IR.
|
| 150 |
|
| 151 |
|
| 152 |
+
### `ResponseInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L150" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 153 |
|
| 154 |
|
| 155 |
Represents response information in our IR.
|
| 156 |
|
| 157 |
|
| 158 |
+
### `HTTPRoute` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L158" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 159 |
|
| 160 |
|
| 161 |
Intermediate Representation for a single OpenAPI operation.
|
| 162 |
|
| 163 |
|
| 164 |
+
### `OpenAPIParser` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L255" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 165 |
|
| 166 |
|
| 167 |
Unified parser for OpenAPI schemas with generic type parameters to handle both 3.0 and 3.1.
|
|
|
|
| 169 |
|
| 170 |
**Methods:**
|
| 171 |
|
| 172 |
+
#### `parse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L617" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 173 |
|
| 174 |
```python
|
| 175 |
parse(self) -> list[HTTPRoute]
|
docs/python-sdk/fastmcp-utilities-tests.mdx
CHANGED
|
@@ -20,7 +20,7 @@ Temporarily override FastMCP setting values.
|
|
| 20 |
- `**kwargs`: The settings to override, including nested settings.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `run_server_in_process` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#
|
| 24 |
|
| 25 |
```python
|
| 26 |
run_server_in_process(server_fn: Callable[..., None], *args, **kwargs) -> Generator[str, None, None]
|
|
@@ -41,7 +41,7 @@ not pickleable, so we need a function that creates and runs one.
|
|
| 41 |
- The server URL.
|
| 42 |
|
| 43 |
|
| 44 |
-
### `caplog_for_fastmcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#
|
| 45 |
|
| 46 |
```python
|
| 47 |
caplog_for_fastmcp(caplog)
|
|
|
|
| 20 |
- `**kwargs`: The settings to override, including nested settings.
|
| 21 |
|
| 22 |
|
| 23 |
+
### `run_server_in_process` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
run_server_in_process(server_fn: Callable[..., None], *args, **kwargs) -> Generator[str, None, None]
|
|
|
|
| 41 |
- The server URL.
|
| 42 |
|
| 43 |
|
| 44 |
+
### `caplog_for_fastmcp` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L133" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 45 |
|
| 46 |
```python
|
| 47 |
caplog_for_fastmcp(caplog)
|
docs/python-sdk/fastmcp-utilities-types.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Common types used across FastMCP.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `get_cached_typeadapter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_cached_typeadapter(cls: T) -> TypeAdapter[T]
|
|
@@ -23,7 +23,7 @@ However, this isn't feasible for user-generated functions. Instead, we use a
|
|
| 23 |
cache to minimize the cost of creating them as much as possible.
|
| 24 |
|
| 25 |
|
| 26 |
-
### `issubclass_safe` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 27 |
|
| 28 |
```python
|
| 29 |
issubclass_safe(cls: type, base: type) -> bool
|
|
@@ -33,7 +33,7 @@ issubclass_safe(cls: type, base: type) -> bool
|
|
| 33 |
Check if cls is a subclass of base, even if cls is a type variable.
|
| 34 |
|
| 35 |
|
| 36 |
-
### `is_class_member_of_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 37 |
|
| 38 |
```python
|
| 39 |
is_class_member_of_type(cls: type, base: type) -> bool
|
|
@@ -46,7 +46,7 @@ Base can be a type, a UnionType, or an Annotated type. Generic types are not
|
|
| 46 |
considered members (e.g. T is not a member of list\[T]).
|
| 47 |
|
| 48 |
|
| 49 |
-
### `find_kwarg_by_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 50 |
|
| 51 |
```python
|
| 52 |
find_kwarg_by_type(fn: Callable, kwarg_type: type) -> str | None
|
|
@@ -58,7 +58,7 @@ Find the name of the kwarg that is of type kwarg_type.
|
|
| 58 |
Includes union types that contain the kwarg_type, as well as Annotated types.
|
| 59 |
|
| 60 |
|
| 61 |
-
### `replace_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 62 |
|
| 63 |
```python
|
| 64 |
replace_type(type_, type_map: dict[type, type])
|
|
@@ -75,23 +75,25 @@ This is useful for transforming types when creating tools.
|
|
| 75 |
- `old_type`: The type to replace.
|
| 76 |
- `new_type`: The type to replace old_type with.
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
>>> replace_type(list
|
| 81 |
-
list
|
| 82 |
-
|
| 83 |
-
list\[list\[str]]
|
| 84 |
|
| 85 |
|
| 86 |
## Classes
|
| 87 |
|
| 88 |
-
### `FastMCPBaseModel` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 89 |
|
| 90 |
|
| 91 |
Base model for FastMCP models.
|
| 92 |
|
| 93 |
|
| 94 |
-
### `Image` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 95 |
|
| 96 |
|
| 97 |
Helper class for returning images from tools.
|
|
@@ -99,7 +101,7 @@ Helper class for returning images from tools.
|
|
| 99 |
|
| 100 |
**Methods:**
|
| 101 |
|
| 102 |
-
#### `to_image_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 103 |
|
| 104 |
```python
|
| 105 |
to_image_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.ImageContent
|
|
@@ -108,7 +110,7 @@ to_image_content(self, mime_type: str | None = None, annotations: Annotations |
|
|
| 108 |
Convert to MCP ImageContent.
|
| 109 |
|
| 110 |
|
| 111 |
-
### `Audio` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 112 |
|
| 113 |
|
| 114 |
Helper class for returning audio from tools.
|
|
@@ -116,13 +118,13 @@ Helper class for returning audio from tools.
|
|
| 116 |
|
| 117 |
**Methods:**
|
| 118 |
|
| 119 |
-
#### `to_audio_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 120 |
|
| 121 |
```python
|
| 122 |
to_audio_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.AudioContent
|
| 123 |
```
|
| 124 |
|
| 125 |
-
### `File` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 126 |
|
| 127 |
|
| 128 |
Helper class for returning audio from tools.
|
|
@@ -130,7 +132,7 @@ Helper class for returning audio from tools.
|
|
| 130 |
|
| 131 |
**Methods:**
|
| 132 |
|
| 133 |
-
#### `to_resource_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#
|
| 134 |
|
| 135 |
```python
|
| 136 |
to_resource_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.EmbeddedResource
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `get_cached_typeadapter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L39" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_cached_typeadapter(cls: T) -> TypeAdapter[T]
|
|
|
|
| 23 |
cache to minimize the cost of creating them as much as possible.
|
| 24 |
|
| 25 |
|
| 26 |
+
### `issubclass_safe` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L97" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 27 |
|
| 28 |
```python
|
| 29 |
issubclass_safe(cls: type, base: type) -> bool
|
|
|
|
| 33 |
Check if cls is a subclass of base, even if cls is a type variable.
|
| 34 |
|
| 35 |
|
| 36 |
+
### `is_class_member_of_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L107" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
is_class_member_of_type(cls: type, base: type) -> bool
|
|
|
|
| 46 |
considered members (e.g. T is not a member of list\[T]).
|
| 47 |
|
| 48 |
|
| 49 |
+
### `find_kwarg_by_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L129" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 50 |
|
| 51 |
```python
|
| 52 |
find_kwarg_by_type(fn: Callable, kwarg_type: type) -> str | None
|
|
|
|
| 58 |
Includes union types that contain the kwarg_type, as well as Annotated types.
|
| 59 |
|
| 60 |
|
| 61 |
+
### `replace_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L358" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 62 |
|
| 63 |
```python
|
| 64 |
replace_type(type_, type_map: dict[type, type])
|
|
|
|
| 75 |
- `old_type`: The type to replace.
|
| 76 |
- `new_type`: The type to replace old_type with.
|
| 77 |
|
| 78 |
+
Examples:
|
| 79 |
+
```python
|
| 80 |
+
>>> replace_type(list[int | bool], {int: str})
|
| 81 |
+
list[str | bool]
|
| 82 |
|
| 83 |
+
>>> replace_type(list[list[int]], {int: str})
|
| 84 |
+
list[list[str]]
|
| 85 |
+
```
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
## Classes
|
| 89 |
|
| 90 |
+
### `FastMCPBaseModel` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L32" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 91 |
|
| 92 |
|
| 93 |
Base model for FastMCP models.
|
| 94 |
|
| 95 |
|
| 96 |
+
### `Image` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L155" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 97 |
|
| 98 |
|
| 99 |
Helper class for returning images from tools.
|
|
|
|
| 101 |
|
| 102 |
**Methods:**
|
| 103 |
|
| 104 |
+
#### `to_image_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L192" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 105 |
|
| 106 |
```python
|
| 107 |
to_image_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.ImageContent
|
|
|
|
| 110 |
Convert to MCP ImageContent.
|
| 111 |
|
| 112 |
|
| 113 |
+
### `Audio` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L214" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 114 |
|
| 115 |
|
| 116 |
Helper class for returning audio from tools.
|
|
|
|
| 118 |
|
| 119 |
**Methods:**
|
| 120 |
|
| 121 |
+
#### `to_audio_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L251" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 122 |
|
| 123 |
```python
|
| 124 |
to_audio_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.AudioContent
|
| 125 |
```
|
| 126 |
|
| 127 |
+
### `File` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L272" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 128 |
|
| 129 |
|
| 130 |
Helper class for returning audio from tools.
|
|
|
|
| 132 |
|
| 133 |
**Methods:**
|
| 134 |
|
| 135 |
+
#### `to_resource_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L311" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
| 136 |
|
| 137 |
```python
|
| 138 |
to_resource_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> mcp.types.EmbeddedResource
|
src/fastmcp/mcp_config.py
CHANGED
|
@@ -7,17 +7,19 @@ The configuration format supports both stdio and remote (HTTP/SSE) transports, w
|
|
| 7 |
field definitions for server metadata, authentication, and execution parameters.
|
| 8 |
|
| 9 |
Example configuration:
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
}
|
| 20 |
}
|
|
|
|
|
|
|
| 21 |
"""
|
| 22 |
|
| 23 |
from __future__ import annotations
|
|
|
|
| 7 |
field definitions for server metadata, authentication, and execution parameters.
|
| 8 |
|
| 9 |
Example configuration:
|
| 10 |
+
```json
|
| 11 |
+
{
|
| 12 |
+
"mcpServers": {
|
| 13 |
+
"my-server": {
|
| 14 |
+
"command": "npx",
|
| 15 |
+
"args": ["-y", "@my/mcp-server"],
|
| 16 |
+
"env": {"API_KEY": "secret"},
|
| 17 |
+
"timeout": 30000,
|
| 18 |
+
"description": "My MCP server"
|
| 19 |
}
|
| 20 |
}
|
| 21 |
+
}
|
| 22 |
+
```
|
| 23 |
"""
|
| 24 |
|
| 25 |
from __future__ import annotations
|
src/fastmcp/utilities/openapi.py
CHANGED
|
@@ -101,8 +101,7 @@ def format_deep_object_parameter(
|
|
| 101 |
According to OpenAPI 3.0 spec, deepObject style with explode=true serializes
|
| 102 |
object properties as separate query parameters with bracket notation.
|
| 103 |
|
| 104 |
-
For example: {"id": "123", "type": "user"} becomes
|
| 105 |
-
param[id]=123¶m[type]=user
|
| 106 |
|
| 107 |
Args:
|
| 108 |
param_value: Dictionary value to format
|
|
|
|
| 101 |
According to OpenAPI 3.0 spec, deepObject style with explode=true serializes
|
| 102 |
object properties as separate query parameters with bracket notation.
|
| 103 |
|
| 104 |
+
For example: `{"id": "123", "type": "user"}` becomes `param[id]=123¶m[type]=user`.
|
|
|
|
| 105 |
|
| 106 |
Args:
|
| 107 |
param_value: Dictionary value to format
|
src/fastmcp/utilities/types.py
CHANGED
|
@@ -368,12 +368,13 @@ def replace_type(type_, type_map: dict[type, type]):
|
|
| 368 |
new_type: The type to replace old_type with.
|
| 369 |
|
| 370 |
Examples:
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
>>> replace_type(list[list[int]], {int: str})
|
| 375 |
-
list[list[str]]
|
| 376 |
|
|
|
|
|
|
|
|
|
|
| 377 |
"""
|
| 378 |
if type_ in type_map:
|
| 379 |
return type_map[type_]
|
|
|
|
| 368 |
new_type: The type to replace old_type with.
|
| 369 |
|
| 370 |
Examples:
|
| 371 |
+
```python
|
| 372 |
+
>>> replace_type(list[int | bool], {int: str})
|
| 373 |
+
list[str | bool]
|
|
|
|
|
|
|
| 374 |
|
| 375 |
+
>>> replace_type(list[list[int]], {int: str})
|
| 376 |
+
list[list[str]]
|
| 377 |
+
```
|
| 378 |
"""
|
| 379 |
if type_ in type_map:
|
| 380 |
return type_map[type_]
|