Spaces:
Running
Running
Merge pull request #935 from jlowin/source-link-api-ref
Browse files- docs/docs.json +11 -1
- docs/python-sdk/fastmcp-cli-claude.mdx +2 -2
- docs/python-sdk/fastmcp-cli-cli.mdx +18 -17
- docs/python-sdk/fastmcp-cli-run.mdx +6 -6
- docs/python-sdk/fastmcp-client-auth-bearer.mdx +2 -2
- docs/python-sdk/fastmcp-client-auth-oauth.mdx +9 -9
- docs/python-sdk/fastmcp-client-client.mdx +42 -42
- docs/python-sdk/fastmcp-client-logging.mdx +1 -1
- docs/python-sdk/fastmcp-client-oauth_callback.mdx +5 -5
- docs/python-sdk/fastmcp-client-roots.mdx +2 -2
- docs/python-sdk/fastmcp-client-sampling.mdx +1 -1
- docs/python-sdk/fastmcp-client-transports.mdx +88 -87
- docs/python-sdk/fastmcp-exceptions.mdx +9 -9
- docs/python-sdk/fastmcp-prompts-prompt.mdx +7 -7
- docs/python-sdk/fastmcp-prompts-prompt_manager.mdx +4 -4
- docs/python-sdk/fastmcp-resources-resource.mdx +8 -8
- docs/python-sdk/fastmcp-resources-resource_manager.mdx +7 -7
- docs/python-sdk/fastmcp-resources-template.mdx +11 -11
- docs/python-sdk/fastmcp-resources-types.mdx +9 -9
- docs/python-sdk/fastmcp-server-auth-auth.mdx +1 -1
- docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx +6 -6
- docs/python-sdk/fastmcp-server-auth-providers-bearer_env.mdx +2 -2
- docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx +1 -1
- docs/python-sdk/fastmcp-server-context.mdx +8 -8
- docs/python-sdk/fastmcp-server-dependencies.mdx +3 -3
- docs/python-sdk/fastmcp-server-http.mdx +8 -8
- docs/python-sdk/fastmcp-server-middleware-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-server-middleware-error_handling.mdx +40 -0
- docs/python-sdk/fastmcp-server-middleware-logging.mdx +29 -0
- docs/python-sdk/fastmcp-server-middleware-middleware.mdx +56 -0
- docs/python-sdk/fastmcp-server-middleware-rate_limiting.mdx +47 -0
- docs/python-sdk/fastmcp-server-middleware-timing.mdx +29 -0
- docs/python-sdk/fastmcp-server-openapi.mdx +7 -7
- docs/python-sdk/fastmcp-server-proxy.mdx +12 -12
- docs/python-sdk/fastmcp-server-server.mdx +84 -80
- docs/python-sdk/fastmcp-settings.mdx +7 -7
- docs/python-sdk/fastmcp-tools-tool.mdx +9 -9
- docs/python-sdk/fastmcp-tools-tool_manager.mdx +5 -5
- docs/python-sdk/fastmcp-tools-tool_transform.mdx +28 -37
- docs/python-sdk/fastmcp-utilities-cache.mdx +4 -4
- docs/python-sdk/fastmcp-utilities-components.mdx +5 -5
- docs/python-sdk/fastmcp-utilities-exceptions.mdx +2 -2
- docs/python-sdk/fastmcp-utilities-http.mdx +1 -1
- docs/python-sdk/fastmcp-utilities-inspect.mdx +5 -5
- docs/python-sdk/fastmcp-utilities-json_schema.mdx +1 -1
- docs/python-sdk/fastmcp-utilities-logging.mdx +2 -2
- docs/python-sdk/fastmcp-utilities-mcp_config.mdx +8 -8
- docs/python-sdk/fastmcp-utilities-openapi.mdx +11 -11
- docs/python-sdk/fastmcp-utilities-tests.mdx +3 -3
- docs/python-sdk/fastmcp-utilities-types.mdx +11 -11
docs/docs.json
CHANGED
|
@@ -257,7 +257,17 @@
|
|
| 257 |
"python-sdk/fastmcp-server-context",
|
| 258 |
"python-sdk/fastmcp-server-dependencies",
|
| 259 |
"python-sdk/fastmcp-server-http",
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
"python-sdk/fastmcp-server-openapi",
|
| 262 |
"python-sdk/fastmcp-server-proxy",
|
| 263 |
"python-sdk/fastmcp-server-server"
|
|
|
|
| 257 |
"python-sdk/fastmcp-server-context",
|
| 258 |
"python-sdk/fastmcp-server-dependencies",
|
| 259 |
"python-sdk/fastmcp-server-http",
|
| 260 |
+
{
|
| 261 |
+
"group": "middleware",
|
| 262 |
+
"pages": [
|
| 263 |
+
"python-sdk/fastmcp-server-middleware-__init__",
|
| 264 |
+
"python-sdk/fastmcp-server-middleware-error_handling",
|
| 265 |
+
"python-sdk/fastmcp-server-middleware-logging",
|
| 266 |
+
"python-sdk/fastmcp-server-middleware-middleware",
|
| 267 |
+
"python-sdk/fastmcp-server-middleware-rate_limiting",
|
| 268 |
+
"python-sdk/fastmcp-server-middleware-timing"
|
| 269 |
+
]
|
| 270 |
+
},
|
| 271 |
"python-sdk/fastmcp-server-openapi",
|
| 272 |
"python-sdk/fastmcp-server-proxy",
|
| 273 |
"python-sdk/fastmcp-server-server"
|
docs/python-sdk/fastmcp-cli-claude.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Claude app integration utilities.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `get_claude_config_path`
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_claude_config_path() -> Path | None
|
|
@@ -20,7 +20,7 @@ get_claude_config_path() -> Path | None
|
|
| 20 |
Get the Claude config directory based on platform.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `update_claude_config`
|
| 24 |
|
| 25 |
```python
|
| 26 |
update_claude_config(file_spec: str, server_name: str) -> bool
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `get_claude_config_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/claude.py#L14" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_claude_config_path() -> Path | None
|
|
|
|
| 20 |
Get the Claude config directory based on platform.
|
| 21 |
|
| 22 |
|
| 23 |
+
### `update_claude_config` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/claude.py#L32" target="_blank">β</a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
update_claude_config(file_spec: str, server_name: str) -> bool
|
docs/python-sdk/fastmcp-cli-cli.mdx
CHANGED
|
@@ -10,13 +10,13 @@ FastMCP CLI tools.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `version`
|
| 14 |
|
| 15 |
```python
|
| 16 |
version(ctx: Context)
|
| 17 |
```
|
| 18 |
|
| 19 |
-
### `dev`
|
| 20 |
|
| 21 |
```python
|
| 22 |
dev(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], inspector_version: Annotated[str | None, typer.Option('--inspector-version', help='Version of the MCP Inspector to use')] = None, ui_port: Annotated[int | None, typer.Option('--ui-port', help='Port for the MCP Inspector UI')] = None, server_port: Annotated[int | None, typer.Option('--server-port', help='Port for the MCP Inspector Proxy server')] = None) -> None
|
|
@@ -26,10 +26,10 @@ dev(server_spec: str = typer.Argument(..., help='Python file to run, optionally
|
|
| 26 |
Run a MCP server with the MCP Inspector.
|
| 27 |
|
| 28 |
|
| 29 |
-
### `run`
|
| 30 |
|
| 31 |
```python
|
| 32 |
-
run(ctx: typer.Context, server_spec: str = typer.Argument(..., help='Python file, object specification (file:obj), or URL'), transport: Annotated[str | None, typer.Option('--transport', '-t', help='Transport protocol to use (stdio,
|
| 33 |
```
|
| 34 |
|
| 35 |
|
|
@@ -51,7 +51,7 @@ Server arguments can be passed after -- :
|
|
| 51 |
fastmcp run server.py -- --config config.json --debug
|
| 52 |
|
| 53 |
|
| 54 |
-
### `install`
|
| 55 |
|
| 56 |
```python
|
| 57 |
install(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), server_name: Annotated[str | None, typer.Option('--name', '-n', help="Custom name for the server (defaults to server's name attribute or file name)")] = None, with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], env_vars: Annotated[list[str], typer.Option('--env-var', '-v', help='Environment variables in KEY=VALUE format')] = [], env_file: Annotated[Path | None, typer.Option('--env-file', '-f', help='Load environment variables from a .env file', exists=True, file_okay=True, dir_okay=False, resolve_path=True)] = None) -> None
|
|
@@ -64,7 +64,7 @@ Environment variables are preserved once added and only updated if new values
|
|
| 64 |
are explicitly provided.
|
| 65 |
|
| 66 |
|
| 67 |
-
### `inspect`
|
| 68 |
|
| 69 |
```python
|
| 70 |
inspect(server_spec: str = typer.Argument(..., help='Python file to inspect, optionally with :object suffix'), output: Annotated[Path, typer.Option('--output', '-o', help='Output file path for the JSON report (default: server-info.json)')] = Path('server-info.json')) -> None
|
|
@@ -73,14 +73,15 @@ inspect(server_spec: str = typer.Argument(..., help='Python file to inspect, opt
|
|
| 73 |
|
| 74 |
Inspect a FastMCP server and generate a JSON report.
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `version` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L87" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
version(ctx: Context)
|
| 17 |
```
|
| 18 |
|
| 19 |
+
### `dev` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L110" target="_blank">β</a></sup>
|
| 20 |
|
| 21 |
```python
|
| 22 |
dev(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], inspector_version: Annotated[str | None, typer.Option('--inspector-version', help='Version of the MCP Inspector to use')] = None, ui_port: Annotated[int | None, typer.Option('--ui-port', help='Port for the MCP Inspector UI')] = None, server_port: Annotated[int | None, typer.Option('--server-port', help='Port for the MCP Inspector Proxy server')] = None) -> None
|
|
|
|
| 26 |
Run a MCP server with the MCP Inspector.
|
| 27 |
|
| 28 |
|
| 29 |
+
### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L227" target="_blank">β</a></sup>
|
| 30 |
|
| 31 |
```python
|
| 32 |
+
run(ctx: typer.Context, server_spec: str = typer.Argument(..., help='Python file, object specification (file:obj), or URL'), transport: Annotated[str | None, typer.Option('--transport', '-t', help='Transport protocol to use (stdio, http, or sse)')] = None, host: Annotated[str | None, typer.Option('--host', help='Host to bind to when using http transport (default: 127.0.0.1)')] = None, port: Annotated[int | None, typer.Option('--port', '-p', help='Port to bind to when using http transport (default: 8000)')] = None, log_level: Annotated[str | None, typer.Option('--log-level', '-l', help='Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)')] = None) -> None
|
| 33 |
```
|
| 34 |
|
| 35 |
|
|
|
|
| 51 |
fastmcp run server.py -- --config config.json --debug
|
| 52 |
|
| 53 |
|
| 54 |
+
### `install` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L313" target="_blank">β</a></sup>
|
| 55 |
|
| 56 |
```python
|
| 57 |
install(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), server_name: Annotated[str | None, typer.Option('--name', '-n', help="Custom name for the server (defaults to server's name attribute or file name)")] = None, with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], env_vars: Annotated[list[str], typer.Option('--env-var', '-v', help='Environment variables in KEY=VALUE format')] = [], env_file: Annotated[Path | None, typer.Option('--env-file', '-f', help='Load environment variables from a .env file', exists=True, file_okay=True, dir_okay=False, resolve_path=True)] = None) -> None
|
|
|
|
| 64 |
are explicitly provided.
|
| 65 |
|
| 66 |
|
| 67 |
+
### `inspect` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/cli.py#L444" target="_blank">β</a></sup>
|
| 68 |
|
| 69 |
```python
|
| 70 |
inspect(server_spec: str = typer.Argument(..., help='Python file to inspect, optionally with :object suffix'), output: Annotated[Path, typer.Option('--output', '-o', help='Output file path for the JSON report (default: server-info.json)')] = Path('server-info.json')) -> None
|
|
|
|
| 73 |
|
| 74 |
Inspect a FastMCP server and generate a JSON report.
|
| 75 |
|
| 76 |
+
This command analyzes a FastMCP server (v1.x or v2.x) and generates
|
| 77 |
+
a comprehensive JSON report containing information about the server's
|
| 78 |
+
name, instructions, version, tools, prompts, resources, templates,
|
| 79 |
+
and capabilities.
|
| 80 |
+
|
| 81 |
+
**Examples:**
|
| 82 |
+
|
| 83 |
+
fastmcp inspect server.py
|
| 84 |
+
fastmcp inspect server.py -o report.json
|
| 85 |
+
fastmcp inspect server.py:mcp -o analysis.json
|
| 86 |
+
fastmcp inspect path/to/server.py:app -o /tmp/server-info.json
|
| 87 |
+
|
docs/python-sdk/fastmcp-cli-run.mdx
CHANGED
|
@@ -10,7 +10,7 @@ FastMCP run command implementation.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `is_url`
|
| 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`
|
| 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`
|
| 40 |
|
| 41 |
```python
|
| 42 |
import_server(file: Path, server_object: str | None = None) -> Any
|
|
@@ -53,7 +53,7 @@ Import a MCP server from a file.
|
|
| 53 |
- The server object
|
| 54 |
|
| 55 |
|
| 56 |
-
### `create_client_server`
|
| 57 |
|
| 58 |
```python
|
| 59 |
create_client_server(url: str) -> Any
|
|
@@ -69,7 +69,7 @@ Create a FastMCP server from a client URL.
|
|
| 69 |
- A FastMCP server instance
|
| 70 |
|
| 71 |
|
| 72 |
-
### `import_server_with_args`
|
| 73 |
|
| 74 |
```python
|
| 75 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
@@ -87,7 +87,7 @@ Import a server with optional command line arguments.
|
|
| 87 |
- The imported server object
|
| 88 |
|
| 89 |
|
| 90 |
-
### `run_command`
|
| 91 |
|
| 92 |
```python
|
| 93 |
run_command(server_spec: str, transport: str | None = None, host: str | None = None, port: int | None = None, log_level: str | None = None, server_args: list[str] | None = None) -> None
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `is_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L14" target="_blank">β</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#L20" target="_blank">β</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#L51" target="_blank">β</a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
import_server(file: Path, server_object: str | None = None) -> Any
|
|
|
|
| 53 |
- The server object
|
| 54 |
|
| 55 |
|
| 56 |
+
### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L121" target="_blank">β</a></sup>
|
| 57 |
|
| 58 |
```python
|
| 59 |
create_client_server(url: str) -> Any
|
|
|
|
| 69 |
- A FastMCP server instance
|
| 70 |
|
| 71 |
|
| 72 |
+
### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L141" target="_blank">β</a></sup>
|
| 73 |
|
| 74 |
```python
|
| 75 |
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
|
|
|
| 87 |
- The imported server object
|
| 88 |
|
| 89 |
|
| 90 |
+
### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L165" target="_blank">β</a></sup>
|
| 91 |
|
| 92 |
```python
|
| 93 |
run_command(server_spec: str, transport: str | None = None, host: str | None = None, port: int | None = None, log_level: str | None = None, server_args: list[str] | None = None) -> None
|
docs/python-sdk/fastmcp-client-auth-bearer.mdx
CHANGED
|
@@ -7,11 +7,11 @@ sidebarTitle: bearer
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `BearerAuth`
|
| 11 |
|
| 12 |
**Methods:**
|
| 13 |
|
| 14 |
-
#### `auth_flow`
|
| 15 |
|
| 16 |
```python
|
| 17 |
auth_flow(self, request)
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `BearerAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/bearer.py#L11" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
**Methods:**
|
| 13 |
|
| 14 |
+
#### `auth_flow` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/bearer.py#L15" target="_blank">β</a></sup>
|
| 15 |
|
| 16 |
```python
|
| 17 |
auth_flow(self, request)
|
docs/python-sdk/fastmcp-client-auth-oauth.mdx
CHANGED
|
@@ -7,13 +7,13 @@ sidebarTitle: oauth
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `default_cache_dir`
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_cache_dir() -> Path
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `OAuth`
|
| 17 |
|
| 18 |
```python
|
| 19 |
OAuth(mcp_url: str, scopes: str | list[str] | None = None, client_name: str = 'FastMCP Client', token_storage_cache_dir: Path | None = None, additional_client_metadata: dict[str, Any] | None = None) -> _MCPOAuthClientProvider
|
|
@@ -38,7 +38,7 @@ httpx.AsyncClient (or appropriate FastMCP client/transport instance)
|
|
| 38 |
|
| 39 |
## Classes
|
| 40 |
|
| 41 |
-
### `ServerOAuthMetadata`
|
| 42 |
|
| 43 |
|
| 44 |
More flexible OAuth metadata model that accepts broader ranges of values
|
|
@@ -48,13 +48,13 @@ This handles real-world OAuth servers like PayPal that may support
|
|
| 48 |
additional methods not in the MCP specification.
|
| 49 |
|
| 50 |
|
| 51 |
-
### `OAuthClientProvider`
|
| 52 |
|
| 53 |
|
| 54 |
OAuth client provider with more flexible OAuth metadata discovery.
|
| 55 |
|
| 56 |
|
| 57 |
-
### `FileTokenStorage`
|
| 58 |
|
| 59 |
|
| 60 |
File-based token storage implementation for OAuth credentials and tokens.
|
|
@@ -65,7 +65,7 @@ Each instance is tied to a specific server URL for proper token isolation.
|
|
| 65 |
|
| 66 |
**Methods:**
|
| 67 |
|
| 68 |
-
#### `get_base_url`
|
| 69 |
|
| 70 |
```python
|
| 71 |
get_base_url(url: str) -> str
|
|
@@ -74,7 +74,7 @@ get_base_url(url: str) -> str
|
|
| 74 |
Extract the base URL (scheme + host) from a URL.
|
| 75 |
|
| 76 |
|
| 77 |
-
#### `get_cache_key`
|
| 78 |
|
| 79 |
```python
|
| 80 |
get_cache_key(self) -> str
|
|
@@ -83,7 +83,7 @@ get_cache_key(self) -> str
|
|
| 83 |
Generate a safe filesystem key from the server's base URL.
|
| 84 |
|
| 85 |
|
| 86 |
-
#### `clear`
|
| 87 |
|
| 88 |
```python
|
| 89 |
clear(self) -> None
|
|
@@ -92,7 +92,7 @@ clear(self) -> None
|
|
| 92 |
Clear all cached data for this server.
|
| 93 |
|
| 94 |
|
| 95 |
-
#### `clear_all`
|
| 96 |
|
| 97 |
```python
|
| 98 |
clear_all(cls, cache_dir: Path | None = None) -> None
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `default_cache_dir` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L38" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_cache_dir() -> Path
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `OAuth` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L295" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
OAuth(mcp_url: str, scopes: str | list[str] | None = None, client_name: str = 'FastMCP Client', token_storage_cache_dir: Path | None = None, additional_client_metadata: dict[str, Any] | None = None) -> _MCPOAuthClientProvider
|
|
|
|
| 38 |
|
| 39 |
## Classes
|
| 40 |
|
| 41 |
+
### `ServerOAuthMetadata` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L43" target="_blank">β</a></sup>
|
| 42 |
|
| 43 |
|
| 44 |
More flexible OAuth metadata model that accepts broader ranges of values
|
|
|
|
| 48 |
additional methods not in the MCP specification.
|
| 49 |
|
| 50 |
|
| 51 |
+
### `OAuthClientProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L68" target="_blank">β</a></sup>
|
| 52 |
|
| 53 |
|
| 54 |
OAuth client provider with more flexible OAuth metadata discovery.
|
| 55 |
|
| 56 |
|
| 57 |
+
### `FileTokenStorage` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L116" target="_blank">β</a></sup>
|
| 58 |
|
| 59 |
|
| 60 |
File-based token storage implementation for OAuth credentials and tokens.
|
|
|
|
| 65 |
|
| 66 |
**Methods:**
|
| 67 |
|
| 68 |
+
#### `get_base_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L131" target="_blank">β</a></sup>
|
| 69 |
|
| 70 |
```python
|
| 71 |
get_base_url(url: str) -> str
|
|
|
|
| 74 |
Extract the base URL (scheme + host) from a URL.
|
| 75 |
|
| 76 |
|
| 77 |
+
#### `get_cache_key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L136" target="_blank">β</a></sup>
|
| 78 |
|
| 79 |
```python
|
| 80 |
get_cache_key(self) -> str
|
|
|
|
| 83 |
Generate a safe filesystem key from the server's base URL.
|
| 84 |
|
| 85 |
|
| 86 |
+
#### `clear` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L208" target="_blank">β</a></sup>
|
| 87 |
|
| 88 |
```python
|
| 89 |
clear(self) -> None
|
|
|
|
| 92 |
Clear all cached data for this server.
|
| 93 |
|
| 94 |
|
| 95 |
+
#### `clear_all` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/auth/oauth.py#L217" target="_blank">β</a></sup>
|
| 96 |
|
| 97 |
```python
|
| 98 |
clear_all(cls, cache_dir: Path | None = None) -> None
|
docs/python-sdk/fastmcp-client-client.mdx
CHANGED
|
@@ -7,48 +7,48 @@ sidebarTitle: client
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `Client`
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
# Call a tool result = await client.call_tool("my_tool", {"param":
|
| 45 |
-
"value"})
|
| 46 |
-
```
|
| 47 |
-
|
| 48 |
|
| 49 |
**Methods:**
|
| 50 |
|
| 51 |
-
#### `session`
|
| 52 |
|
| 53 |
```python
|
| 54 |
session(self) -> ClientSession
|
|
@@ -57,7 +57,7 @@ session(self) -> ClientSession
|
|
| 57 |
Get the current active session. Raises RuntimeError if not connected.
|
| 58 |
|
| 59 |
|
| 60 |
-
#### `initialize_result`
|
| 61 |
|
| 62 |
```python
|
| 63 |
initialize_result(self) -> mcp.types.InitializeResult
|
|
@@ -66,7 +66,7 @@ initialize_result(self) -> mcp.types.InitializeResult
|
|
| 66 |
Get the result of the initialization request.
|
| 67 |
|
| 68 |
|
| 69 |
-
#### `set_roots`
|
| 70 |
|
| 71 |
```python
|
| 72 |
set_roots(self, roots: RootsList | RootsHandler) -> None
|
|
@@ -75,7 +75,7 @@ set_roots(self, roots: RootsList | RootsHandler) -> None
|
|
| 75 |
Set the roots for the client. This does not automatically call `send_roots_list_changed`.
|
| 76 |
|
| 77 |
|
| 78 |
-
#### `set_sampling_callback`
|
| 79 |
|
| 80 |
```python
|
| 81 |
set_sampling_callback(self, sampling_callback: SamplingHandler) -> None
|
|
@@ -84,7 +84,7 @@ set_sampling_callback(self, sampling_callback: SamplingHandler) -> None
|
|
| 84 |
Set the sampling callback for the client.
|
| 85 |
|
| 86 |
|
| 87 |
-
#### `is_connected`
|
| 88 |
|
| 89 |
```python
|
| 90 |
is_connected(self) -> bool
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `Client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L60" target="_blank">β</a></sup>
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
MCP client that delegates connection management to a Transport instance.
|
| 14 |
+
|
| 15 |
+
The Client class is responsible for MCP protocol logic, while the Transport
|
| 16 |
+
handles connection establishment and management. Client provides methods for
|
| 17 |
+
working with resources, prompts, tools and other MCP capabilities.
|
| 18 |
+
|
| 19 |
+
**Args:**
|
| 20 |
+
- `transport`: Connection source specification, which can be\:
|
| 21 |
+
- ClientTransport\: Direct transport instance
|
| 22 |
+
- FastMCP\: In-process FastMCP server
|
| 23 |
+
- AnyUrl | str\: URL to connect to
|
| 24 |
+
- Path\: File path for local socket
|
| 25 |
+
- MCPConfig\: MCP server configuration
|
| 26 |
+
- dict\: Transport configuration
|
| 27 |
+
- `roots`: Optional RootsList or RootsHandler for filesystem access
|
| 28 |
+
- `sampling_handler`: Optional handler for sampling requests
|
| 29 |
+
- `log_handler`: Optional handler for log messages
|
| 30 |
+
- `message_handler`: Optional handler for protocol messages
|
| 31 |
+
- `progress_handler`: Optional handler for progress notifications
|
| 32 |
+
- `timeout`: Optional timeout for requests (seconds or timedelta)
|
| 33 |
+
- `init_timeout`: Optional timeout for initial connection (seconds or timedelta).
|
| 34 |
+
Set to 0 to disable. If None, uses the value in the FastMCP global settings.
|
| 35 |
+
|
| 36 |
+
**Examples:**
|
| 37 |
+
|
| 38 |
+
```python # Connect to FastMCP server client =
|
| 39 |
+
Client("http://localhost:8080")
|
| 40 |
+
|
| 41 |
+
async with client:
|
| 42 |
+
# List available resources resources = await client.list_resources()
|
| 43 |
+
|
| 44 |
+
# Call a tool result = await client.call_tool("my_tool", {"param":
|
| 45 |
+
"value"})
|
| 46 |
+
```
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
**Methods:**
|
| 50 |
|
| 51 |
+
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L207" target="_blank">β</a></sup>
|
| 52 |
|
| 53 |
```python
|
| 54 |
session(self) -> ClientSession
|
|
|
|
| 57 |
Get the current active session. Raises RuntimeError if not connected.
|
| 58 |
|
| 59 |
|
| 60 |
+
#### `initialize_result` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L217" target="_blank">β</a></sup>
|
| 61 |
|
| 62 |
```python
|
| 63 |
initialize_result(self) -> mcp.types.InitializeResult
|
|
|
|
| 66 |
Get the result of the initialization request.
|
| 67 |
|
| 68 |
|
| 69 |
+
#### `set_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L225" target="_blank">β</a></sup>
|
| 70 |
|
| 71 |
```python
|
| 72 |
set_roots(self, roots: RootsList | RootsHandler) -> None
|
|
|
|
| 75 |
Set the roots for the client. This does not automatically call `send_roots_list_changed`.
|
| 76 |
|
| 77 |
|
| 78 |
+
#### `set_sampling_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L229" target="_blank">β</a></sup>
|
| 79 |
|
| 80 |
```python
|
| 81 |
set_sampling_callback(self, sampling_callback: SamplingHandler) -> None
|
|
|
|
| 84 |
Set the sampling callback for the client.
|
| 85 |
|
| 86 |
|
| 87 |
+
#### `is_connected` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/client.py#L235" target="_blank">β</a></sup>
|
| 88 |
|
| 89 |
```python
|
| 90 |
is_connected(self) -> bool
|
docs/python-sdk/fastmcp-client-logging.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: logging
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `create_log_callback`
|
| 11 |
|
| 12 |
```python
|
| 13 |
create_log_callback(handler: LogHandler | None = None) -> LoggingFnT
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `create_log_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/logging.py#L20" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
create_log_callback(handler: LogHandler | None = None) -> LoggingFnT
|
docs/python-sdk/fastmcp-client-oauth_callback.mdx
CHANGED
|
@@ -15,7 +15,7 @@ and display styled responses to users.
|
|
| 15 |
|
| 16 |
## Functions
|
| 17 |
|
| 18 |
-
### `create_callback_html`
|
| 19 |
|
| 20 |
```python
|
| 21 |
create_callback_html(message: str, is_success: bool = True, title: str = 'FastMCP OAuth', server_url: str | None = None) -> str
|
|
@@ -25,7 +25,7 @@ create_callback_html(message: str, is_success: bool = True, title: str = 'FastMC
|
|
| 25 |
Create a styled HTML response for OAuth callbacks.
|
| 26 |
|
| 27 |
|
| 28 |
-
### `create_oauth_callback_server`
|
| 29 |
|
| 30 |
```python
|
| 31 |
create_oauth_callback_server(port: int, callback_path: str = '/callback', server_url: str | None = None, response_future: asyncio.Future | None = None) -> Server
|
|
@@ -46,17 +46,17 @@ Create an OAuth callback server.
|
|
| 46 |
|
| 47 |
## Classes
|
| 48 |
|
| 49 |
-
### `CallbackResponse`
|
| 50 |
|
| 51 |
**Methods:**
|
| 52 |
|
| 53 |
-
#### `from_dict`
|
| 54 |
|
| 55 |
```python
|
| 56 |
from_dict(cls, data: dict[str, str]) -> CallbackResponse
|
| 57 |
```
|
| 58 |
|
| 59 |
-
#### `to_dict`
|
| 60 |
|
| 61 |
```python
|
| 62 |
to_dict(self) -> dict[str, str]
|
|
|
|
| 15 |
|
| 16 |
## Functions
|
| 17 |
|
| 18 |
+
### `create_callback_html` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L25" target="_blank">β</a></sup>
|
| 19 |
|
| 20 |
```python
|
| 21 |
create_callback_html(message: str, is_success: bool = True, title: str = 'FastMCP OAuth', server_url: str | None = None) -> str
|
|
|
|
| 25 |
Create a styled HTML response for OAuth callbacks.
|
| 26 |
|
| 27 |
|
| 28 |
+
### `create_oauth_callback_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L197" target="_blank">β</a></sup>
|
| 29 |
|
| 30 |
```python
|
| 31 |
create_oauth_callback_server(port: int, callback_path: str = '/callback', server_url: str | None = None, response_future: asyncio.Future | None = None) -> Server
|
|
|
|
| 46 |
|
| 47 |
## Classes
|
| 48 |
|
| 49 |
+
### `CallbackResponse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L183" target="_blank">β</a></sup>
|
| 50 |
|
| 51 |
**Methods:**
|
| 52 |
|
| 53 |
+
#### `from_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L190" target="_blank">β</a></sup>
|
| 54 |
|
| 55 |
```python
|
| 56 |
from_dict(cls, data: dict[str, str]) -> CallbackResponse
|
| 57 |
```
|
| 58 |
|
| 59 |
+
#### `to_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/oauth_callback.py#L193" target="_blank">β</a></sup>
|
| 60 |
|
| 61 |
```python
|
| 62 |
to_dict(self) -> dict[str, str]
|
docs/python-sdk/fastmcp-client-roots.mdx
CHANGED
|
@@ -7,13 +7,13 @@ sidebarTitle: roots
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `convert_roots_list`
|
| 11 |
|
| 12 |
```python
|
| 13 |
convert_roots_list(roots: RootsList) -> list[mcp.types.Root]
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `create_roots_callback`
|
| 17 |
|
| 18 |
```python
|
| 19 |
create_roots_callback(handler: RootsList | RootsHandler) -> ListRootsFnT
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `convert_roots_list` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/roots.py#L19" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
convert_roots_list(roots: RootsList) -> list[mcp.types.Root]
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `create_roots_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/roots.py#L33" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
create_roots_callback(handler: RootsList | RootsHandler) -> ListRootsFnT
|
docs/python-sdk/fastmcp-client-sampling.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: sampling
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `create_sampling_callback`
|
| 11 |
|
| 12 |
```python
|
| 13 |
create_sampling_callback(sampling_handler: SamplingHandler) -> SamplingFnT
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `create_sampling_callback` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/sampling.py#L25" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
create_sampling_callback(sampling_handler: SamplingHandler) -> SamplingFnT
|
docs/python-sdk/fastmcp-client-transports.mdx
CHANGED
|
@@ -7,63 +7,63 @@ sidebarTitle: transports
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `infer_transport`
|
| 11 |
|
| 12 |
```python
|
| 13 |
infer_transport(transport: ClientTransport | FastMCP | FastMCP1Server | AnyUrl | Path | MCPConfig | dict[str, Any] | str) -> ClientTransport
|
| 14 |
```
|
| 15 |
|
| 16 |
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
- ClientTransport: Used directly without modification
|
| 26 |
-
- FastMCP or FastMCP1Server: Creates an in-memory FastMCPTransport
|
| 27 |
-
- Path or str (file path): Creates PythonStdioTransport (.py) or NodeStdioTransport (.js)
|
| 28 |
-
- AnyUrl or str (URL): Creates StreamableHttpTransport (default) or SSETransport (for /sse endpoints)
|
| 29 |
-
- MCPConfig or dict: Creates MCPConfigTransport, potentially connecting to multiple servers
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
is mounted with its name as prefix. This allows accessing tools and resources from multiple
|
| 35 |
-
servers through a single unified client interface, using naming patterns like
|
| 36 |
-
`servername_toolname` for tools and `protocol://servername/path` for resources.
|
| 37 |
-
If the MCPConfig contains only one server, a direct connection is established without prefixing.
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
# Connect to multiple servers using MCPConfig
|
| 48 |
-
config = {
|
| 49 |
-
"mcpServers": {
|
| 50 |
-
"weather": {"url": "http://weather.example.com/mcp"},
|
| 51 |
-
"calendar": {"url": "http://calendar.example.com/mcp"}
|
| 52 |
-
}
|
| 53 |
-
}
|
| 54 |
-
transport = infer_transport(config)
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
|
| 58 |
## Classes
|
| 59 |
|
| 60 |
-
### `SessionKwargs`
|
| 61 |
|
| 62 |
|
| 63 |
Keyword arguments for the MCP ClientSession constructor.
|
| 64 |
|
| 65 |
|
| 66 |
-
### `ClientTransport`
|
| 67 |
|
| 68 |
|
| 69 |
Abstract base class for different MCP client transport mechanisms.
|
|
@@ -72,25 +72,25 @@ A Transport is responsible for establishing and managing connections
|
|
| 72 |
to an MCP server, and providing a ClientSession within an async context.
|
| 73 |
|
| 74 |
|
| 75 |
-
### `WSTransport`
|
| 76 |
|
| 77 |
|
| 78 |
Transport implementation that connects to an MCP server via WebSockets.
|
| 79 |
|
| 80 |
|
| 81 |
-
### `SSETransport`
|
| 82 |
|
| 83 |
|
| 84 |
Transport implementation that connects to an MCP server via Server-Sent Events.
|
| 85 |
|
| 86 |
|
| 87 |
-
### `StreamableHttpTransport`
|
| 88 |
|
| 89 |
|
| 90 |
Transport implementation that connects to an MCP server via Streamable HTTP Requests.
|
| 91 |
|
| 92 |
|
| 93 |
-
### `StdioTransport`
|
| 94 |
|
| 95 |
|
| 96 |
Base transport for connecting to an MCP server via subprocess with stdio.
|
|
@@ -99,37 +99,37 @@ This is a base class that can be subclassed for specific command-based
|
|
| 99 |
transports like Python, Node, Uvx, etc.
|
| 100 |
|
| 101 |
|
| 102 |
-
### `PythonStdioTransport`
|
| 103 |
|
| 104 |
|
| 105 |
Transport for running Python scripts.
|
| 106 |
|
| 107 |
|
| 108 |
-
### `FastMCPStdioTransport`
|
| 109 |
|
| 110 |
|
| 111 |
Transport for running FastMCP servers using the FastMCP CLI.
|
| 112 |
|
| 113 |
|
| 114 |
-
### `NodeStdioTransport`
|
| 115 |
|
| 116 |
|
| 117 |
Transport for running Node.js scripts.
|
| 118 |
|
| 119 |
|
| 120 |
-
### `UvxStdioTransport`
|
| 121 |
|
| 122 |
|
| 123 |
Transport for running commands via the uvx tool.
|
| 124 |
|
| 125 |
|
| 126 |
-
### `NpxStdioTransport`
|
| 127 |
|
| 128 |
|
| 129 |
Transport for running commands via the npx tool.
|
| 130 |
|
| 131 |
|
| 132 |
-
### `FastMCPTransport`
|
| 133 |
|
| 134 |
|
| 135 |
In-memory transport for FastMCP servers.
|
|
@@ -140,52 +140,53 @@ servers from the low-level MCP SDK. This is particularly useful for unit
|
|
| 140 |
tests or scenarios where client and server run in the same runtime.
|
| 141 |
|
| 142 |
|
| 143 |
-
### `MCPConfigTransport`
|
| 144 |
|
| 145 |
|
| 146 |
Transport for connecting to one or more MCP servers defined in an MCPConfig.
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
}
|
| 178 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
events = await client.call_tool("calendar_list_events", {"date": "2023-06-01"})
|
| 187 |
|
| 188 |
-
# Access resources with prefixed URIs
|
| 189 |
-
icons = await client.read_resource("weather://weather/icons/sunny")
|
| 190 |
-
```
|
| 191 |
-
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `infer_transport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L837" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
infer_transport(transport: ClientTransport | FastMCP | FastMCP1Server | AnyUrl | Path | MCPConfig | dict[str, Any] | str) -> ClientTransport
|
| 14 |
```
|
| 15 |
|
| 16 |
|
| 17 |
+
Infer the appropriate transport type from the given transport argument.
|
| 18 |
|
| 19 |
+
This function attempts to infer the correct transport type from the provided
|
| 20 |
+
argument, handling various input types and converting them to the appropriate
|
| 21 |
+
ClientTransport subclass.
|
| 22 |
|
| 23 |
+
The function supports these input types:
|
| 24 |
+
- ClientTransport: Used directly without modification
|
| 25 |
+
- FastMCP or FastMCP1Server: Creates an in-memory FastMCPTransport
|
| 26 |
+
- Path or str (file path): Creates PythonStdioTransport (.py) or NodeStdioTransport (.js)
|
| 27 |
+
- AnyUrl or str (URL): Creates StreamableHttpTransport (default) or SSETransport (for /sse endpoints)
|
| 28 |
+
- MCPConfig or dict: Creates MCPConfigTransport, potentially connecting to multiple servers
|
| 29 |
|
| 30 |
+
For HTTP URLs, they are assumed to be Streamable HTTP URLs unless they end in `/sse`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
For MCPConfig with multiple servers, a composite client is created where each server
|
| 33 |
+
is mounted with its name as prefix. This allows accessing tools and resources from multiple
|
| 34 |
+
servers through a single unified client interface, using naming patterns like
|
| 35 |
+
`servername_toolname` for tools and `protocol://servername/path` for resources.
|
| 36 |
+
If the MCPConfig contains only one server, a direct connection is established without prefixing.
|
| 37 |
|
| 38 |
+
**Examples:**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
```python
|
| 41 |
+
# Connect to a local Python script
|
| 42 |
+
transport = infer_transport("my_script.py")
|
| 43 |
+
|
| 44 |
+
# Connect to a remote server via HTTP
|
| 45 |
+
transport = infer_transport("http://example.com/mcp")
|
| 46 |
+
|
| 47 |
+
# Connect to multiple servers using MCPConfig
|
| 48 |
+
config = {
|
| 49 |
+
"mcpServers": {
|
| 50 |
+
"weather": {"url": "http://weather.example.com/mcp"},
|
| 51 |
+
"calendar": {"url": "http://calendar.example.com/mcp"}
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
transport = infer_transport(config)
|
| 55 |
+
```
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
## Classes
|
| 59 |
|
| 60 |
+
### `SessionKwargs` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L52" target="_blank">β</a></sup>
|
| 61 |
|
| 62 |
|
| 63 |
Keyword arguments for the MCP ClientSession constructor.
|
| 64 |
|
| 65 |
|
| 66 |
+
### `ClientTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L63" target="_blank">β</a></sup>
|
| 67 |
|
| 68 |
|
| 69 |
Abstract base class for different MCP client transport mechanisms.
|
|
|
|
| 72 |
to an MCP server, and providing a ClientSession within an async context.
|
| 73 |
|
| 74 |
|
| 75 |
+
### `WSTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L109" target="_blank">β</a></sup>
|
| 76 |
|
| 77 |
|
| 78 |
Transport implementation that connects to an MCP server via WebSockets.
|
| 79 |
|
| 80 |
|
| 81 |
+
### `SSETransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L148" target="_blank">β</a></sup>
|
| 82 |
|
| 83 |
|
| 84 |
Transport implementation that connects to an MCP server via Server-Sent Events.
|
| 85 |
|
| 86 |
|
| 87 |
+
### `StreamableHttpTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L223" target="_blank">β</a></sup>
|
| 88 |
|
| 89 |
|
| 90 |
Transport implementation that connects to an MCP server via Streamable HTTP Requests.
|
| 91 |
|
| 92 |
|
| 93 |
+
### `StdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L299" target="_blank">β</a></sup>
|
| 94 |
|
| 95 |
|
| 96 |
Base transport for connecting to an MCP server via subprocess with stdio.
|
|
|
|
| 99 |
transports like Python, Node, Uvx, etc.
|
| 100 |
|
| 101 |
|
| 102 |
+
### `PythonStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L416" target="_blank">β</a></sup>
|
| 103 |
|
| 104 |
|
| 105 |
Transport for running Python scripts.
|
| 106 |
|
| 107 |
|
| 108 |
+
### `FastMCPStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L462" target="_blank">β</a></sup>
|
| 109 |
|
| 110 |
|
| 111 |
Transport for running FastMCP servers using the FastMCP CLI.
|
| 112 |
|
| 113 |
|
| 114 |
+
### `NodeStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L489" target="_blank">β</a></sup>
|
| 115 |
|
| 116 |
|
| 117 |
Transport for running Node.js scripts.
|
| 118 |
|
| 119 |
|
| 120 |
+
### `UvxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L531" target="_blank">β</a></sup>
|
| 121 |
|
| 122 |
|
| 123 |
Transport for running commands via the uvx tool.
|
| 124 |
|
| 125 |
|
| 126 |
+
### `NpxStdioTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L597" target="_blank">β</a></sup>
|
| 127 |
|
| 128 |
|
| 129 |
Transport for running commands via the npx tool.
|
| 130 |
|
| 131 |
|
| 132 |
+
### `FastMCPTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L659" target="_blank">β</a></sup>
|
| 133 |
|
| 134 |
|
| 135 |
In-memory transport for FastMCP servers.
|
|
|
|
| 140 |
tests or scenarios where client and server run in the same runtime.
|
| 141 |
|
| 142 |
|
| 143 |
+
### `MCPConfigTransport` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/transports.py#L713" target="_blank">β</a></sup>
|
| 144 |
|
| 145 |
|
| 146 |
Transport for connecting to one or more MCP servers defined in an MCPConfig.
|
| 147 |
|
| 148 |
+
This transport provides a unified interface to multiple MCP servers defined in an MCPConfig
|
| 149 |
+
object or dictionary matching the MCPConfig schema. It supports two key scenarios:
|
| 150 |
+
|
| 151 |
+
1. If the MCPConfig contains exactly one server, it creates a direct transport to that server.
|
| 152 |
+
2. If the MCPConfig contains multiple servers, it creates a composite client by mounting
|
| 153 |
+
all servers on a single FastMCP instance, with each server's name used as its mounting prefix.
|
| 154 |
+
|
| 155 |
+
In the multi-server case, tools are accessible with the prefix pattern `{server_name}_{tool_name}`
|
| 156 |
+
and resources with the pattern `protocol://{server_name}/path/to/resource`.
|
| 157 |
+
|
| 158 |
+
This is particularly useful for creating clients that need to interact with multiple specialized
|
| 159 |
+
MCP servers through a single interface, simplifying client code.
|
| 160 |
+
|
| 161 |
+
**Examples:**
|
| 162 |
+
|
| 163 |
+
```python
|
| 164 |
+
from fastmcp import Client
|
| 165 |
+
from fastmcp.utilities.mcp_config import MCPConfig
|
| 166 |
+
|
| 167 |
+
# Create a config with multiple servers
|
| 168 |
+
config = {
|
| 169 |
+
"mcpServers": {
|
| 170 |
+
"weather": {
|
| 171 |
+
"url": "https://weather-api.example.com/mcp",
|
| 172 |
+
"transport": "http"
|
| 173 |
+
},
|
| 174 |
+
"calendar": {
|
| 175 |
+
"url": "https://calendar-api.example.com/mcp",
|
| 176 |
+
"transport": "http"
|
|
|
|
| 177 |
}
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
# Create a client with the config
|
| 182 |
+
client = Client(config)
|
| 183 |
|
| 184 |
+
async with client:
|
| 185 |
+
# Access tools with prefixes
|
| 186 |
+
weather = await client.call_tool("weather_get_forecast", {"city": "London"})
|
| 187 |
+
events = await client.call_tool("calendar_list_events", {"date": "2023-06-01"})
|
| 188 |
|
| 189 |
+
# Access resources with prefixed URIs
|
| 190 |
+
icons = await client.read_resource("weather://weather/icons/sunny")
|
| 191 |
+
```
|
|
|
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
docs/python-sdk/fastmcp-exceptions.mdx
CHANGED
|
@@ -10,55 +10,55 @@ Custom exceptions for FastMCP.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `FastMCPError`
|
| 14 |
|
| 15 |
|
| 16 |
Base error for FastMCP.
|
| 17 |
|
| 18 |
|
| 19 |
-
### `ValidationError`
|
| 20 |
|
| 21 |
|
| 22 |
Error in validating parameters or return values.
|
| 23 |
|
| 24 |
|
| 25 |
-
### `ResourceError`
|
| 26 |
|
| 27 |
|
| 28 |
Error in resource operations.
|
| 29 |
|
| 30 |
|
| 31 |
-
### `ToolError`
|
| 32 |
|
| 33 |
|
| 34 |
Error in tool operations.
|
| 35 |
|
| 36 |
|
| 37 |
-
### `PromptError`
|
| 38 |
|
| 39 |
|
| 40 |
Error in prompt operations.
|
| 41 |
|
| 42 |
|
| 43 |
-
### `InvalidSignature`
|
| 44 |
|
| 45 |
|
| 46 |
Invalid signature for use with FastMCP.
|
| 47 |
|
| 48 |
|
| 49 |
-
### `ClientError`
|
| 50 |
|
| 51 |
|
| 52 |
Error in client operations.
|
| 53 |
|
| 54 |
|
| 55 |
-
### `NotFoundError`
|
| 56 |
|
| 57 |
|
| 58 |
Object not found.
|
| 59 |
|
| 60 |
|
| 61 |
-
### `DisabledError`
|
| 62 |
|
| 63 |
|
| 64 |
Object is disabled.
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `FastMCPError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L6" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Base error for FastMCP.
|
| 17 |
|
| 18 |
|
| 19 |
+
### `ValidationError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L10" target="_blank">β</a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
Error in validating parameters or return values.
|
| 23 |
|
| 24 |
|
| 25 |
+
### `ResourceError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L14" target="_blank">β</a></sup>
|
| 26 |
|
| 27 |
|
| 28 |
Error in resource operations.
|
| 29 |
|
| 30 |
|
| 31 |
+
### `ToolError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L18" target="_blank">β</a></sup>
|
| 32 |
|
| 33 |
|
| 34 |
Error in tool operations.
|
| 35 |
|
| 36 |
|
| 37 |
+
### `PromptError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L22" target="_blank">β</a></sup>
|
| 38 |
|
| 39 |
|
| 40 |
Error in prompt operations.
|
| 41 |
|
| 42 |
|
| 43 |
+
### `InvalidSignature` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L26" target="_blank">β</a></sup>
|
| 44 |
|
| 45 |
|
| 46 |
Invalid signature for use with FastMCP.
|
| 47 |
|
| 48 |
|
| 49 |
+
### `ClientError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L30" target="_blank">β</a></sup>
|
| 50 |
|
| 51 |
|
| 52 |
Error in client operations.
|
| 53 |
|
| 54 |
|
| 55 |
+
### `NotFoundError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L34" target="_blank">β</a></sup>
|
| 56 |
|
| 57 |
|
| 58 |
Object not found.
|
| 59 |
|
| 60 |
|
| 61 |
+
### `DisabledError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/exceptions.py#L38" target="_blank">β</a></sup>
|
| 62 |
|
| 63 |
|
| 64 |
Object is disabled.
|
docs/python-sdk/fastmcp-prompts-prompt.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Base classes for FastMCP prompts.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `Message`
|
| 14 |
|
| 15 |
```python
|
| 16 |
Message(content: str | MCPContent, role: Role | None = None, **kwargs: Any) -> PromptMessage
|
|
@@ -22,13 +22,13 @@ A user-friendly constructor for PromptMessage.
|
|
| 22 |
|
| 23 |
## Classes
|
| 24 |
|
| 25 |
-
### `PromptArgument`
|
| 26 |
|
| 27 |
|
| 28 |
An argument that can be passed to a prompt.
|
| 29 |
|
| 30 |
|
| 31 |
-
### `Prompt`
|
| 32 |
|
| 33 |
|
| 34 |
A prompt template that can be rendered with parameters.
|
|
@@ -36,7 +36,7 @@ A prompt template that can be rendered with parameters.
|
|
| 36 |
|
| 37 |
**Methods:**
|
| 38 |
|
| 39 |
-
#### `to_mcp_prompt`
|
| 40 |
|
| 41 |
```python
|
| 42 |
to_mcp_prompt(self, **overrides: Any) -> MCPPrompt
|
|
@@ -45,7 +45,7 @@ to_mcp_prompt(self, **overrides: Any) -> MCPPrompt
|
|
| 45 |
Convert the prompt to an MCP prompt.
|
| 46 |
|
| 47 |
|
| 48 |
-
#### `from_function`
|
| 49 |
|
| 50 |
```python
|
| 51 |
from_function(fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
|
@@ -60,7 +60,7 @@ The function can return:
|
|
| 60 |
- A sequence of any of the above
|
| 61 |
|
| 62 |
|
| 63 |
-
### `FunctionPrompt`
|
| 64 |
|
| 65 |
|
| 66 |
A prompt that is a function.
|
|
@@ -68,7 +68,7 @@ A prompt that is a function.
|
|
| 68 |
|
| 69 |
**Methods:**
|
| 70 |
|
| 71 |
-
#### `from_function`
|
| 72 |
|
| 73 |
```python
|
| 74 |
from_function(cls, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `Message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L32" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
Message(content: str | MCPContent, role: Role | None = None, **kwargs: Any) -> PromptMessage
|
|
|
|
| 22 |
|
| 23 |
## Classes
|
| 24 |
|
| 25 |
+
### `PromptArgument` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L54" target="_blank">β</a></sup>
|
| 26 |
|
| 27 |
|
| 28 |
An argument that can be passed to a prompt.
|
| 29 |
|
| 30 |
|
| 31 |
+
### `Prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L66" target="_blank">β</a></sup>
|
| 32 |
|
| 33 |
|
| 34 |
A prompt template that can be rendered with parameters.
|
|
|
|
| 36 |
|
| 37 |
**Methods:**
|
| 38 |
|
| 39 |
+
#### `to_mcp_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L73" target="_blank">β</a></sup>
|
| 40 |
|
| 41 |
```python
|
| 42 |
to_mcp_prompt(self, **overrides: Any) -> MCPPrompt
|
|
|
|
| 45 |
Convert the prompt to an MCP prompt.
|
| 46 |
|
| 47 |
|
| 48 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L91" target="_blank">β</a></sup>
|
| 49 |
|
| 50 |
```python
|
| 51 |
from_function(fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
|
|
|
| 60 |
- A sequence of any of the above
|
| 61 |
|
| 62 |
|
| 63 |
+
### `FunctionPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L119" target="_blank">β</a></sup>
|
| 64 |
|
| 65 |
|
| 66 |
A prompt that is a function.
|
|
|
|
| 68 |
|
| 69 |
**Methods:**
|
| 70 |
|
| 71 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt.py#L125" target="_blank">β</a></sup>
|
| 72 |
|
| 73 |
```python
|
| 74 |
from_function(cls, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
docs/python-sdk/fastmcp-prompts-prompt_manager.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: prompt_manager
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `PromptManager`
|
| 11 |
|
| 12 |
|
| 13 |
Manages FastMCP prompts.
|
|
@@ -15,7 +15,7 @@ Manages FastMCP prompts.
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
-
#### `mount`
|
| 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 prompts.
|
| 25 |
|
| 26 |
|
| 27 |
-
#### `add_prompt_from_fn`
|
| 28 |
|
| 29 |
```python
|
| 30 |
add_prompt_from_fn(self, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None) -> FunctionPrompt
|
|
@@ -33,7 +33,7 @@ add_prompt_from_fn(self, fn: Callable[..., PromptResult | Awaitable[PromptResult
|
|
| 33 |
Create a prompt from a function.
|
| 34 |
|
| 35 |
|
| 36 |
-
#### `add_prompt`
|
| 37 |
|
| 38 |
```python
|
| 39 |
add_prompt(self, prompt: Prompt) -> Prompt
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `PromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L21" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
Manages FastMCP prompts.
|
|
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L45" target="_blank">β</a></sup>
|
| 19 |
|
| 20 |
```python
|
| 21 |
mount(self, server: MountedServer) -> None
|
|
|
|
| 24 |
Adds a mounted server as a source for prompts.
|
| 25 |
|
| 26 |
|
| 27 |
+
#### `add_prompt_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L114" target="_blank">β</a></sup>
|
| 28 |
|
| 29 |
```python
|
| 30 |
add_prompt_from_fn(self, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None) -> FunctionPrompt
|
|
|
|
| 33 |
Create a prompt from a function.
|
| 34 |
|
| 35 |
|
| 36 |
+
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/prompts/prompt_manager.py#L134" target="_blank">β</a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
add_prompt(self, prompt: Prompt) -> Prompt
|
docs/python-sdk/fastmcp-resources-resource.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Base classes and interfaces for FastMCP resources.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `Resource`
|
| 14 |
|
| 15 |
|
| 16 |
Base class for all resources.
|
|
@@ -18,13 +18,13 @@ Base class for all resources.
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
-
#### `from_function`
|
| 22 |
|
| 23 |
```python
|
| 24 |
from_function(fn: Callable[[], Any], uri: str | AnyUrl, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
| 25 |
```
|
| 26 |
|
| 27 |
-
#### `set_default_mime_type`
|
| 28 |
|
| 29 |
```python
|
| 30 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
@@ -33,7 +33,7 @@ set_default_mime_type(cls, mime_type: str | None) -> str
|
|
| 33 |
Set default MIME type if not provided.
|
| 34 |
|
| 35 |
|
| 36 |
-
#### `set_default_name`
|
| 37 |
|
| 38 |
```python
|
| 39 |
set_default_name(self) -> Self
|
|
@@ -42,7 +42,7 @@ set_default_name(self) -> Self
|
|
| 42 |
Set default name from URI if not provided.
|
| 43 |
|
| 44 |
|
| 45 |
-
#### `to_mcp_resource`
|
| 46 |
|
| 47 |
```python
|
| 48 |
to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
@@ -51,7 +51,7 @@ to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
| 51 |
Convert the resource to an MCPResource.
|
| 52 |
|
| 53 |
|
| 54 |
-
#### `key`
|
| 55 |
|
| 56 |
```python
|
| 57 |
key(self) -> str
|
|
@@ -63,7 +63,7 @@ keys having a certain value, as the same tool loaded from different
|
|
| 63 |
hierarchies of servers may have different keys.
|
| 64 |
|
| 65 |
|
| 66 |
-
### `FunctionResource`
|
| 67 |
|
| 68 |
|
| 69 |
A resource that defers data loading by wrapping a function.
|
|
@@ -80,7 +80,7 @@ The function can return:
|
|
| 80 |
|
| 81 |
**Methods:**
|
| 82 |
|
| 83 |
-
#### `from_function`
|
| 84 |
|
| 85 |
```python
|
| 86 |
from_function(cls, fn: Callable[[], Any], uri: str | AnyUrl, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `Resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L32" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Base class for all resources.
|
|
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L48" target="_blank">β</a></sup>
|
| 22 |
|
| 23 |
```python
|
| 24 |
from_function(fn: Callable[[], Any], uri: str | AnyUrl, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
| 25 |
```
|
| 26 |
|
| 27 |
+
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L69" target="_blank">β</a></sup>
|
| 28 |
|
| 29 |
```python
|
| 30 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
|
|
| 33 |
Set default MIME type if not provided.
|
| 34 |
|
| 35 |
|
| 36 |
+
#### `set_default_name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L76" target="_blank">β</a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
set_default_name(self) -> Self
|
|
|
|
| 42 |
Set default name from URI if not provided.
|
| 43 |
|
| 44 |
|
| 45 |
+
#### `to_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L91" target="_blank">β</a></sup>
|
| 46 |
|
| 47 |
```python
|
| 48 |
to_mcp_resource(self, **overrides: Any) -> MCPResource
|
|
|
|
| 51 |
Convert the resource to an MCPResource.
|
| 52 |
|
| 53 |
|
| 54 |
+
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L105" target="_blank">β</a></sup>
|
| 55 |
|
| 56 |
```python
|
| 57 |
key(self) -> str
|
|
|
|
| 63 |
hierarchies of servers may have different keys.
|
| 64 |
|
| 65 |
|
| 66 |
+
### `FunctionResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L115" target="_blank">β</a></sup>
|
| 67 |
|
| 68 |
|
| 69 |
A resource that defers data loading by wrapping a function.
|
|
|
|
| 80 |
|
| 81 |
**Methods:**
|
| 82 |
|
| 83 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource.py#L131" target="_blank">β</a></sup>
|
| 84 |
|
| 85 |
```python
|
| 86 |
from_function(cls, fn: Callable[[], Any], uri: str | AnyUrl, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
docs/python-sdk/fastmcp-resources-resource_manager.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Resource manager functionality.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `ResourceManager`
|
| 14 |
|
| 15 |
|
| 16 |
Manages FastMCP resources.
|
|
@@ -18,7 +18,7 @@ Manages FastMCP resources.
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
-
#### `mount`
|
| 22 |
|
| 23 |
```python
|
| 24 |
mount(self, server: MountedServer) -> None
|
|
@@ -27,7 +27,7 @@ mount(self, server: MountedServer) -> None
|
|
| 27 |
Adds a mounted server as a source for resources and templates.
|
| 28 |
|
| 29 |
|
| 30 |
-
#### `add_resource_or_template_from_fn`
|
| 31 |
|
| 32 |
```python
|
| 33 |
add_resource_or_template_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource | ResourceTemplate
|
|
@@ -48,7 +48,7 @@ Add a resource or template to the manager from a function.
|
|
| 48 |
- returns the existing resource or template.
|
| 49 |
|
| 50 |
|
| 51 |
-
#### `add_resource_from_fn`
|
| 52 |
|
| 53 |
```python
|
| 54 |
add_resource_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource
|
|
@@ -69,7 +69,7 @@ Add a resource to the manager from a function.
|
|
| 69 |
- returns the existing resource.
|
| 70 |
|
| 71 |
|
| 72 |
-
#### `add_resource`
|
| 73 |
|
| 74 |
```python
|
| 75 |
add_resource(self, resource: Resource) -> Resource
|
|
@@ -83,7 +83,7 @@ will be used as the storage key. To overwrite it, call
|
|
| 83 |
Resource.with_key() before calling this method.
|
| 84 |
|
| 85 |
|
| 86 |
-
#### `add_template_from_fn`
|
| 87 |
|
| 88 |
```python
|
| 89 |
add_template_from_fn(self, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> ResourceTemplate
|
|
@@ -92,7 +92,7 @@ add_template_from_fn(self, fn: Callable[..., Any], uri_template: str, name: str
|
|
| 92 |
Create a template from a function.
|
| 93 |
|
| 94 |
|
| 95 |
-
#### `add_template`
|
| 96 |
|
| 97 |
```python
|
| 98 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `ResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L28" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Manages FastMCP resources.
|
|
|
|
| 18 |
|
| 19 |
**Methods:**
|
| 20 |
|
| 21 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L60" target="_blank">β</a></sup>
|
| 22 |
|
| 23 |
```python
|
| 24 |
mount(self, server: MountedServer) -> None
|
|
|
|
| 27 |
Adds a mounted server as a source for resources and templates.
|
| 28 |
|
| 29 |
|
| 30 |
+
#### `add_resource_or_template_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L182" target="_blank">β</a></sup>
|
| 31 |
|
| 32 |
```python
|
| 33 |
add_resource_or_template_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource | ResourceTemplate
|
|
|
|
| 48 |
- returns the existing resource or template.
|
| 49 |
|
| 50 |
|
| 51 |
+
#### `add_resource_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L230" target="_blank">β</a></sup>
|
| 52 |
|
| 53 |
```python
|
| 54 |
add_resource_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource
|
|
|
|
| 69 |
- returns the existing resource.
|
| 70 |
|
| 71 |
|
| 72 |
+
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L270" target="_blank">β</a></sup>
|
| 73 |
|
| 74 |
```python
|
| 75 |
add_resource(self, resource: Resource) -> Resource
|
|
|
|
| 83 |
Resource.with_key() before calling this method.
|
| 84 |
|
| 85 |
|
| 86 |
+
#### `add_template_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L292" target="_blank">β</a></sup>
|
| 87 |
|
| 88 |
```python
|
| 89 |
add_template_from_fn(self, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> ResourceTemplate
|
|
|
|
| 92 |
Create a template from a function.
|
| 93 |
|
| 94 |
|
| 95 |
+
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/resource_manager.py#L319" target="_blank">β</a></sup>
|
| 96 |
|
| 97 |
```python
|
| 98 |
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
docs/python-sdk/fastmcp-resources-template.mdx
CHANGED
|
@@ -10,13 +10,13 @@ Resource template functionality.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `build_regex`
|
| 14 |
|
| 15 |
```python
|
| 16 |
build_regex(template: str) -> re.Pattern
|
| 17 |
```
|
| 18 |
|
| 19 |
-
### `match_uri_template`
|
| 20 |
|
| 21 |
```python
|
| 22 |
match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None
|
|
@@ -24,7 +24,7 @@ match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None
|
|
| 24 |
|
| 25 |
## Classes
|
| 26 |
|
| 27 |
-
### `ResourceTemplate`
|
| 28 |
|
| 29 |
|
| 30 |
A template for dynamically creating resources.
|
|
@@ -32,13 +32,13 @@ A template for dynamically creating resources.
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
-
#### `from_function`
|
| 36 |
|
| 37 |
```python
|
| 38 |
from_function(fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
| 39 |
```
|
| 40 |
|
| 41 |
-
#### `set_default_mime_type`
|
| 42 |
|
| 43 |
```python
|
| 44 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
@@ -47,7 +47,7 @@ set_default_mime_type(cls, mime_type: str | None) -> str
|
|
| 47 |
Set default MIME type if not provided.
|
| 48 |
|
| 49 |
|
| 50 |
-
#### `matches`
|
| 51 |
|
| 52 |
```python
|
| 53 |
matches(self, uri: str) -> dict[str, Any] | None
|
|
@@ -56,7 +56,7 @@ matches(self, uri: str) -> dict[str, Any] | None
|
|
| 56 |
Check if URI matches template and extract parameters.
|
| 57 |
|
| 58 |
|
| 59 |
-
#### `to_mcp_template`
|
| 60 |
|
| 61 |
```python
|
| 62 |
to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
@@ -65,7 +65,7 @@ to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
| 65 |
Convert the resource template to an MCPResourceTemplate.
|
| 66 |
|
| 67 |
|
| 68 |
-
#### `from_mcp_template`
|
| 69 |
|
| 70 |
```python
|
| 71 |
from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
@@ -74,7 +74,7 @@ from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
| 74 |
Creates a FastMCP ResourceTemplate from a raw MCP ResourceTemplate object.
|
| 75 |
|
| 76 |
|
| 77 |
-
#### `key`
|
| 78 |
|
| 79 |
```python
|
| 80 |
key(self) -> str
|
|
@@ -86,7 +86,7 @@ keys having a certain value, as the same tool loaded from different
|
|
| 86 |
hierarchies of servers may have different keys.
|
| 87 |
|
| 88 |
|
| 89 |
-
### `FunctionResourceTemplate`
|
| 90 |
|
| 91 |
|
| 92 |
A template for dynamically creating resources.
|
|
@@ -94,7 +94,7 @@ A template for dynamically creating resources.
|
|
| 94 |
|
| 95 |
**Methods:**
|
| 96 |
|
| 97 |
-
#### `from_function`
|
| 98 |
|
| 99 |
```python
|
| 100 |
from_function(cls, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `build_regex` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L28" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
build_regex(template: str) -> re.Pattern
|
| 17 |
```
|
| 18 |
|
| 19 |
+
### `match_uri_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L44" target="_blank">β</a></sup>
|
| 20 |
|
| 21 |
```python
|
| 22 |
match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None
|
|
|
|
| 24 |
|
| 25 |
## Classes
|
| 26 |
|
| 27 |
+
### `ResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L52" target="_blank">β</a></sup>
|
| 28 |
|
| 29 |
|
| 30 |
A template for dynamically creating resources.
|
|
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L69" target="_blank">β</a></sup>
|
| 36 |
|
| 37 |
```python
|
| 38 |
from_function(fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
| 39 |
```
|
| 40 |
|
| 41 |
+
#### `set_default_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L90" target="_blank">β</a></sup>
|
| 42 |
|
| 43 |
```python
|
| 44 |
set_default_mime_type(cls, mime_type: str | None) -> str
|
|
|
|
| 47 |
Set default MIME type if not provided.
|
| 48 |
|
| 49 |
|
| 50 |
+
#### `matches` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L96" target="_blank">β</a></sup>
|
| 51 |
|
| 52 |
```python
|
| 53 |
matches(self, uri: str) -> dict[str, Any] | None
|
|
|
|
| 56 |
Check if URI matches template and extract parameters.
|
| 57 |
|
| 58 |
|
| 59 |
+
#### `to_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L124" target="_blank">β</a></sup>
|
| 60 |
|
| 61 |
```python
|
| 62 |
to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
|
|
|
| 65 |
Convert the resource template to an MCPResourceTemplate.
|
| 66 |
|
| 67 |
|
| 68 |
+
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L135" target="_blank">β</a></sup>
|
| 69 |
|
| 70 |
```python
|
| 71 |
from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
|
|
|
| 74 |
Creates a FastMCP ResourceTemplate from a raw MCP ResourceTemplate object.
|
| 75 |
|
| 76 |
|
| 77 |
+
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L148" target="_blank">β</a></sup>
|
| 78 |
|
| 79 |
```python
|
| 80 |
key(self) -> str
|
|
|
|
| 86 |
hierarchies of servers may have different keys.
|
| 87 |
|
| 88 |
|
| 89 |
+
### `FunctionResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L158" target="_blank">β</a></sup>
|
| 90 |
|
| 91 |
|
| 92 |
A template for dynamically creating resources.
|
|
|
|
| 94 |
|
| 95 |
**Methods:**
|
| 96 |
|
| 97 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/template.py#L179" target="_blank">β</a></sup>
|
| 98 |
|
| 99 |
```python
|
| 100 |
from_function(cls, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
docs/python-sdk/fastmcp-resources-types.mdx
CHANGED
|
@@ -10,19 +10,19 @@ Concrete resource implementations.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `TextResource`
|
| 14 |
|
| 15 |
|
| 16 |
A resource that reads from a string.
|
| 17 |
|
| 18 |
|
| 19 |
-
### `BinaryResource`
|
| 20 |
|
| 21 |
|
| 22 |
A resource that reads from bytes.
|
| 23 |
|
| 24 |
|
| 25 |
-
### `FileResource`
|
| 26 |
|
| 27 |
|
| 28 |
A resource that reads from a file.
|
|
@@ -32,7 +32,7 @@ Set is_binary=True to read file as binary data instead of text.
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
-
#### `validate_absolute_path`
|
| 36 |
|
| 37 |
```python
|
| 38 |
validate_absolute_path(cls, path: Path) -> Path
|
|
@@ -41,7 +41,7 @@ validate_absolute_path(cls, path: Path) -> Path
|
|
| 41 |
Ensure path is absolute.
|
| 42 |
|
| 43 |
|
| 44 |
-
#### `set_binary_from_mime_type`
|
| 45 |
|
| 46 |
```python
|
| 47 |
set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool
|
|
@@ -50,13 +50,13 @@ set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool
|
|
| 50 |
Set is_binary based on mime_type if not explicitly set.
|
| 51 |
|
| 52 |
|
| 53 |
-
### `HttpResource`
|
| 54 |
|
| 55 |
|
| 56 |
A resource that reads from an HTTP endpoint.
|
| 57 |
|
| 58 |
|
| 59 |
-
### `DirectoryResource`
|
| 60 |
|
| 61 |
|
| 62 |
A resource that lists files in a directory.
|
|
@@ -64,7 +64,7 @@ A resource that lists files in a directory.
|
|
| 64 |
|
| 65 |
**Methods:**
|
| 66 |
|
| 67 |
-
#### `validate_absolute_path`
|
| 68 |
|
| 69 |
```python
|
| 70 |
validate_absolute_path(cls, path: Path) -> Path
|
|
@@ -73,7 +73,7 @@ validate_absolute_path(cls, path: Path) -> Path
|
|
| 73 |
Ensure path is absolute.
|
| 74 |
|
| 75 |
|
| 76 |
-
#### `list_files`
|
| 77 |
|
| 78 |
```python
|
| 79 |
list_files(self) -> list[Path]
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `TextResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L21" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
A resource that reads from a string.
|
| 17 |
|
| 18 |
|
| 19 |
+
### `BinaryResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L31" target="_blank">β</a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
A resource that reads from bytes.
|
| 23 |
|
| 24 |
|
| 25 |
+
### `FileResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L41" target="_blank">β</a></sup>
|
| 26 |
|
| 27 |
|
| 28 |
A resource that reads from a file.
|
|
|
|
| 32 |
|
| 33 |
**Methods:**
|
| 34 |
|
| 35 |
+
#### `validate_absolute_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L59" target="_blank">β</a></sup>
|
| 36 |
|
| 37 |
```python
|
| 38 |
validate_absolute_path(cls, path: Path) -> Path
|
|
|
|
| 41 |
Ensure path is absolute.
|
| 42 |
|
| 43 |
|
| 44 |
+
#### `set_binary_from_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L67" target="_blank">β</a></sup>
|
| 45 |
|
| 46 |
```python
|
| 47 |
set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool
|
|
|
|
| 50 |
Set is_binary based on mime_type if not explicitly set.
|
| 51 |
|
| 52 |
|
| 53 |
+
### `HttpResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L84" target="_blank">β</a></sup>
|
| 54 |
|
| 55 |
|
| 56 |
A resource that reads from an HTTP endpoint.
|
| 57 |
|
| 58 |
|
| 59 |
+
### `DirectoryResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L100" target="_blank">β</a></sup>
|
| 60 |
|
| 61 |
|
| 62 |
A resource that lists files in a directory.
|
|
|
|
| 64 |
|
| 65 |
**Methods:**
|
| 66 |
|
| 67 |
+
#### `validate_absolute_path` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L116" target="_blank">β</a></sup>
|
| 68 |
|
| 69 |
```python
|
| 70 |
validate_absolute_path(cls, path: Path) -> Path
|
|
|
|
| 73 |
Ensure path is absolute.
|
| 74 |
|
| 75 |
|
| 76 |
+
#### `list_files` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/resources/types.py#L122" target="_blank">β</a></sup>
|
| 77 |
|
| 78 |
```python
|
| 79 |
list_files(self) -> list[Path]
|
docs/python-sdk/fastmcp-server-auth-auth.mdx
CHANGED
|
@@ -7,4 +7,4 @@ sidebarTitle: auth
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `OAuthProvider`
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `OAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L14" target="_blank">β</a></sup>
|
docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx
CHANGED
|
@@ -7,23 +7,23 @@ sidebarTitle: bearer
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `JWKData`
|
| 11 |
|
| 12 |
|
| 13 |
JSON Web Key data structure.
|
| 14 |
|
| 15 |
|
| 16 |
-
### `JWKSData`
|
| 17 |
|
| 18 |
|
| 19 |
JSON Web Key Set data structure.
|
| 20 |
|
| 21 |
|
| 22 |
-
### `RSAKeyPair`
|
| 23 |
|
| 24 |
**Methods:**
|
| 25 |
|
| 26 |
-
#### `generate`
|
| 27 |
|
| 28 |
```python
|
| 29 |
generate(cls) -> 'RSAKeyPair'
|
|
@@ -35,7 +35,7 @@ Generate an RSA key pair for testing.
|
|
| 35 |
- (private_key_pem, public_key_pem)
|
| 36 |
|
| 37 |
|
| 38 |
-
#### `create_token`
|
| 39 |
|
| 40 |
```python
|
| 41 |
create_token(self, subject: str = 'fastmcp-user', issuer: str = 'https://fastmcp.example.com', audience: str | list[str] | None = None, scopes: list[str] | None = None, expires_in_seconds: int = 3600, additional_claims: dict[str, Any] | None = None, kid: str | None = None) -> str
|
|
@@ -57,7 +57,7 @@ Generate a test JWT token for testing purposes.
|
|
| 57 |
- Signed JWT token string
|
| 58 |
|
| 59 |
|
| 60 |
-
### `BearerAuthProvider`
|
| 61 |
|
| 62 |
|
| 63 |
Simple JWT Bearer Token validator for hosted MCP servers.
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `JWKData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L29" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
JSON Web Key data structure.
|
| 14 |
|
| 15 |
|
| 16 |
+
### `JWKSData` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L42" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
|
| 19 |
JSON Web Key Set data structure.
|
| 20 |
|
| 21 |
|
| 22 |
+
### `RSAKeyPair` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L49" target="_blank">β</a></sup>
|
| 23 |
|
| 24 |
**Methods:**
|
| 25 |
|
| 26 |
+
#### `generate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L54" target="_blank">β</a></sup>
|
| 27 |
|
| 28 |
```python
|
| 29 |
generate(cls) -> 'RSAKeyPair'
|
|
|
|
| 35 |
- (private_key_pem, public_key_pem)
|
| 36 |
|
| 37 |
|
| 38 |
+
#### `create_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L88" target="_blank">β</a></sup>
|
| 39 |
|
| 40 |
```python
|
| 41 |
create_token(self, subject: str = 'fastmcp-user', issuer: str = 'https://fastmcp.example.com', audience: str | list[str] | None = None, scopes: list[str] | None = None, expires_in_seconds: int = 3600, additional_claims: dict[str, Any] | None = None, kid: str | None = None) -> str
|
|
|
|
| 57 |
- Signed JWT token string
|
| 58 |
|
| 59 |
|
| 60 |
+
### `BearerAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L149" target="_blank">β</a></sup>
|
| 61 |
|
| 62 |
|
| 63 |
Simple JWT Bearer Token validator for hosted MCP servers.
|
docs/python-sdk/fastmcp-server-auth-providers-bearer_env.mdx
CHANGED
|
@@ -7,13 +7,13 @@ sidebarTitle: bearer_env
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `EnvBearerAuthProviderSettings`
|
| 11 |
|
| 12 |
|
| 13 |
Settings for the BearerAuthProvider.
|
| 14 |
|
| 15 |
|
| 16 |
-
### `EnvBearerAuthProvider`
|
| 17 |
|
| 18 |
|
| 19 |
A BearerAuthProvider that loads settings from environment variables. Any
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `EnvBearerAuthProviderSettings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer_env.py#L8" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
Settings for the BearerAuthProvider.
|
| 14 |
|
| 15 |
|
| 16 |
+
### `EnvBearerAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer_env.py#L24" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
|
| 19 |
A BearerAuthProvider that loads settings from environment variables. Any
|
docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: in_memory
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `InMemoryOAuthProvider`
|
| 11 |
|
| 12 |
|
| 13 |
An in-memory OAuth provider for testing purposes.
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `InMemoryOAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/in_memory.py#L31" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
An in-memory OAuth provider for testing purposes.
|
docs/python-sdk/fastmcp-server-context.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: context
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `set_context`
|
| 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`
|
| 19 |
|
| 20 |
|
| 21 |
Context object providing access to MCP capabilities.
|
|
@@ -53,7 +53,7 @@ The context is optional - tools that don't need it can omit the parameter.
|
|
| 53 |
|
| 54 |
**Methods:**
|
| 55 |
|
| 56 |
-
#### `request_context`
|
| 57 |
|
| 58 |
```python
|
| 59 |
request_context(self) -> RequestContext
|
|
@@ -64,7 +64,7 @@ Access to the underlying request context.
|
|
| 64 |
If called outside of a request context, this will raise a ValueError.
|
| 65 |
|
| 66 |
|
| 67 |
-
#### `client_id`
|
| 68 |
|
| 69 |
```python
|
| 70 |
client_id(self) -> str | None
|
|
@@ -73,7 +73,7 @@ client_id(self) -> str | None
|
|
| 73 |
Get the client ID if available.
|
| 74 |
|
| 75 |
|
| 76 |
-
#### `request_id`
|
| 77 |
|
| 78 |
```python
|
| 79 |
request_id(self) -> str
|
|
@@ -82,7 +82,7 @@ request_id(self) -> str
|
|
| 82 |
Get the unique ID for this request.
|
| 83 |
|
| 84 |
|
| 85 |
-
#### `session_id`
|
| 86 |
|
| 87 |
```python
|
| 88 |
session_id(self) -> str | None
|
|
@@ -99,7 +99,7 @@ the same client session.
|
|
| 99 |
- for stdio and in-memory transports which don't use session IDs.
|
| 100 |
|
| 101 |
|
| 102 |
-
#### `session`
|
| 103 |
|
| 104 |
```python
|
| 105 |
session(self)
|
|
@@ -108,7 +108,7 @@ session(self)
|
|
| 108 |
Access to the underlying session for advanced usage.
|
| 109 |
|
| 110 |
|
| 111 |
-
#### `get_http_request`
|
| 112 |
|
| 113 |
```python
|
| 114 |
get_http_request(self) -> Request
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `set_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L36" target="_blank">β</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#L45" target="_blank">β</a></sup>
|
| 19 |
|
| 20 |
|
| 21 |
Context object providing access to MCP capabilities.
|
|
|
|
| 53 |
|
| 54 |
**Methods:**
|
| 55 |
|
| 56 |
+
#### `request_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L98" target="_blank">β</a></sup>
|
| 57 |
|
| 58 |
```python
|
| 59 |
request_context(self) -> RequestContext
|
|
|
|
| 64 |
If called outside of a request context, this will raise a ValueError.
|
| 65 |
|
| 66 |
|
| 67 |
+
#### `client_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L168" target="_blank">β</a></sup>
|
| 68 |
|
| 69 |
```python
|
| 70 |
client_id(self) -> str | None
|
|
|
|
| 73 |
Get the client ID if available.
|
| 74 |
|
| 75 |
|
| 76 |
+
#### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L177" target="_blank">β</a></sup>
|
| 77 |
|
| 78 |
```python
|
| 79 |
request_id(self) -> str
|
|
|
|
| 82 |
Get the unique ID for this request.
|
| 83 |
|
| 84 |
|
| 85 |
+
#### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L182" target="_blank">β</a></sup>
|
| 86 |
|
| 87 |
```python
|
| 88 |
session_id(self) -> str | None
|
|
|
|
| 99 |
- for stdio and in-memory transports which don't use session IDs.
|
| 100 |
|
| 101 |
|
| 102 |
+
#### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L213" target="_blank">β</a></sup>
|
| 103 |
|
| 104 |
```python
|
| 105 |
session(self)
|
|
|
|
| 108 |
Access to the underlying session for advanced usage.
|
| 109 |
|
| 110 |
|
| 111 |
+
#### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L282" target="_blank">β</a></sup>
|
| 112 |
|
| 113 |
```python
|
| 114 |
get_http_request(self) -> Request
|
docs/python-sdk/fastmcp-server-dependencies.mdx
CHANGED
|
@@ -7,19 +7,19 @@ sidebarTitle: dependencies
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `get_context`
|
| 11 |
|
| 12 |
```python
|
| 13 |
get_context() -> Context
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `get_http_request`
|
| 17 |
|
| 18 |
```python
|
| 19 |
get_http_request() -> Request
|
| 20 |
```
|
| 21 |
|
| 22 |
-
### `get_http_headers`
|
| 23 |
|
| 24 |
```python
|
| 25 |
get_http_headers(include_all: bool = False) -> dict[str, str]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `get_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L27" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
get_context() -> Context
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L39" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
get_http_request() -> Request
|
| 20 |
```
|
| 21 |
|
| 22 |
+
### `get_http_headers` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L48" target="_blank">β</a></sup>
|
| 23 |
|
| 24 |
```python
|
| 25 |
get_http_headers(include_all: bool = False) -> dict[str, str]
|
docs/python-sdk/fastmcp-server-http.mdx
CHANGED
|
@@ -7,13 +7,13 @@ sidebarTitle: http
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `set_http_request`
|
| 11 |
|
| 12 |
```python
|
| 13 |
set_http_request(request: Request) -> Generator[Request, None, None]
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `setup_auth_middleware_and_routes`
|
| 17 |
|
| 18 |
```python
|
| 19 |
setup_auth_middleware_and_routes(auth: OAuthProvider) -> tuple[list[Middleware], list[BaseRoute], list[str]]
|
|
@@ -29,7 +29,7 @@ Set up authentication middleware and routes if auth is enabled.
|
|
| 29 |
- Tuple of (middleware, auth_routes, required_scopes)
|
| 30 |
|
| 31 |
|
| 32 |
-
### `create_base_app`
|
| 33 |
|
| 34 |
```python
|
| 35 |
create_base_app(routes: list[BaseRoute], middleware: list[Middleware], debug: bool = False, lifespan: Callable | None = None) -> StarletteWithLifespan
|
|
@@ -48,7 +48,7 @@ Create a base Starlette app with common middleware and routes.
|
|
| 48 |
- A Starlette application
|
| 49 |
|
| 50 |
|
| 51 |
-
### `create_sse_app`
|
| 52 |
|
| 53 |
```python
|
| 54 |
create_sse_app(server: FastMCP[LifespanResultT], message_path: str, sse_path: str, auth: OAuthProvider | None = None, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
@@ -70,7 +70,7 @@ Returns:
|
|
| 70 |
A Starlette application with RequestContextMiddleware
|
| 71 |
|
| 72 |
|
| 73 |
-
### `create_streamable_http_app`
|
| 74 |
|
| 75 |
```python
|
| 76 |
create_streamable_http_app(server: FastMCP[LifespanResultT], streamable_http_path: str, event_store: EventStore | None = None, auth: OAuthProvider | None = None, json_response: bool = False, stateless_http: bool = False, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
@@ -96,17 +96,17 @@ Return an instance of the StreamableHTTP server app.
|
|
| 96 |
|
| 97 |
## Classes
|
| 98 |
|
| 99 |
-
### `StarletteWithLifespan`
|
| 100 |
|
| 101 |
**Methods:**
|
| 102 |
|
| 103 |
-
#### `lifespan`
|
| 104 |
|
| 105 |
```python
|
| 106 |
lifespan(self) -> Lifespan
|
| 107 |
```
|
| 108 |
|
| 109 |
-
### `RequestContextMiddleware`
|
| 110 |
|
| 111 |
|
| 112 |
Middleware that stores each request in a ContextVar
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `set_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L48" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
set_http_request(request: Request) -> Generator[Request, None, None]
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `setup_auth_middleware_and_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L72" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
setup_auth_middleware_and_routes(auth: OAuthProvider) -> tuple[list[Middleware], list[BaseRoute], list[str]]
|
|
|
|
| 29 |
- Tuple of (middleware, auth_routes, required_scopes)
|
| 30 |
|
| 31 |
|
| 32 |
+
### `create_base_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L110" target="_blank">β</a></sup>
|
| 33 |
|
| 34 |
```python
|
| 35 |
create_base_app(routes: list[BaseRoute], middleware: list[Middleware], debug: bool = False, lifespan: Callable | None = None) -> StarletteWithLifespan
|
|
|
|
| 48 |
- A Starlette application
|
| 49 |
|
| 50 |
|
| 51 |
+
### `create_sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L138" target="_blank">β</a></sup>
|
| 52 |
|
| 53 |
```python
|
| 54 |
create_sse_app(server: FastMCP[LifespanResultT], message_path: str, sse_path: str, auth: OAuthProvider | None = None, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 70 |
A Starlette application with RequestContextMiddleware
|
| 71 |
|
| 72 |
|
| 73 |
+
### `create_streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L246" target="_blank">β</a></sup>
|
| 74 |
|
| 75 |
```python
|
| 76 |
create_streamable_http_app(server: FastMCP[LifespanResultT], streamable_http_path: str, event_store: EventStore | None = None, auth: OAuthProvider | None = None, json_response: bool = False, stateless_http: bool = False, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 96 |
|
| 97 |
## Classes
|
| 98 |
|
| 99 |
+
### `StarletteWithLifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L41" target="_blank">β</a></sup>
|
| 100 |
|
| 101 |
**Methods:**
|
| 102 |
|
| 103 |
+
#### `lifespan` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L43" target="_blank">β</a></sup>
|
| 104 |
|
| 105 |
```python
|
| 106 |
lifespan(self) -> Lifespan
|
| 107 |
```
|
| 108 |
|
| 109 |
+
### `RequestContextMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/http.py#L56" target="_blank">β</a></sup>
|
| 110 |
|
| 111 |
|
| 112 |
Middleware that stores each request in a ContextVar
|
docs/python-sdk/fastmcp-server-middleware-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.middleware`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-server-middleware-error_handling.mdx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: error_handling
|
| 3 |
+
sidebarTitle: error_handling
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.middleware.error_handling`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Error handling middleware for consistent error responses and tracking.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `ErrorHandlingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L15" target="_blank">β</a></sup>
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Middleware that provides consistent error handling and logging.
|
| 17 |
+
|
| 18 |
+
Catches exceptions, logs them appropriately, and converts them to
|
| 19 |
+
proper MCP error responses. Also tracks error patterns for monitoring.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
**Methods:**
|
| 23 |
+
|
| 24 |
+
#### `get_error_stats` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L121" target="_blank">β</a></sup>
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
get_error_stats(self) -> dict[str, int]
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
Get error statistics for monitoring.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
### `RetryMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L126" target="_blank">β</a></sup>
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Middleware that implements automatic retry logic for failed requests.
|
| 37 |
+
|
| 38 |
+
Retries requests that fail with transient errors, using exponential
|
| 39 |
+
backoff to avoid overwhelming the server or external dependencies.
|
| 40 |
+
|
docs/python-sdk/fastmcp-server-middleware-logging.mdx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: logging
|
| 3 |
+
sidebarTitle: logging
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.middleware.logging`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Comprehensive logging middleware for FastMCP servers.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `LoggingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L10" target="_blank">β</a></sup>
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Middleware that provides comprehensive request and response logging.
|
| 17 |
+
|
| 18 |
+
Logs all MCP messages with configurable detail levels. Useful for debugging,
|
| 19 |
+
monitoring, and understanding server usage patterns.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
### `StructuredLoggingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L87" target="_blank">β</a></sup>
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Middleware that provides structured JSON logging for better log analysis.
|
| 26 |
+
|
| 27 |
+
Outputs structured logs that are easier to parse and analyze with log
|
| 28 |
+
aggregation tools like ELK stack, Splunk, or cloud logging services.
|
| 29 |
+
|
docs/python-sdk/fastmcp-server-middleware-middleware.mdx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: middleware
|
| 3 |
+
sidebarTitle: middleware
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.middleware.middleware`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `make_middleware_wrapper` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L106" target="_blank">β</a></sup>
|
| 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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L36" target="_blank">β</a></sup>
|
| 25 |
+
|
| 26 |
+
### `CallToolResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L56" target="_blank">β</a></sup>
|
| 27 |
+
|
| 28 |
+
### `ListToolsResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L62" target="_blank">β</a></sup>
|
| 29 |
+
|
| 30 |
+
### `ListResourcesResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L67" target="_blank">β</a></sup>
|
| 31 |
+
|
| 32 |
+
### `ListResourceTemplatesResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L72" target="_blank">β</a></sup>
|
| 33 |
+
|
| 34 |
+
### `ListPromptsResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L77" target="_blank">β</a></sup>
|
| 35 |
+
|
| 36 |
+
### `ServerResultProtocol` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L82" target="_blank">β</a></sup>
|
| 37 |
+
|
| 38 |
+
### `MiddlewareContext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L87" target="_blank">β</a></sup>
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Unified context for all middleware operations.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
**Methods:**
|
| 45 |
+
|
| 46 |
+
#### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L102" target="_blank">β</a></sup>
|
| 47 |
+
|
| 48 |
+
```python
|
| 49 |
+
copy(self, **kwargs: Any) -> MiddlewareContext[T]
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### `Middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/middleware.py#L119" target="_blank">β</a></sup>
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Base class for FastMCP middleware with dispatching hooks.
|
| 56 |
+
|
docs/python-sdk/fastmcp-server-middleware-rate_limiting.mdx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: rate_limiting
|
| 3 |
+
sidebarTitle: rate_limiting
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.middleware.rate_limiting`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Rate limiting middleware for protecting FastMCP servers from abuse.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `RateLimitError` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L15" target="_blank">β</a></sup>
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Error raised when rate limit is exceeded.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
### `TokenBucketRateLimiter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L22" target="_blank">β</a></sup>
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Token bucket implementation for rate limiting.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
### `SlidingWindowRateLimiter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L61" target="_blank">β</a></sup>
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Sliding window rate limiter implementation.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
### `RateLimitingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L92" target="_blank">β</a></sup>
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Middleware that implements rate limiting to prevent server abuse.
|
| 35 |
+
|
| 36 |
+
Uses a token bucket algorithm by default, allowing for burst traffic
|
| 37 |
+
while maintaining a sustainable long-term rate.
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
### `SlidingWindowRateLimitingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/rate_limiting.py#L170" target="_blank">β</a></sup>
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Middleware that implements sliding window rate limiting.
|
| 44 |
+
|
| 45 |
+
Uses a sliding window approach which provides more precise rate limiting
|
| 46 |
+
but uses more memory to track individual request timestamps.
|
| 47 |
+
|
docs/python-sdk/fastmcp-server-middleware-timing.mdx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: timing
|
| 3 |
+
sidebarTitle: timing
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.middleware.timing`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Timing middleware for measuring and logging request performance.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `TimingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L10" target="_blank">β</a></sup>
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Middleware that logs the execution time of requests.
|
| 17 |
+
|
| 18 |
+
Only measures and logs timing for request messages (not notifications).
|
| 19 |
+
Provides insights into performance characteristics of your MCP server.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
### `DetailedTimingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L60" target="_blank">β</a></sup>
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Enhanced timing middleware with per-operation breakdowns.
|
| 26 |
+
|
| 27 |
+
Provides detailed timing information for different types of MCP operations,
|
| 28 |
+
allowing you to identify performance bottlenecks in specific operations.
|
| 29 |
+
|
docs/python-sdk/fastmcp-server-openapi.mdx
CHANGED
|
@@ -10,13 +10,13 @@ FastMCP server implementation for OpenAPI integration.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `MCPType`
|
| 14 |
|
| 15 |
|
| 16 |
Type of FastMCP component to create from a route.
|
| 17 |
|
| 18 |
|
| 19 |
-
### `RouteType`
|
| 20 |
|
| 21 |
|
| 22 |
Deprecated: Use MCPType instead.
|
|
@@ -24,31 +24,31 @@ Deprecated: Use MCPType instead.
|
|
| 24 |
This enum is kept for backward compatibility and will be removed in a future version.
|
| 25 |
|
| 26 |
|
| 27 |
-
### `RouteMap`
|
| 28 |
|
| 29 |
|
| 30 |
Mapping configuration for HTTP routes to FastMCP component types.
|
| 31 |
|
| 32 |
|
| 33 |
-
### `OpenAPITool`
|
| 34 |
|
| 35 |
|
| 36 |
Tool implementation for OpenAPI endpoints.
|
| 37 |
|
| 38 |
|
| 39 |
-
### `OpenAPIResource`
|
| 40 |
|
| 41 |
|
| 42 |
Resource implementation for OpenAPI endpoints.
|
| 43 |
|
| 44 |
|
| 45 |
-
### `OpenAPIResourceTemplate`
|
| 46 |
|
| 47 |
|
| 48 |
Resource template implementation for OpenAPI endpoints.
|
| 49 |
|
| 50 |
|
| 51 |
-
### `FastMCPOpenAPI`
|
| 52 |
|
| 53 |
|
| 54 |
FastMCP server implementation that creates components from an OpenAPI schema.
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `MCPType` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L76" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Type of FastMCP component to create from a route.
|
| 17 |
|
| 18 |
|
| 19 |
+
### `RouteType` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L95" target="_blank">β</a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
Deprecated: Use MCPType instead.
|
|
|
|
| 24 |
This enum is kept for backward compatibility and will be removed in a future version.
|
| 25 |
|
| 26 |
|
| 27 |
+
### `RouteMap` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L109" target="_blank">β</a></sup>
|
| 28 |
|
| 29 |
|
| 30 |
Mapping configuration for HTTP routes to FastMCP component types.
|
| 31 |
|
| 32 |
|
| 33 |
+
### `OpenAPITool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L227" target="_blank">β</a></sup>
|
| 34 |
|
| 35 |
|
| 36 |
Tool implementation for OpenAPI endpoints.
|
| 37 |
|
| 38 |
|
| 39 |
+
### `OpenAPIResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L478" target="_blank">β</a></sup>
|
| 40 |
|
| 41 |
|
| 42 |
Resource implementation for OpenAPI endpoints.
|
| 43 |
|
| 44 |
|
| 45 |
+
### `OpenAPIResourceTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L597" target="_blank">β</a></sup>
|
| 46 |
|
| 47 |
|
| 48 |
Resource template implementation for OpenAPI endpoints.
|
| 49 |
|
| 50 |
|
| 51 |
+
### `FastMCPOpenAPI` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/openapi.py#L651" target="_blank">β</a></sup>
|
| 52 |
|
| 53 |
|
| 54 |
FastMCP server implementation that creates components from an OpenAPI schema.
|
docs/python-sdk/fastmcp-server-proxy.mdx
CHANGED
|
@@ -7,25 +7,25 @@ sidebarTitle: proxy
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `ProxyToolManager`
|
| 11 |
|
| 12 |
|
| 13 |
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
| 14 |
|
| 15 |
|
| 16 |
-
### `ProxyResourceManager`
|
| 17 |
|
| 18 |
|
| 19 |
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
| 20 |
|
| 21 |
|
| 22 |
-
### `ProxyPromptManager`
|
| 23 |
|
| 24 |
|
| 25 |
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
| 26 |
|
| 27 |
|
| 28 |
-
### `ProxyTool`
|
| 29 |
|
| 30 |
|
| 31 |
A Tool that represents and executes a tool on a remote server.
|
|
@@ -33,7 +33,7 @@ A Tool that represents and executes a tool on a remote server.
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
-
#### `from_mcp_tool`
|
| 37 |
|
| 38 |
```python
|
| 39 |
from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
@@ -42,7 +42,7 @@ from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
| 42 |
Factory method to create a ProxyTool from a raw MCP tool schema.
|
| 43 |
|
| 44 |
|
| 45 |
-
### `ProxyResource`
|
| 46 |
|
| 47 |
|
| 48 |
A Resource that represents and reads a resource from a remote server.
|
|
@@ -50,7 +50,7 @@ A Resource that represents and reads a resource from a remote server.
|
|
| 50 |
|
| 51 |
**Methods:**
|
| 52 |
|
| 53 |
-
#### `from_mcp_resource`
|
| 54 |
|
| 55 |
```python
|
| 56 |
from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> ProxyResource
|
|
@@ -59,7 +59,7 @@ from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> Prox
|
|
| 59 |
Factory method to create a ProxyResource from a raw MCP resource schema.
|
| 60 |
|
| 61 |
|
| 62 |
-
### `ProxyTemplate`
|
| 63 |
|
| 64 |
|
| 65 |
A ResourceTemplate that represents and creates resources from a remote server template.
|
|
@@ -67,7 +67,7 @@ A ResourceTemplate that represents and creates resources from a remote server te
|
|
| 67 |
|
| 68 |
**Methods:**
|
| 69 |
|
| 70 |
-
#### `from_mcp_template`
|
| 71 |
|
| 72 |
```python
|
| 73 |
from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate) -> ProxyTemplate
|
|
@@ -76,7 +76,7 @@ from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate)
|
|
| 76 |
Factory method to create a ProxyTemplate from a raw MCP template schema.
|
| 77 |
|
| 78 |
|
| 79 |
-
### `ProxyPrompt`
|
| 80 |
|
| 81 |
|
| 82 |
A Prompt that represents and renders a prompt from a remote server.
|
|
@@ -84,7 +84,7 @@ A Prompt that represents and renders a prompt from a remote server.
|
|
| 84 |
|
| 85 |
**Methods:**
|
| 86 |
|
| 87 |
-
#### `from_mcp_prompt`
|
| 88 |
|
| 89 |
```python
|
| 90 |
from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPrompt
|
|
@@ -93,7 +93,7 @@ from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPromp
|
|
| 93 |
Factory method to create a ProxyPrompt from a raw MCP prompt schema.
|
| 94 |
|
| 95 |
|
| 96 |
-
### `FastMCPProxy`
|
| 97 |
|
| 98 |
|
| 99 |
A FastMCP server that acts as a proxy to a remote MCP-compliant server.
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ProxyToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L36" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
| 14 |
|
| 15 |
|
| 16 |
+
### `ProxyResourceManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L81" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
|
| 19 |
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
| 20 |
|
| 21 |
|
| 22 |
+
### `ProxyPromptManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L159" target="_blank">β</a></sup>
|
| 23 |
|
| 24 |
|
| 25 |
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
| 26 |
|
| 27 |
|
| 28 |
+
### `ProxyTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L209" target="_blank">β</a></sup>
|
| 29 |
|
| 30 |
|
| 31 |
A Tool that represents and executes a tool on a remote server.
|
|
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
+
#### `from_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L219" target="_blank">β</a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
|
|
|
| 42 |
Factory method to create a ProxyTool from a raw MCP tool schema.
|
| 43 |
|
| 44 |
|
| 45 |
+
### `ProxyResource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L246" target="_blank">β</a></sup>
|
| 46 |
|
| 47 |
|
| 48 |
A Resource that represents and reads a resource from a remote server.
|
|
|
|
| 50 |
|
| 51 |
**Methods:**
|
| 52 |
|
| 53 |
+
#### `from_mcp_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L260" target="_blank">β</a></sup>
|
| 54 |
|
| 55 |
```python
|
| 56 |
from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> ProxyResource
|
|
|
|
| 59 |
Factory method to create a ProxyResource from a raw MCP resource schema.
|
| 60 |
|
| 61 |
|
| 62 |
+
### `ProxyTemplate` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L287" target="_blank">β</a></sup>
|
| 63 |
|
| 64 |
|
| 65 |
A ResourceTemplate that represents and creates resources from a remote server template.
|
|
|
|
| 67 |
|
| 68 |
**Methods:**
|
| 69 |
|
| 70 |
+
#### `from_mcp_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L297" target="_blank">β</a></sup>
|
| 71 |
|
| 72 |
```python
|
| 73 |
from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate) -> ProxyTemplate
|
|
|
|
| 76 |
Factory method to create a ProxyTemplate from a raw MCP template schema.
|
| 77 |
|
| 78 |
|
| 79 |
+
### `ProxyPrompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L343" target="_blank">β</a></sup>
|
| 80 |
|
| 81 |
|
| 82 |
A Prompt that represents and renders a prompt from a remote server.
|
|
|
|
| 84 |
|
| 85 |
**Methods:**
|
| 86 |
|
| 87 |
+
#### `from_mcp_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L355" target="_blank">β</a></sup>
|
| 88 |
|
| 89 |
```python
|
| 90 |
from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPrompt
|
|
|
|
| 93 |
Factory method to create a ProxyPrompt from a raw MCP prompt schema.
|
| 94 |
|
| 95 |
|
| 96 |
+
### `FastMCPProxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/proxy.py#L381" target="_blank">β</a></sup>
|
| 97 |
|
| 98 |
|
| 99 |
A FastMCP server that acts as a proxy to a remote MCP-compliant server.
|
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 |
-
### `add_resource_prefix`
|
| 14 |
|
| 15 |
```python
|
| 16 |
add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -19,26 +19,27 @@ add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'p
|
|
| 19 |
|
| 20 |
Add a prefix to a resource URI.
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
"resource://prefix/path/to/resource" # with new style
|
| 32 |
-
>>> add_resource_prefix("resource://path/to/resource", "prefix")
|
| 33 |
-
"prefix+resource://path/to/resource" # with legacy style
|
| 34 |
-
>>> add_resource_prefix("resource:///absolute/path", "prefix")
|
| 35 |
-
"resource://prefix//absolute/path" # with new style
|
| 36 |
|
| 37 |
-
Raises:
|
| 38 |
-
ValueError: If the URI doesn't match the expected protocol://path format
|
| 39 |
-
|
| 40 |
|
| 41 |
-
### `remove_resource_prefix`
|
| 42 |
|
| 43 |
```python
|
| 44 |
remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
@@ -47,26 +48,28 @@ remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol',
|
|
| 47 |
|
| 48 |
Remove a prefix from a resource URI.
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
>>> remove_resource_prefix("resource://prefix/path/to/resource", "prefix")
|
| 59 |
-
"resource://path/to/resource" # with new style
|
| 60 |
-
>>> remove_resource_prefix("prefix+resource://path/to/resource", "prefix")
|
| 61 |
-
"resource://path/to/resource" # with legacy style
|
| 62 |
-
>>> remove_resource_prefix("resource://prefix//absolute/path", "prefix")
|
| 63 |
-
"resource:///absolute/path" # with new style
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
```python
|
| 72 |
has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> bool
|
|
@@ -75,53 +78,54 @@ has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'p
|
|
| 75 |
|
| 76 |
Check if a resource URI has a specific prefix.
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
Raises:
|
| 94 |
-
ValueError: If the URI doesn't match the expected protocol://path format
|
| 95 |
-
|
| 96 |
|
| 97 |
## Classes
|
| 98 |
|
| 99 |
-
### `FastMCP`
|
| 100 |
|
| 101 |
**Methods:**
|
| 102 |
|
| 103 |
-
#### `settings`
|
| 104 |
|
| 105 |
```python
|
| 106 |
settings(self) -> Settings
|
| 107 |
```
|
| 108 |
|
| 109 |
-
#### `name`
|
| 110 |
|
| 111 |
```python
|
| 112 |
name(self) -> str
|
| 113 |
```
|
| 114 |
|
| 115 |
-
#### `instructions`
|
| 116 |
|
| 117 |
```python
|
| 118 |
instructions(self) -> str | None
|
| 119 |
```
|
| 120 |
|
| 121 |
-
#### `run`
|
| 122 |
|
| 123 |
```python
|
| 124 |
-
run(self, transport:
|
| 125 |
```
|
| 126 |
|
| 127 |
Run the FastMCP server. Note this is a synchronous function.
|
|
@@ -130,13 +134,13 @@ Run the FastMCP server. Note this is a synchronous function.
|
|
| 130 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 131 |
|
| 132 |
|
| 133 |
-
#### `add_middleware`
|
| 134 |
|
| 135 |
```python
|
| 136 |
add_middleware(self, middleware: Middleware) -> None
|
| 137 |
```
|
| 138 |
|
| 139 |
-
#### `custom_route`
|
| 140 |
|
| 141 |
```python
|
| 142 |
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True)
|
|
@@ -157,7 +161,7 @@ Starlette's reverse URL lookup feature)
|
|
| 157 |
- `include_in_schema`: Whether to include in OpenAPI schema, defaults to True
|
| 158 |
|
| 159 |
|
| 160 |
-
#### `add_tool`
|
| 161 |
|
| 162 |
```python
|
| 163 |
add_tool(self, tool: Tool) -> None
|
|
@@ -172,7 +176,7 @@ with the Context type annotation. See the @tool decorator for examples.
|
|
| 172 |
- `tool`: The Tool instance to register
|
| 173 |
|
| 174 |
|
| 175 |
-
#### `remove_tool`
|
| 176 |
|
| 177 |
```python
|
| 178 |
remove_tool(self, name: str) -> None
|
|
@@ -187,19 +191,19 @@ Remove a tool from the server.
|
|
| 187 |
- `NotFoundError`: If the tool is not found
|
| 188 |
|
| 189 |
|
| 190 |
-
#### `tool`
|
| 191 |
|
| 192 |
```python
|
| 193 |
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 194 |
```
|
| 195 |
|
| 196 |
-
#### `tool`
|
| 197 |
|
| 198 |
```python
|
| 199 |
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 200 |
```
|
| 201 |
|
| 202 |
-
#### `tool`
|
| 203 |
|
| 204 |
```python
|
| 205 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
@@ -228,7 +232,7 @@ This decorator supports multiple calling patterns:
|
|
| 228 |
- `enabled`: Optional boolean to enable or disable the tool
|
| 229 |
|
| 230 |
|
| 231 |
-
#### `add_resource`
|
| 232 |
|
| 233 |
```python
|
| 234 |
add_resource(self, resource: Resource) -> None
|
|
@@ -240,7 +244,7 @@ Add a resource to the server.
|
|
| 240 |
- `resource`: A Resource instance to add
|
| 241 |
|
| 242 |
|
| 243 |
-
#### `add_template`
|
| 244 |
|
| 245 |
```python
|
| 246 |
add_template(self, template: ResourceTemplate) -> None
|
|
@@ -252,7 +256,7 @@ Add a resource template to the server.
|
|
| 252 |
- `template`: A ResourceTemplate instance to add
|
| 253 |
|
| 254 |
|
| 255 |
-
#### `add_resource_fn`
|
| 256 |
|
| 257 |
```python
|
| 258 |
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
|
|
@@ -272,7 +276,7 @@ has parameters, it will be registered as a template resource.
|
|
| 272 |
- `tags`: Optional set of tags for categorizing the resource
|
| 273 |
|
| 274 |
|
| 275 |
-
#### `resource`
|
| 276 |
|
| 277 |
```python
|
| 278 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
@@ -302,7 +306,7 @@ has parameters, it will be registered as a template resource.
|
|
| 302 |
- `enabled`: Optional boolean to enable or disable the resource
|
| 303 |
|
| 304 |
|
| 305 |
-
#### `add_prompt`
|
| 306 |
|
| 307 |
```python
|
| 308 |
add_prompt(self, prompt: Prompt) -> None
|
|
@@ -314,19 +318,19 @@ Add a prompt to the server.
|
|
| 314 |
- `prompt`: A Prompt instance to add
|
| 315 |
|
| 316 |
|
| 317 |
-
#### `prompt`
|
| 318 |
|
| 319 |
```python
|
| 320 |
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 321 |
```
|
| 322 |
|
| 323 |
-
#### `prompt`
|
| 324 |
|
| 325 |
```python
|
| 326 |
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 327 |
```
|
| 328 |
|
| 329 |
-
#### `prompt`
|
| 330 |
|
| 331 |
```python
|
| 332 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
@@ -400,7 +404,7 @@ Decorator to register a prompt.
|
|
| 400 |
server.prompt(my_function, name="custom_name")
|
| 401 |
|
| 402 |
|
| 403 |
-
#### `sse_app`
|
| 404 |
|
| 405 |
```python
|
| 406 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -414,7 +418,7 @@ Create a Starlette app for the SSE server.
|
|
| 414 |
- `middleware`: A list of middleware to apply to the app
|
| 415 |
|
| 416 |
|
| 417 |
-
#### `streamable_http_app`
|
| 418 |
|
| 419 |
```python
|
| 420 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
@@ -427,10 +431,10 @@ Create a Starlette app for the StreamableHTTP server.
|
|
| 427 |
- `middleware`: A list of middleware to apply to the app
|
| 428 |
|
| 429 |
|
| 430 |
-
#### `http_app`
|
| 431 |
|
| 432 |
```python
|
| 433 |
-
http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None, json_response: bool | None = None, stateless_http: bool | None = None, transport: Literal['streamable-http', 'sse'] = '
|
| 434 |
```
|
| 435 |
|
| 436 |
Create a Starlette app using the specified HTTP transport.
|
|
@@ -444,7 +448,7 @@ Create a Starlette app using the specified HTTP transport.
|
|
| 444 |
- A Starlette application configured with the specified transport
|
| 445 |
|
| 446 |
|
| 447 |
-
#### `mount`
|
| 448 |
|
| 449 |
```python
|
| 450 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
@@ -498,7 +502,7 @@ automatically determined based on whether the server has a custom lifespan
|
|
| 498 |
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 499 |
|
| 500 |
|
| 501 |
-
#### `from_openapi`
|
| 502 |
|
| 503 |
```python
|
| 504 |
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
|
|
@@ -507,7 +511,7 @@ from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route
|
|
| 507 |
Create a FastMCP server from an OpenAPI specification.
|
| 508 |
|
| 509 |
|
| 510 |
-
#### `from_fastapi`
|
| 511 |
|
| 512 |
```python
|
| 513 |
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
|
|
@@ -516,7 +520,7 @@ from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap]
|
|
| 516 |
Create a FastMCP server from a FastAPI application.
|
| 517 |
|
| 518 |
|
| 519 |
-
#### `as_proxy`
|
| 520 |
|
| 521 |
```python
|
| 522 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
@@ -530,7 +534,7 @@ instance or any value accepted as the ``transport`` argument of
|
|
| 530 |
``Client`` constructor.
|
| 531 |
|
| 532 |
|
| 533 |
-
#### `from_client`
|
| 534 |
|
| 535 |
```python
|
| 536 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
@@ -539,4 +543,4 @@ from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPPr
|
|
| 539 |
Create a FastMCP proxy server from a FastMCP client.
|
| 540 |
|
| 541 |
|
| 542 |
-
### `MountedServer`
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `add_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1865" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
|
|
| 19 |
|
| 20 |
Add a prefix to a resource URI.
|
| 21 |
|
| 22 |
+
**Args:**
|
| 23 |
+
- `uri`: The original resource URI
|
| 24 |
+
- `prefix`: The prefix to add
|
| 25 |
+
|
| 26 |
+
**Returns:**
|
| 27 |
+
- The resource URI with the prefix added
|
| 28 |
+
|
| 29 |
+
**Examples:**
|
| 30 |
|
| 31 |
+
>>> add_resource_prefix("resource://path/to/resource", "prefix")
|
| 32 |
+
"resource://prefix/path/to/resource" # with new style
|
| 33 |
+
>>> add_resource_prefix("resource://path/to/resource", "prefix")
|
| 34 |
+
"prefix+resource://path/to/resource" # with legacy style
|
| 35 |
+
>>> add_resource_prefix("resource:///absolute/path", "prefix")
|
| 36 |
+
"resource://prefix//absolute/path" # with new style
|
| 37 |
|
| 38 |
+
**Raises:**
|
| 39 |
+
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
### `remove_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1916" target="_blank">β</a></sup>
|
| 43 |
|
| 44 |
```python
|
| 45 |
remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
|
|
|
| 48 |
|
| 49 |
Remove a prefix from a resource URI.
|
| 50 |
|
| 51 |
+
**Args:**
|
| 52 |
+
- `uri`: The resource URI with a prefix
|
| 53 |
+
- `prefix`: The prefix to remove
|
| 54 |
+
- `prefix_format`: The format of the prefix to remove
|
| 55 |
+
|
| 56 |
+
Returns:
|
| 57 |
+
The resource URI with the prefix removed
|
| 58 |
|
| 59 |
+
**Examples:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
>>> remove_resource_prefix("resource://prefix/path/to/resource", "prefix")
|
| 62 |
+
"resource://path/to/resource" # with new style
|
| 63 |
+
>>> remove_resource_prefix("prefix+resource://path/to/resource", "prefix")
|
| 64 |
+
"resource://path/to/resource" # with legacy style
|
| 65 |
+
>>> remove_resource_prefix("resource://prefix//absolute/path", "prefix")
|
| 66 |
+
"resource:///absolute/path" # with new style
|
| 67 |
|
| 68 |
+
**Raises:**
|
| 69 |
+
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
### `has_resource_prefix` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1974" target="_blank">β</a></sup>
|
| 73 |
|
| 74 |
```python
|
| 75 |
has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> bool
|
|
|
|
| 78 |
|
| 79 |
Check if a resource URI has a specific prefix.
|
| 80 |
|
| 81 |
+
**Args:**
|
| 82 |
+
- `uri`: The resource URI to check
|
| 83 |
+
- `prefix`: The prefix to look for
|
| 84 |
|
| 85 |
+
**Returns:**
|
| 86 |
+
- True if the URI has the specified prefix, False otherwise
|
| 87 |
|
| 88 |
+
**Examples:**
|
| 89 |
+
|
| 90 |
+
>>> has_resource_prefix("resource://prefix/path/to/resource", "prefix")
|
| 91 |
+
True # with new style
|
| 92 |
+
>>> has_resource_prefix("prefix+resource://path/to/resource", "prefix")
|
| 93 |
+
True # with legacy style
|
| 94 |
+
>>> has_resource_prefix("resource://other/path/to/resource", "prefix")
|
| 95 |
+
False
|
| 96 |
+
|
| 97 |
+
**Raises:**
|
| 98 |
+
- `ValueError`: If the URI doesn't match the expected protocol\://path format
|
| 99 |
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
## Classes
|
| 102 |
|
| 103 |
+
### `FastMCP` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L113" target="_blank">β</a></sup>
|
| 104 |
|
| 105 |
**Methods:**
|
| 106 |
|
| 107 |
+
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L264" target="_blank">β</a></sup>
|
| 108 |
|
| 109 |
```python
|
| 110 |
settings(self) -> Settings
|
| 111 |
```
|
| 112 |
|
| 113 |
+
#### `name` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L275" target="_blank">β</a></sup>
|
| 114 |
|
| 115 |
```python
|
| 116 |
name(self) -> str
|
| 117 |
```
|
| 118 |
|
| 119 |
+
#### `instructions` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L279" target="_blank">β</a></sup>
|
| 120 |
|
| 121 |
```python
|
| 122 |
instructions(self) -> str | None
|
| 123 |
```
|
| 124 |
|
| 125 |
+
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L304" target="_blank">β</a></sup>
|
| 126 |
|
| 127 |
```python
|
| 128 |
+
run(self, transport: Transport | None = None, **transport_kwargs: Any) -> None
|
| 129 |
```
|
| 130 |
|
| 131 |
Run the FastMCP server. Note this is a synchronous function.
|
|
|
|
| 134 |
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 135 |
|
| 136 |
|
| 137 |
+
#### `add_middleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L338" target="_blank">β</a></sup>
|
| 138 |
|
| 139 |
```python
|
| 140 |
add_middleware(self, middleware: Middleware) -> None
|
| 141 |
```
|
| 142 |
|
| 143 |
+
#### `custom_route` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L383" target="_blank">β</a></sup>
|
| 144 |
|
| 145 |
```python
|
| 146 |
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True)
|
|
|
|
| 161 |
- `include_in_schema`: Whether to include in OpenAPI schema, defaults to True
|
| 162 |
|
| 163 |
|
| 164 |
+
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L738" target="_blank">β</a></sup>
|
| 165 |
|
| 166 |
```python
|
| 167 |
add_tool(self, tool: Tool) -> None
|
|
|
|
| 176 |
- `tool`: The Tool instance to register
|
| 177 |
|
| 178 |
|
| 179 |
+
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L750" target="_blank">β</a></sup>
|
| 180 |
|
| 181 |
```python
|
| 182 |
remove_tool(self, name: str) -> None
|
|
|
|
| 191 |
- `NotFoundError`: If the tool is not found
|
| 192 |
|
| 193 |
|
| 194 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L763" target="_blank">β</a></sup>
|
| 195 |
|
| 196 |
```python
|
| 197 |
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 198 |
```
|
| 199 |
|
| 200 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L776" target="_blank">β</a></sup>
|
| 201 |
|
| 202 |
```python
|
| 203 |
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 204 |
```
|
| 205 |
|
| 206 |
+
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L788" target="_blank">β</a></sup>
|
| 207 |
|
| 208 |
```python
|
| 209 |
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
|
|
|
| 232 |
- `enabled`: Optional boolean to enable or disable the tool
|
| 233 |
|
| 234 |
|
| 235 |
+
#### `add_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L904" target="_blank">β</a></sup>
|
| 236 |
|
| 237 |
```python
|
| 238 |
add_resource(self, resource: Resource) -> None
|
|
|
|
| 244 |
- `resource`: A Resource instance to add
|
| 245 |
|
| 246 |
|
| 247 |
+
#### `add_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L914" target="_blank">β</a></sup>
|
| 248 |
|
| 249 |
```python
|
| 250 |
add_template(self, template: ResourceTemplate) -> None
|
|
|
|
| 256 |
- `template`: A ResourceTemplate instance to add
|
| 257 |
|
| 258 |
|
| 259 |
+
#### `add_resource_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L922" target="_blank">β</a></sup>
|
| 260 |
|
| 261 |
```python
|
| 262 |
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
|
|
|
|
| 276 |
- `tags`: Optional set of tags for categorizing the resource
|
| 277 |
|
| 278 |
|
| 279 |
+
#### `resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L961" target="_blank">β</a></sup>
|
| 280 |
|
| 281 |
```python
|
| 282 |
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
|
|
|
| 306 |
- `enabled`: Optional boolean to enable or disable the resource
|
| 307 |
|
| 308 |
|
| 309 |
+
#### `add_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1081" target="_blank">β</a></sup>
|
| 310 |
|
| 311 |
```python
|
| 312 |
add_prompt(self, prompt: Prompt) -> None
|
|
|
|
| 318 |
- `prompt`: A Prompt instance to add
|
| 319 |
|
| 320 |
|
| 321 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1091" target="_blank">β</a></sup>
|
| 322 |
|
| 323 |
```python
|
| 324 |
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 325 |
```
|
| 326 |
|
| 327 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1102" target="_blank">β</a></sup>
|
| 328 |
|
| 329 |
```python
|
| 330 |
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 331 |
```
|
| 332 |
|
| 333 |
+
#### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1112" target="_blank">β</a></sup>
|
| 334 |
|
| 335 |
```python
|
| 336 |
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
|
|
|
| 404 |
server.prompt(my_function, name="custom_name")
|
| 405 |
|
| 406 |
|
| 407 |
+
#### `sse_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1330" target="_blank">β</a></sup>
|
| 408 |
|
| 409 |
```python
|
| 410 |
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 418 |
- `middleware`: A list of middleware to apply to the app
|
| 419 |
|
| 420 |
|
| 421 |
+
#### `streamable_http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1361" target="_blank">β</a></sup>
|
| 422 |
|
| 423 |
```python
|
| 424 |
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
|
|
|
| 431 |
- `middleware`: A list of middleware to apply to the app
|
| 432 |
|
| 433 |
|
| 434 |
+
#### `http_app` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1382" target="_blank">β</a></sup>
|
| 435 |
|
| 436 |
```python
|
| 437 |
+
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
|
| 438 |
```
|
| 439 |
|
| 440 |
Create a Starlette app using the specified HTTP transport.
|
|
|
|
| 448 |
- A Starlette application configured with the specified transport
|
| 449 |
|
| 450 |
|
| 451 |
+
#### `mount` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1456" target="_blank">β</a></sup>
|
| 452 |
|
| 453 |
```python
|
| 454 |
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
|
|
|
| 502 |
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 503 |
|
| 504 |
|
| 505 |
+
#### `from_openapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1706" target="_blank">β</a></sup>
|
| 506 |
|
| 507 |
```python
|
| 508 |
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
|
|
|
|
| 511 |
Create a FastMCP server from an OpenAPI specification.
|
| 512 |
|
| 513 |
|
| 514 |
+
#### `from_fastapi` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1734" target="_blank">β</a></sup>
|
| 515 |
|
| 516 |
```python
|
| 517 |
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
|
|
|
|
| 520 |
Create a FastMCP server from a FastAPI application.
|
| 521 |
|
| 522 |
|
| 523 |
+
#### `as_proxy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1776" target="_blank">β</a></sup>
|
| 524 |
|
| 525 |
```python
|
| 526 |
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
|
|
|
| 534 |
``Client`` constructor.
|
| 535 |
|
| 536 |
|
| 537 |
+
#### `from_client` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1806" target="_blank">β</a></sup>
|
| 538 |
|
| 539 |
```python
|
| 540 |
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
|
|
|
| 543 |
Create a FastMCP proxy server from a FastMCP client.
|
| 544 |
|
| 545 |
|
| 546 |
+
### `MountedServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L1859" target="_blank">β</a></sup>
|
docs/python-sdk/fastmcp-settings.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: settings
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `ExtendedEnvSettingsSource`
|
| 11 |
|
| 12 |
|
| 13 |
A special EnvSettingsSource that allows for multiple env var prefixes to be used.
|
|
@@ -17,15 +17,15 @@ Raises a deprecation warning if the old `FASTMCP_SERVER_` prefix is used.
|
|
| 17 |
|
| 18 |
**Methods:**
|
| 19 |
|
| 20 |
-
#### `get_field_value`
|
| 21 |
|
| 22 |
```python
|
| 23 |
get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool]
|
| 24 |
```
|
| 25 |
|
| 26 |
-
### `ExtendedSettingsConfigDict`
|
| 27 |
|
| 28 |
-
### `Settings`
|
| 29 |
|
| 30 |
|
| 31 |
FastMCP settings.
|
|
@@ -33,13 +33,13 @@ FastMCP settings.
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
-
#### `settings_customise_sources`
|
| 37 |
|
| 38 |
```python
|
| 39 |
settings_customise_sources(cls, settings_cls: type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> tuple[PydanticBaseSettingsSource, ...]
|
| 40 |
```
|
| 41 |
|
| 42 |
-
#### `settings`
|
| 43 |
|
| 44 |
```python
|
| 45 |
settings(self) -> Self
|
|
@@ -49,7 +49,7 @@ This property is for backwards compatibility with FastMCP < 2.8.0,
|
|
| 49 |
which accessed fastmcp.settings.settings
|
| 50 |
|
| 51 |
|
| 52 |
-
#### `setup_logging`
|
| 53 |
|
| 54 |
```python
|
| 55 |
setup_logging(self) -> Self
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ExtendedEnvSettingsSource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L26" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
A special EnvSettingsSource that allows for multiple env var prefixes to be used.
|
|
|
|
| 17 |
|
| 18 |
**Methods:**
|
| 19 |
|
| 20 |
+
#### `get_field_value` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L33" target="_blank">β</a></sup>
|
| 21 |
|
| 22 |
```python
|
| 23 |
get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool]
|
| 24 |
```
|
| 25 |
|
| 26 |
+
### `ExtendedSettingsConfigDict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L53" target="_blank">β</a></sup>
|
| 27 |
|
| 28 |
+
### `Settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L57" target="_blank">β</a></sup>
|
| 29 |
|
| 30 |
|
| 31 |
FastMCP settings.
|
|
|
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
+
#### `settings_customise_sources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L69" target="_blank">β</a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
settings_customise_sources(cls, settings_cls: type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> tuple[PydanticBaseSettingsSource, ...]
|
| 40 |
```
|
| 41 |
|
| 42 |
+
#### `settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L87" target="_blank">β</a></sup>
|
| 43 |
|
| 44 |
```python
|
| 45 |
settings(self) -> Self
|
|
|
|
| 49 |
which accessed fastmcp.settings.settings
|
| 50 |
|
| 51 |
|
| 52 |
+
#### `setup_logging` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/settings.py#L182" target="_blank">β</a></sup>
|
| 53 |
|
| 54 |
```python
|
| 55 |
setup_logging(self) -> Self
|
docs/python-sdk/fastmcp-tools-tool.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: tool
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `default_serializer`
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_serializer(data: Any) -> str
|
|
@@ -15,7 +15,7 @@ default_serializer(data: Any) -> str
|
|
| 15 |
|
| 16 |
## Classes
|
| 17 |
|
| 18 |
-
### `Tool`
|
| 19 |
|
| 20 |
|
| 21 |
Internal tool registration info.
|
|
@@ -23,13 +23,13 @@ Internal tool registration info.
|
|
| 23 |
|
| 24 |
**Methods:**
|
| 25 |
|
| 26 |
-
#### `to_mcp_tool`
|
| 27 |
|
| 28 |
```python
|
| 29 |
to_mcp_tool(self, **overrides: Any) -> MCPTool
|
| 30 |
```
|
| 31 |
|
| 32 |
-
#### `from_function`
|
| 33 |
|
| 34 |
```python
|
| 35 |
from_function(fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
|
@@ -38,17 +38,17 @@ from_function(fn: Callable[..., Any], name: str | None = None, description: str
|
|
| 38 |
Create a Tool from a function.
|
| 39 |
|
| 40 |
|
| 41 |
-
#### `from_tool`
|
| 42 |
|
| 43 |
```python
|
| 44 |
from_tool(cls, tool: Tool, transform_fn: Callable[..., Any] | None = None, name: str | None = None, transform_args: dict[str, ArgTransform] | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
| 45 |
```
|
| 46 |
|
| 47 |
-
### `FunctionTool`
|
| 48 |
|
| 49 |
**Methods:**
|
| 50 |
|
| 51 |
-
#### `from_function`
|
| 52 |
|
| 53 |
```python
|
| 54 |
from_function(cls, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
|
@@ -57,11 +57,11 @@ from_function(cls, fn: Callable[..., Any], name: str | None = None, description:
|
|
| 57 |
Create a Tool from a function.
|
| 58 |
|
| 59 |
|
| 60 |
-
### `ParsedFunction`
|
| 61 |
|
| 62 |
**Methods:**
|
| 63 |
|
| 64 |
-
#### `from_function`
|
| 65 |
|
| 66 |
```python
|
| 67 |
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: 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#L34" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
default_serializer(data: Any) -> str
|
|
|
|
| 15 |
|
| 16 |
## Classes
|
| 17 |
|
| 18 |
+
### `Tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L38" target="_blank">β</a></sup>
|
| 19 |
|
| 20 |
|
| 21 |
Internal tool registration info.
|
|
|
|
| 23 |
|
| 24 |
**Methods:**
|
| 25 |
|
| 26 |
+
#### `to_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L49" target="_blank">β</a></sup>
|
| 27 |
|
| 28 |
```python
|
| 29 |
to_mcp_tool(self, **overrides: Any) -> MCPTool
|
| 30 |
```
|
| 31 |
|
| 32 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L59" target="_blank">β</a></sup>
|
| 33 |
|
| 34 |
```python
|
| 35 |
from_function(fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
|
|
|
| 38 |
Create a Tool from a function.
|
| 39 |
|
| 40 |
|
| 41 |
+
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L86" target="_blank">β</a></sup>
|
| 42 |
|
| 43 |
```python
|
| 44 |
from_tool(cls, tool: Tool, transform_fn: Callable[..., Any] | None = None, name: str | None = None, transform_args: dict[str, ArgTransform] | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
| 45 |
```
|
| 46 |
|
| 47 |
+
### `FunctionTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L113" target="_blank">β</a></sup>
|
| 48 |
|
| 49 |
**Methods:**
|
| 50 |
|
| 51 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L117" target="_blank">β</a></sup>
|
| 52 |
|
| 53 |
```python
|
| 54 |
from_function(cls, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
|
|
|
| 57 |
Create a Tool from a function.
|
| 58 |
|
| 59 |
|
| 60 |
+
### `ParsedFunction` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L194" target="_blank">β</a></sup>
|
| 61 |
|
| 62 |
**Methods:**
|
| 63 |
|
| 64 |
+
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L201" target="_blank">β</a></sup>
|
| 65 |
|
| 66 |
```python
|
| 67 |
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: 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`
|
| 11 |
|
| 12 |
|
| 13 |
Manages FastMCP tools.
|
|
@@ -15,7 +15,7 @@ Manages FastMCP tools.
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
-
#### `mount`
|
| 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 |
-
#### `add_tool_from_fn`
|
| 28 |
|
| 29 |
```python
|
| 30 |
add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, exclude_args: list[str] | None = None) -> Tool
|
|
@@ -33,7 +33,7 @@ add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, descript
|
|
| 33 |
Add a tool to the server.
|
| 34 |
|
| 35 |
|
| 36 |
-
#### `add_tool`
|
| 37 |
|
| 38 |
```python
|
| 39 |
add_tool(self, tool: Tool) -> Tool
|
|
@@ -42,7 +42,7 @@ add_tool(self, tool: Tool) -> Tool
|
|
| 42 |
Register a tool with the server.
|
| 43 |
|
| 44 |
|
| 45 |
-
#### `remove_tool`
|
| 46 |
|
| 47 |
```python
|
| 48 |
remove_tool(self, key: str) -> None
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ToolManager` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L22" target="_blank">β</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#L46" target="_blank">β</a></sup>
|
| 19 |
|
| 20 |
```python
|
| 21 |
mount(self, server: MountedServer) -> None
|
|
|
|
| 24 |
Adds a mounted server as a source for tools.
|
| 25 |
|
| 26 |
|
| 27 |
+
#### `add_tool_from_fn` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L113" target="_blank">β</a></sup>
|
| 28 |
|
| 29 |
```python
|
| 30 |
add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, exclude_args: list[str] | None = None) -> Tool
|
|
|
|
| 33 |
Add a tool to the server.
|
| 34 |
|
| 35 |
|
| 36 |
+
#### `add_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L142" target="_blank">β</a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
add_tool(self, tool: Tool) -> Tool
|
|
|
|
| 42 |
Register a tool with the server.
|
| 43 |
|
| 44 |
|
| 45 |
+
#### `remove_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_manager.py#L159" target="_blank">β</a></sup>
|
| 46 |
|
| 47 |
```python
|
| 48 |
remove_tool(self, key: str) -> None
|
docs/python-sdk/fastmcp-tools-tool_transform.mdx
CHANGED
|
@@ -7,58 +7,49 @@ sidebarTitle: tool_transform
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `ArgTransform`
|
| 11 |
|
| 12 |
|
| 13 |
Configuration for transforming a parent tool's argument.
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
name: New name for the argument. Use None to keep original name, or ... for no change.
|
| 21 |
-
description: New description for the argument. Use None to remove description, or ... for no change.
|
| 22 |
-
default: New default value for the argument. Use ... for no change.
|
| 23 |
-
default_factory: Callable that returns a default value. Cannot be used with default.
|
| 24 |
-
type: New type for the argument. Use ... for no change.
|
| 25 |
-
hide: If True, hide this argument from clients but pass a constant value to parent.
|
| 26 |
-
required: If True, make argument required (remove default). Use ... for no change.
|
| 27 |
-
examples: Examples for the argument. Use ... for no change.
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
ArgTransform(name="new_name")
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
A tool that is transformed from another tool.
|
|
@@ -74,7 +65,7 @@ with transformed arguments.
|
|
| 74 |
|
| 75 |
**Methods:**
|
| 76 |
|
| 77 |
-
#### `from_tool`
|
| 78 |
|
| 79 |
```python
|
| 80 |
from_tool(cls, tool: Tool, name: str | None = None, description: str | None = None, tags: set[str] | None = None, transform_fn: Callable[..., Any] | None = None, transform_args: dict[str, ArgTransform] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `ArgTransform` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L85" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
Configuration for transforming a parent tool's argument.
|
| 14 |
|
| 15 |
+
This class allows fine-grained control over how individual arguments are transformed
|
| 16 |
+
when creating a new tool from an existing one. You can rename arguments, change their
|
| 17 |
+
descriptions, add default values, or hide them from clients while passing constants.
|
| 18 |
|
| 19 |
+
**Examples:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Rename argument 'old_name' to 'new_name'
|
| 22 |
+
ArgTransform(name="new_name")
|
|
|
|
| 23 |
|
| 24 |
+
# Change description only
|
| 25 |
+
ArgTransform(description="Updated description")
|
| 26 |
|
| 27 |
+
# Add a default value (makes argument optional)
|
| 28 |
+
ArgTransform(default=42)
|
| 29 |
|
| 30 |
+
# Add a default factory (makes argument optional)
|
| 31 |
+
ArgTransform(default_factory=lambda: time.time())
|
| 32 |
|
| 33 |
+
# Change the type
|
| 34 |
+
ArgTransform(type=str)
|
| 35 |
|
| 36 |
+
# Hide the argument entirely from clients
|
| 37 |
+
ArgTransform(hide=True)
|
| 38 |
|
| 39 |
+
# Hide argument but pass a constant value to parent
|
| 40 |
+
ArgTransform(hide=True, default="constant_value")
|
| 41 |
|
| 42 |
+
# Hide argument but pass a factory-generated value to parent
|
| 43 |
+
ArgTransform(hide=True, default_factory=lambda: uuid.uuid4().hex)
|
| 44 |
|
| 45 |
+
# Make an optional parameter required (removes any default)
|
| 46 |
+
ArgTransform(required=True)
|
| 47 |
|
| 48 |
+
# Combine multiple transformations
|
| 49 |
+
ArgTransform(name="new_name", description="New desc", default=None, type=int)
|
|
|
|
| 50 |
|
| 51 |
+
|
| 52 |
+
### `TransformedTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L179" target="_blank">β</a></sup>
|
| 53 |
|
| 54 |
|
| 55 |
A tool that is transformed from another tool.
|
|
|
|
| 65 |
|
| 66 |
**Methods:**
|
| 67 |
|
| 68 |
+
#### `from_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool_transform.py#L260" target="_blank">β</a></sup>
|
| 69 |
|
| 70 |
```python
|
| 71 |
from_tool(cls, tool: Tool, name: str | None = None, description: str | None = None, tags: set[str] | None = None, transform_fn: Callable[..., Any] | None = None, transform_args: dict[str, ArgTransform] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
docs/python-sdk/fastmcp-utilities-cache.mdx
CHANGED
|
@@ -7,23 +7,23 @@ sidebarTitle: cache
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `TimedCache`
|
| 11 |
|
| 12 |
**Methods:**
|
| 13 |
|
| 14 |
-
#### `set`
|
| 15 |
|
| 16 |
```python
|
| 17 |
set(self, key: Any, value: Any) -> None
|
| 18 |
```
|
| 19 |
|
| 20 |
-
#### `get`
|
| 21 |
|
| 22 |
```python
|
| 23 |
get(self, key: Any) -> Any
|
| 24 |
```
|
| 25 |
|
| 26 |
-
#### `clear`
|
| 27 |
|
| 28 |
```python
|
| 29 |
clear(self) -> None
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `TimedCache` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/cache.py#L7" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
**Methods:**
|
| 13 |
|
| 14 |
+
#### `set` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/cache.py#L14" target="_blank">β</a></sup>
|
| 15 |
|
| 16 |
```python
|
| 17 |
set(self, key: Any, value: Any) -> None
|
| 18 |
```
|
| 19 |
|
| 20 |
+
#### `get` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/cache.py#L18" target="_blank">β</a></sup>
|
| 21 |
|
| 22 |
```python
|
| 23 |
get(self, key: Any) -> Any
|
| 24 |
```
|
| 25 |
|
| 26 |
+
#### `clear` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/cache.py#L25" target="_blank">β</a></sup>
|
| 27 |
|
| 28 |
```python
|
| 29 |
clear(self) -> None
|
docs/python-sdk/fastmcp-utilities-components.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: components
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
-
### `FastMCPComponent`
|
| 11 |
|
| 12 |
|
| 13 |
Base class for FastMCP tools, prompts, resources, and resource templates.
|
|
@@ -15,7 +15,7 @@ Base class for FastMCP tools, prompts, resources, and resource templates.
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
-
#### `key`
|
| 19 |
|
| 20 |
```python
|
| 21 |
key(self) -> str
|
|
@@ -27,13 +27,13 @@ keys having a certain value, as the same tool loaded from different
|
|
| 27 |
hierarchies of servers may have different keys.
|
| 28 |
|
| 29 |
|
| 30 |
-
#### `with_key`
|
| 31 |
|
| 32 |
```python
|
| 33 |
with_key(self, key: str) -> Self
|
| 34 |
```
|
| 35 |
|
| 36 |
-
#### `enable`
|
| 37 |
|
| 38 |
```python
|
| 39 |
enable(self) -> None
|
|
@@ -42,7 +42,7 @@ enable(self) -> None
|
|
| 42 |
Enable the component.
|
| 43 |
|
| 44 |
|
| 45 |
-
#### `disable`
|
| 46 |
|
| 47 |
```python
|
| 48 |
disable(self) -> None
|
|
|
|
| 7 |
|
| 8 |
## Classes
|
| 9 |
|
| 10 |
+
### `FastMCPComponent` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L21" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
|
| 13 |
Base class for FastMCP tools, prompts, resources, and resource templates.
|
|
|
|
| 15 |
|
| 16 |
**Methods:**
|
| 17 |
|
| 18 |
+
#### `key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L48" target="_blank">β</a></sup>
|
| 19 |
|
| 20 |
```python
|
| 21 |
key(self) -> str
|
|
|
|
| 27 |
hierarchies of servers may have different keys.
|
| 28 |
|
| 29 |
|
| 30 |
+
#### `with_key` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L57" target="_blank">β</a></sup>
|
| 31 |
|
| 32 |
```python
|
| 33 |
with_key(self, key: str) -> Self
|
| 34 |
```
|
| 35 |
|
| 36 |
+
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L69" target="_blank">β</a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
enable(self) -> None
|
|
|
|
| 42 |
Enable the component.
|
| 43 |
|
| 44 |
|
| 45 |
+
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L73" target="_blank">β</a></sup>
|
| 46 |
|
| 47 |
```python
|
| 48 |
disable(self) -> None
|
docs/python-sdk/fastmcp-utilities-exceptions.mdx
CHANGED
|
@@ -7,13 +7,13 @@ sidebarTitle: exceptions
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `iter_exc`
|
| 11 |
|
| 12 |
```python
|
| 13 |
iter_exc(group: BaseExceptionGroup)
|
| 14 |
```
|
| 15 |
|
| 16 |
-
### `get_catch_handlers`
|
| 17 |
|
| 18 |
```python
|
| 19 |
get_catch_handlers() -> Mapping[type[BaseException] | Iterable[type[BaseException]], Callable[[BaseExceptionGroup[Any]], Any]]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `iter_exc` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/exceptions.py#L12" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
iter_exc(group: BaseExceptionGroup)
|
| 14 |
```
|
| 15 |
|
| 16 |
+
### `get_catch_handlers` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/exceptions.py#L42" target="_blank">β</a></sup>
|
| 17 |
|
| 18 |
```python
|
| 19 |
get_catch_handlers() -> Mapping[type[BaseException] | Iterable[type[BaseException]], Callable[[BaseExceptionGroup[Any]], Any]]
|
docs/python-sdk/fastmcp-utilities-http.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: http
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `find_available_port`
|
| 11 |
|
| 12 |
```python
|
| 13 |
find_available_port() -> int
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `find_available_port` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/http.py#L4" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
find_available_port() -> int
|
docs/python-sdk/fastmcp-utilities-inspect.mdx
CHANGED
|
@@ -10,31 +10,31 @@ Utilities for inspecting FastMCP instances.
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
-
### `ToolInfo`
|
| 14 |
|
| 15 |
|
| 16 |
Information about a tool.
|
| 17 |
|
| 18 |
|
| 19 |
-
### `PromptInfo`
|
| 20 |
|
| 21 |
|
| 22 |
Information about a prompt.
|
| 23 |
|
| 24 |
|
| 25 |
-
### `ResourceInfo`
|
| 26 |
|
| 27 |
|
| 28 |
Information about a resource.
|
| 29 |
|
| 30 |
|
| 31 |
-
### `TemplateInfo`
|
| 32 |
|
| 33 |
|
| 34 |
Information about a resource template.
|
| 35 |
|
| 36 |
|
| 37 |
-
### `FastMCPInfo`
|
| 38 |
|
| 39 |
|
| 40 |
Information extracted from a FastMCP instance.
|
|
|
|
| 10 |
|
| 11 |
## Classes
|
| 12 |
|
| 13 |
+
### `ToolInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/inspect.py#L16" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
|
| 16 |
Information about a tool.
|
| 17 |
|
| 18 |
|
| 19 |
+
### `PromptInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/inspect.py#L29" target="_blank">β</a></sup>
|
| 20 |
|
| 21 |
|
| 22 |
Information about a prompt.
|
| 23 |
|
| 24 |
|
| 25 |
+
### `ResourceInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/inspect.py#L41" target="_blank">β</a></sup>
|
| 26 |
|
| 27 |
|
| 28 |
Information about a resource.
|
| 29 |
|
| 30 |
|
| 31 |
+
### `TemplateInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/inspect.py#L54" target="_blank">β</a></sup>
|
| 32 |
|
| 33 |
|
| 34 |
Information about a resource template.
|
| 35 |
|
| 36 |
|
| 37 |
+
### `FastMCPInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/inspect.py#L67" target="_blank">β</a></sup>
|
| 38 |
|
| 39 |
|
| 40 |
Information extracted from a FastMCP instance.
|
docs/python-sdk/fastmcp-utilities-json_schema.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: json_schema
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `compress_schema`
|
| 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#L130" target="_blank">β</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-logging.mdx
CHANGED
|
@@ -10,7 +10,7 @@ Logging utilities for FastMCP.
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
-
### `get_logger`
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_logger(name: str) -> logging.Logger
|
|
@@ -26,7 +26,7 @@ Get a logger nested under FastMCP namespace.
|
|
| 26 |
- a configured logger instance
|
| 27 |
|
| 28 |
|
| 29 |
-
### `configure_logging`
|
| 30 |
|
| 31 |
```python
|
| 32 |
configure_logging(level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | int = 'INFO', logger: logging.Logger | None = None, enable_rich_tracebacks: bool = True) -> None
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `get_logger` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/logging.py#L10" target="_blank">β</a></sup>
|
| 14 |
|
| 15 |
```python
|
| 16 |
get_logger(name: str) -> logging.Logger
|
|
|
|
| 26 |
- a configured logger instance
|
| 27 |
|
| 28 |
|
| 29 |
+
### `configure_logging` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/logging.py#L22" target="_blank">β</a></sup>
|
| 30 |
|
| 31 |
```python
|
| 32 |
configure_logging(level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | int = 'INFO', logger: logging.Logger | None = None, enable_rich_tracebacks: bool = True) -> None
|
docs/python-sdk/fastmcp-utilities-mcp_config.mdx
CHANGED
|
@@ -7,10 +7,10 @@ sidebarTitle: mcp_config
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `infer_transport_type_from_url`
|
| 11 |
|
| 12 |
```python
|
| 13 |
-
infer_transport_type_from_url(url: str | AnyUrl) -> Literal['
|
| 14 |
```
|
| 15 |
|
| 16 |
|
|
@@ -19,31 +19,31 @@ Infer the appropriate transport type from the given URL.
|
|
| 19 |
|
| 20 |
## Classes
|
| 21 |
|
| 22 |
-
### `StdioMCPServer`
|
| 23 |
|
| 24 |
**Methods:**
|
| 25 |
|
| 26 |
-
#### `to_transport`
|
| 27 |
|
| 28 |
```python
|
| 29 |
to_transport(self) -> StdioTransport
|
| 30 |
```
|
| 31 |
|
| 32 |
-
### `RemoteMCPServer`
|
| 33 |
|
| 34 |
**Methods:**
|
| 35 |
|
| 36 |
-
#### `to_transport`
|
| 37 |
|
| 38 |
```python
|
| 39 |
to_transport(self) -> StreamableHttpTransport | SSETransport
|
| 40 |
```
|
| 41 |
|
| 42 |
-
### `MCPConfig`
|
| 43 |
|
| 44 |
**Methods:**
|
| 45 |
|
| 46 |
-
#### `from_dict`
|
| 47 |
|
| 48 |
```python
|
| 49 |
from_dict(cls, config: dict[str, Any]) -> MCPConfig
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `infer_transport_type_from_url` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L20" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
+
infer_transport_type_from_url(url: str | AnyUrl) -> Literal['http', 'sse']
|
| 14 |
```
|
| 15 |
|
| 16 |
|
|
|
|
| 19 |
|
| 20 |
## Classes
|
| 21 |
|
| 22 |
+
### `StdioMCPServer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L40" target="_blank">β</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" target="_blank">β</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" target="_blank">β</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" target="_blank">β</a></sup>
|
| 37 |
|
| 38 |
```python
|
| 39 |
to_transport(self) -> StreamableHttpTransport | SSETransport
|
| 40 |
```
|
| 41 |
|
| 42 |
+
### `MCPConfig` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L88" target="_blank">β</a></sup>
|
| 43 |
|
| 44 |
**Methods:**
|
| 45 |
|
| 46 |
+
#### `from_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/mcp_config.py#L92" target="_blank">β</a></sup>
|
| 47 |
|
| 48 |
```python
|
| 49 |
from_dict(cls, config: dict[str, Any]) -> MCPConfig
|
docs/python-sdk/fastmcp-utilities-openapi.mdx
CHANGED
|
@@ -7,7 +7,7 @@ sidebarTitle: openapi
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `parse_openapi_to_http_routes`
|
| 11 |
|
| 12 |
```python
|
| 13 |
parse_openapi_to_http_routes(openapi_dict: dict[str, Any]) -> list[HTTPRoute]
|
|
@@ -20,7 +20,7 @@ using the openapi-pydantic library.
|
|
| 20 |
Supports both OpenAPI 3.0.x and 3.1.x versions.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `clean_schema_for_display`
|
| 24 |
|
| 25 |
```python
|
| 26 |
clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
@@ -30,7 +30,7 @@ clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
| 30 |
Clean up a schema dictionary for display by removing internal/complex fields.
|
| 31 |
|
| 32 |
|
| 33 |
-
### `generate_example_from_schema`
|
| 34 |
|
| 35 |
```python
|
| 36 |
generate_example_from_schema(schema: JsonSchema | None) -> Any
|
|
@@ -41,7 +41,7 @@ Generate a simple example value from a JSON schema dictionary.
|
|
| 41 |
Very basic implementation focusing on types.
|
| 42 |
|
| 43 |
|
| 44 |
-
### `format_json_for_description`
|
| 45 |
|
| 46 |
```python
|
| 47 |
format_json_for_description(data: Any, indent: int = 2) -> str
|
|
@@ -51,7 +51,7 @@ format_json_for_description(data: Any, indent: int = 2) -> str
|
|
| 51 |
Formats Python data as a JSON string block for markdown.
|
| 52 |
|
| 53 |
|
| 54 |
-
### `format_description_with_responses`
|
| 55 |
|
| 56 |
```python
|
| 57 |
format_description_with_responses(base_description: str, responses: dict[str, Any], parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
|
|
@@ -76,31 +76,31 @@ including its description, whether it is required, and its content schema.
|
|
| 76 |
|
| 77 |
## Classes
|
| 78 |
|
| 79 |
-
### `ParameterInfo`
|
| 80 |
|
| 81 |
|
| 82 |
Represents a single parameter for an HTTP operation in our IR.
|
| 83 |
|
| 84 |
|
| 85 |
-
### `RequestBodyInfo`
|
| 86 |
|
| 87 |
|
| 88 |
Represents the request body for an HTTP operation in our IR.
|
| 89 |
|
| 90 |
|
| 91 |
-
### `ResponseInfo`
|
| 92 |
|
| 93 |
|
| 94 |
Represents response information in our IR.
|
| 95 |
|
| 96 |
|
| 97 |
-
### `HTTPRoute`
|
| 98 |
|
| 99 |
|
| 100 |
Intermediate Representation for a single OpenAPI operation.
|
| 101 |
|
| 102 |
|
| 103 |
-
### `OpenAPIParser`
|
| 104 |
|
| 105 |
|
| 106 |
Unified parser for OpenAPI schemas with generic type parameters to handle both 3.0 and 3.1.
|
|
@@ -108,7 +108,7 @@ Unified parser for OpenAPI schemas with generic type parameters to handle both 3
|
|
| 108 |
|
| 109 |
**Methods:**
|
| 110 |
|
| 111 |
-
#### `parse`
|
| 112 |
|
| 113 |
```python
|
| 114 |
parse(self) -> list[HTTPRoute]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `parse_openapi_to_http_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L112" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
parse_openapi_to_http_routes(openapi_dict: dict[str, Any]) -> list[HTTPRoute]
|
|
|
|
| 20 |
Supports both OpenAPI 3.0.x and 3.1.x versions.
|
| 21 |
|
| 22 |
|
| 23 |
+
### `clean_schema_for_display` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L570" target="_blank">β</a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
clean_schema_for_display(schema: JsonSchema | None) -> JsonSchema | None
|
|
|
|
| 30 |
Clean up a schema dictionary for display by removing internal/complex fields.
|
| 31 |
|
| 32 |
|
| 33 |
+
### `generate_example_from_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L630" target="_blank">β</a></sup>
|
| 34 |
|
| 35 |
```python
|
| 36 |
generate_example_from_schema(schema: JsonSchema | None) -> Any
|
|
|
|
| 41 |
Very basic implementation focusing on types.
|
| 42 |
|
| 43 |
|
| 44 |
+
### `format_json_for_description` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L713" target="_blank">β</a></sup>
|
| 45 |
|
| 46 |
```python
|
| 47 |
format_json_for_description(data: Any, indent: int = 2) -> str
|
|
|
|
| 51 |
Formats Python data as a JSON string block for markdown.
|
| 52 |
|
| 53 |
|
| 54 |
+
### `format_description_with_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L722" target="_blank">β</a></sup>
|
| 55 |
|
| 56 |
```python
|
| 57 |
format_description_with_responses(base_description: str, responses: dict[str, Any], parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
|
|
|
|
| 76 |
|
| 77 |
## Classes
|
| 78 |
|
| 79 |
+
### `ParameterInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L42" target="_blank">β</a></sup>
|
| 80 |
|
| 81 |
|
| 82 |
Represents a single parameter for an HTTP operation in our IR.
|
| 83 |
|
| 84 |
|
| 85 |
+
### `RequestBodyInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L52" target="_blank">β</a></sup>
|
| 86 |
|
| 87 |
|
| 88 |
Represents the request body for an HTTP operation in our IR.
|
| 89 |
|
| 90 |
|
| 91 |
+
### `ResponseInfo` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L62" target="_blank">β</a></sup>
|
| 92 |
|
| 93 |
|
| 94 |
Represents response information in our IR.
|
| 95 |
|
| 96 |
|
| 97 |
+
### `HTTPRoute` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L70" target="_blank">β</a></sup>
|
| 98 |
|
| 99 |
|
| 100 |
Intermediate Representation for a single OpenAPI operation.
|
| 101 |
|
| 102 |
|
| 103 |
+
### `OpenAPIParser` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L164" target="_blank">β</a></sup>
|
| 104 |
|
| 105 |
|
| 106 |
Unified parser for OpenAPI schemas with generic type parameters to handle both 3.0 and 3.1.
|
|
|
|
| 108 |
|
| 109 |
**Methods:**
|
| 110 |
|
| 111 |
+
#### `parse` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi.py#L469" target="_blank">β</a></sup>
|
| 112 |
|
| 113 |
```python
|
| 114 |
parse(self) -> list[HTTPRoute]
|
docs/python-sdk/fastmcp-utilities-tests.mdx
CHANGED
|
@@ -7,20 +7,20 @@ sidebarTitle: tests
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
-
### `temporary_settings`
|
| 11 |
|
| 12 |
```python
|
| 13 |
temporary_settings(**kwargs: Any)
|
| 14 |
```
|
| 15 |
|
| 16 |
|
| 17 |
-
Temporarily override
|
| 18 |
|
| 19 |
**Args:**
|
| 20 |
- `**kwargs`: The settings to override, including nested settings.
|
| 21 |
|
| 22 |
|
| 23 |
-
### `run_server_in_process`
|
| 24 |
|
| 25 |
```python
|
| 26 |
run_server_in_process(server_fn: Callable[..., None], *args, **kwargs) -> Generator[str, None, None]
|
|
|
|
| 7 |
|
| 8 |
## Functions
|
| 9 |
|
| 10 |
+
### `temporary_settings` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/tests.py#L21" target="_blank">β</a></sup>
|
| 11 |
|
| 12 |
```python
|
| 13 |
temporary_settings(**kwargs: Any)
|
| 14 |
```
|
| 15 |
|
| 16 |
|
| 17 |
+
Temporarily override FastMCP setting values.
|
| 18 |
|
| 19 |
**Args:**
|
| 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#L74" target="_blank">β</a></sup>
|
| 24 |
|
| 25 |
```python
|
| 26 |
run_server_in_process(server_fn: Callable[..., None], *args, **kwargs) -> Generator[str, None, None]
|
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`
|
| 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`
|
| 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`
|
| 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`
|
| 50 |
|
| 51 |
```python
|
| 52 |
find_kwarg_by_type(fn: Callable, kwarg_type: type) -> str | None
|
|
@@ -60,13 +60,13 @@ Includes union types that contain the kwarg_type, as well as Annotated types.
|
|
| 60 |
|
| 61 |
## Classes
|
| 62 |
|
| 63 |
-
### `FastMCPBaseModel`
|
| 64 |
|
| 65 |
|
| 66 |
Base model for FastMCP models.
|
| 67 |
|
| 68 |
|
| 69 |
-
### `Image`
|
| 70 |
|
| 71 |
|
| 72 |
Helper class for returning images from tools.
|
|
@@ -74,7 +74,7 @@ Helper class for returning images from tools.
|
|
| 74 |
|
| 75 |
**Methods:**
|
| 76 |
|
| 77 |
-
#### `to_image_content`
|
| 78 |
|
| 79 |
```python
|
| 80 |
to_image_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> ImageContent
|
|
@@ -83,7 +83,7 @@ to_image_content(self, mime_type: str | None = None, annotations: Annotations |
|
|
| 83 |
Convert to MCP ImageContent.
|
| 84 |
|
| 85 |
|
| 86 |
-
### `Audio`
|
| 87 |
|
| 88 |
|
| 89 |
Helper class for returning audio from tools.
|
|
@@ -91,13 +91,13 @@ Helper class for returning audio from tools.
|
|
| 91 |
|
| 92 |
**Methods:**
|
| 93 |
|
| 94 |
-
#### `to_audio_content`
|
| 95 |
|
| 96 |
```python
|
| 97 |
to_audio_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> AudioContent
|
| 98 |
```
|
| 99 |
|
| 100 |
-
### `File`
|
| 101 |
|
| 102 |
|
| 103 |
Helper class for returning audio from tools.
|
|
@@ -105,7 +105,7 @@ Helper class for returning audio from tools.
|
|
| 105 |
|
| 106 |
**Methods:**
|
| 107 |
|
| 108 |
-
#### `to_resource_content`
|
| 109 |
|
| 110 |
```python
|
| 111 |
to_resource_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> EmbeddedResource
|
|
|
|
| 10 |
|
| 11 |
## Functions
|
| 12 |
|
| 13 |
+
### `get_cached_typeadapter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L35" target="_blank">β</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#L45" target="_blank">β</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#L55" target="_blank">β</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#L77" target="_blank">β</a></sup>
|
| 50 |
|
| 51 |
```python
|
| 52 |
find_kwarg_by_type(fn: Callable, kwarg_type: type) -> str | None
|
|
|
|
| 60 |
|
| 61 |
## Classes
|
| 62 |
|
| 63 |
+
### `FastMCPBaseModel` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L28" target="_blank">β</a></sup>
|
| 64 |
|
| 65 |
|
| 66 |
Base model for FastMCP models.
|
| 67 |
|
| 68 |
|
| 69 |
+
### `Image` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L94" target="_blank">β</a></sup>
|
| 70 |
|
| 71 |
|
| 72 |
Helper class for returning images from tools.
|
|
|
|
| 74 |
|
| 75 |
**Methods:**
|
| 76 |
|
| 77 |
+
#### `to_image_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L131" target="_blank">β</a></sup>
|
| 78 |
|
| 79 |
```python
|
| 80 |
to_image_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> ImageContent
|
|
|
|
| 83 |
Convert to MCP ImageContent.
|
| 84 |
|
| 85 |
|
| 86 |
+
### `Audio` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L153" target="_blank">β</a></sup>
|
| 87 |
|
| 88 |
|
| 89 |
Helper class for returning audio from tools.
|
|
|
|
| 91 |
|
| 92 |
**Methods:**
|
| 93 |
|
| 94 |
+
#### `to_audio_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L190" target="_blank">β</a></sup>
|
| 95 |
|
| 96 |
```python
|
| 97 |
to_audio_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> AudioContent
|
| 98 |
```
|
| 99 |
|
| 100 |
+
### `File` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L211" target="_blank">β</a></sup>
|
| 101 |
|
| 102 |
|
| 103 |
Helper class for returning audio from tools.
|
|
|
|
| 105 |
|
| 106 |
**Methods:**
|
| 107 |
|
| 108 |
+
#### `to_resource_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L250" target="_blank">β</a></sup>
|
| 109 |
|
| 110 |
```python
|
| 111 |
to_resource_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> EmbeddedResource
|