Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
c9eb71f
1
Parent(s): 9663571
Update CLI docs
Browse files- docs/deployment/cli.mdx +174 -0
- docs/deployment/running-server.mdx +29 -1
- docs/docs.json +14 -3
- docs/{patterns → servers}/composition.mdx +0 -0
- docs/{patterns → servers}/proxy.mdx +0 -0
- src/fastmcp/cli/cli.py +7 -8
docs/deployment/cli.mdx
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: FastMCP CLI
|
| 3 |
+
sidebarTitle: CLI
|
| 4 |
+
description: Learn how to use the FastMCP command-line interface
|
| 5 |
+
icon: terminal
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
import { VersionBadge } from "/snippets/version-badge.mdx"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
FastMCP provides a command-line interface (CLI) that makes it easy to run, develop, and install your MCP servers. The CLI is automatically installed when you install FastMCP.
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
fastmcp --help
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
## Commands Overview
|
| 18 |
+
|
| 19 |
+
| Command | Purpose | Dependency Management |
|
| 20 |
+
| ------- | ------- | --------------------- |
|
| 21 |
+
| `run` | Run a FastMCP server directly | Uses your current environment; you are responsible for ensuring all dependencies are available |
|
| 22 |
+
| `dev` | Run a server with the MCP Inspector for testing | Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable` |
|
| 23 |
+
| `install` | Install a server in the Claude desktop app | Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable` |
|
| 24 |
+
| `version` | Display version information | N/A |
|
| 25 |
+
|
| 26 |
+
## Command Details
|
| 27 |
+
|
| 28 |
+
### `run`
|
| 29 |
+
|
| 30 |
+
Run a FastMCP server directly.
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
fastmcp run server.py
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
<Tip>
|
| 37 |
+
This command runs the server directly in your current Python environment. You are responsible for ensuring all dependencies are available.
|
| 38 |
+
</Tip>
|
| 39 |
+
|
| 40 |
+
#### Options
|
| 41 |
+
|
| 42 |
+
| Option | Flag | Description |
|
| 43 |
+
| ------ | ---- | ----------- |
|
| 44 |
+
| Transport | `--transport`, `-t` | Transport protocol to use (`stdio`, `streamable-http`, or `sse`) |
|
| 45 |
+
| Host | `--host` | Host to bind to when using http transport (default: 127.0.0.1) |
|
| 46 |
+
| Port | `--port`, `-p` | Port to bind to when using http transport (default: 8000) |
|
| 47 |
+
| Log Level | `--log-level`, `-l` | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
|
| 48 |
+
|
| 49 |
+
#### Server Specification
|
| 50 |
+
|
| 51 |
+
The server can be specified in two ways:
|
| 52 |
+
1. `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
|
| 53 |
+
2. `server.py:custom_name` - imports and uses the specified server object
|
| 54 |
+
|
| 55 |
+
<Tip>
|
| 56 |
+
When using `fastmcp run`, it **ignores** the `if __name__ == "__main__"` block entirely. Instead, it finds your server object and calls its `run()` method directly with the transport options you specify. This means you can use `fastmcp run` to override the transport specified in your code.
|
| 57 |
+
</Tip>
|
| 58 |
+
|
| 59 |
+
For example, if your code contains:
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
# server.py
|
| 63 |
+
from fastmcp import FastMCP
|
| 64 |
+
|
| 65 |
+
mcp = FastMCP("MyServer")
|
| 66 |
+
|
| 67 |
+
@mcp.tool()
|
| 68 |
+
def hello(name: str) -> str:
|
| 69 |
+
return f"Hello, {name}!"
|
| 70 |
+
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
# This is ignored when using `fastmcp run`!
|
| 73 |
+
mcp.run(transport="stdio")
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
You can run it with Streamable HTTP transport regardless of what's in the `__main__` block:
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
fastmcp run server.py --transport streamable-http --port 8000
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
**Example**
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
# Run a server with Streamable HTTP transport on a custom port
|
| 86 |
+
fastmcp run server.py --transport streamable-http --port 8000
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### `dev`
|
| 90 |
+
|
| 91 |
+
Run a MCP server with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) for testing.
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
fastmcp dev server.py
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
<Tip>
|
| 98 |
+
This command runs your server in an isolated environment. All dependencies must be explicitly specified using the `--with` and/or `--with-editable` options.
|
| 99 |
+
</Tip>
|
| 100 |
+
|
| 101 |
+
<Warning>
|
| 102 |
+
The `dev` command is a shortcut for testing a server over STDIO only. When the Inspector launches, you may need to:
|
| 103 |
+
1. Select "STDIO" from the transport dropdown
|
| 104 |
+
2. Connect manually
|
| 105 |
+
|
| 106 |
+
This command does not support HTTP testing. To test a server over HTTP:
|
| 107 |
+
1. Start your server manually with HTTP transport using either:
|
| 108 |
+
```bash
|
| 109 |
+
fastmcp run server.py --transport streamable-http
|
| 110 |
+
```
|
| 111 |
+
or
|
| 112 |
+
```bash
|
| 113 |
+
python server.py # Assuming your __main__ block sets HTTP transport
|
| 114 |
+
```
|
| 115 |
+
2. Open the MCP Inspector separately and connect to your running server
|
| 116 |
+
</Warning>
|
| 117 |
+
|
| 118 |
+
#### Options
|
| 119 |
+
|
| 120 |
+
| Option | Flag | Description |
|
| 121 |
+
| ------ | ---- | ----------- |
|
| 122 |
+
| Editable Package | `--with-editable`, `-e` | Directory containing pyproject.toml to install in editable mode |
|
| 123 |
+
| Additional Packages | `--with` | Additional packages to install (can be used multiple times) |
|
| 124 |
+
| Inspector Version | `--inspector-version` | Version of the MCP Inspector to use |
|
| 125 |
+
| UI Port | `--ui-port` | Port for the MCP Inspector UI |
|
| 126 |
+
| Server Port | `--server-port` | Port for the MCP Inspector Proxy server |
|
| 127 |
+
|
| 128 |
+
**Example**
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
# Run dev server with editable mode and additional packages
|
| 132 |
+
fastmcp dev server.py -e . --with pandas --with matplotlib
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
### `install`
|
| 136 |
+
|
| 137 |
+
Install a MCP server in the Claude desktop app.
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
fastmcp install server.py
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
<Tip>
|
| 144 |
+
This command installs your server in an isolated environment. All dependencies must be explicitly specified using the `--with` and/or `--with-editable` options.
|
| 145 |
+
</Tip>
|
| 146 |
+
|
| 147 |
+
<Warning>
|
| 148 |
+
The `install` command currently only sets up servers for STDIO transport. When installed in the Claude desktop app, your server will be run using STDIO regardless of any transport configuration in your code.
|
| 149 |
+
</Warning>
|
| 150 |
+
|
| 151 |
+
#### Options
|
| 152 |
+
|
| 153 |
+
| Option | Flag | Description |
|
| 154 |
+
| ------ | ---- | ----------- |
|
| 155 |
+
| Server Name | `--name`, `-n` | Custom name for the server |
|
| 156 |
+
| Editable Package | `--with-editable`, `-e` | Directory containing pyproject.toml to install in editable mode |
|
| 157 |
+
| Additional Packages | `--with` | Additional packages to install (can be used multiple times) |
|
| 158 |
+
| Environment Variables | `--env-var`, `-v` | Environment variables in KEY=VALUE format (can be used multiple times) |
|
| 159 |
+
| Environment File | `--env-file`, `-f` | Load environment variables from a .env file |
|
| 160 |
+
|
| 161 |
+
**Example**
|
| 162 |
+
|
| 163 |
+
```bash
|
| 164 |
+
# Install server with custom name, dependencies, and environment variables
|
| 165 |
+
fastmcp install server.py -n "My Analysis Server" -e . --with pandas --env-var API_KEY=12345
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
### `version`
|
| 169 |
+
|
| 170 |
+
Display version information about FastMCP and related components.
|
| 171 |
+
|
| 172 |
+
```bash
|
| 173 |
+
fastmcp version
|
| 174 |
+
```
|
docs/deployment/running-server.mdx
CHANGED
|
@@ -11,7 +11,7 @@ FastMCP servers can be run in different ways depending on your application's nee
|
|
| 11 |
|
| 12 |
## The `run()` Method
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
<Tip>
|
| 17 |
For maximum compatibility, it's best practice to place the `run()` call within an `if __name__ == "__main__":` block. This ensures the server starts only when the script is executed directly, not when imported as a module.
|
|
@@ -33,6 +33,34 @@ You can now run this MCP server by executing `python my_server.py`.
|
|
| 33 |
|
| 34 |
MCP servers can be run with a variety of different transport options, depending on your application's requirements. The `run()` method can take a `transport` argument and other transport-specific keyword arguments to configure how the server operates.
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
## Transport Options
|
| 37 |
|
| 38 |
Below is a comparison of available transport options to help you choose the right one for your needs:
|
|
|
|
| 11 |
|
| 12 |
## The `run()` Method
|
| 13 |
|
| 14 |
+
FastMCP servers can be run directly from Python by calling the `run()` method on a `FastMCP` instance.
|
| 15 |
|
| 16 |
<Tip>
|
| 17 |
For maximum compatibility, it's best practice to place the `run()` call within an `if __name__ == "__main__":` block. This ensures the server starts only when the script is executed directly, not when imported as a module.
|
|
|
|
| 33 |
|
| 34 |
MCP servers can be run with a variety of different transport options, depending on your application's requirements. The `run()` method can take a `transport` argument and other transport-specific keyword arguments to configure how the server operates.
|
| 35 |
|
| 36 |
+
## The FastMCP CLI
|
| 37 |
+
|
| 38 |
+
FastMCP also provides a command-line interface for running servers without modifying the source code. After installing FastMCP, you can run your server directly from the command line:
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
fastmcp run server.py
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
<Tip>
|
| 45 |
+
**Important**: When using `fastmcp run`, it **ignores** the `if __name__ == "__main__"` block entirely. Instead, it looks for a FastMCP object named `mcp`, `server`, or `app` and calls its `run()` method directly with the transport options you specify.
|
| 46 |
+
|
| 47 |
+
This means you can use `fastmcp run` to override the transport specified in your code, which is particularly useful for testing or changing deployment methods without modifying the code.
|
| 48 |
+
</Tip>
|
| 49 |
+
|
| 50 |
+
You can specify transport options and other configuration:
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
fastmcp run server.py --transport sse --port 9000
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
For development and testing, you can use the `dev` command to run your server with the MCP Inspector:
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
fastmcp dev server.py
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
See the [CLI documentation](/deployment/cli) for detailed information about all available commands and options.
|
| 63 |
+
|
| 64 |
## Transport Options
|
| 65 |
|
| 66 |
Below is a comparison of available transport options to help you choose the right one for your needs:
|
docs/docs.json
CHANGED
|
@@ -50,8 +50,8 @@
|
|
| 50 |
"servers/resources",
|
| 51 |
"servers/prompts",
|
| 52 |
"servers/context",
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
]
|
| 56 |
},
|
| 57 |
{
|
|
@@ -59,7 +59,8 @@
|
|
| 59 |
"pages": [
|
| 60 |
"deployment/running-server",
|
| 61 |
"deployment/asgi",
|
| 62 |
-
"deployment/authentication"
|
|
|
|
| 63 |
]
|
| 64 |
},
|
| 65 |
{
|
|
@@ -86,5 +87,15 @@
|
|
| 86 |
}
|
| 87 |
]
|
| 88 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
"theme": "mint"
|
| 90 |
}
|
|
|
|
| 50 |
"servers/resources",
|
| 51 |
"servers/prompts",
|
| 52 |
"servers/context",
|
| 53 |
+
"servers/proxy",
|
| 54 |
+
"servers/composition"
|
| 55 |
]
|
| 56 |
},
|
| 57 |
{
|
|
|
|
| 59 |
"pages": [
|
| 60 |
"deployment/running-server",
|
| 61 |
"deployment/asgi",
|
| 62 |
+
"deployment/authentication",
|
| 63 |
+
"deployment/cli"
|
| 64 |
]
|
| 65 |
},
|
| 66 |
{
|
|
|
|
| 87 |
}
|
| 88 |
]
|
| 89 |
},
|
| 90 |
+
"redirects": [
|
| 91 |
+
{
|
| 92 |
+
"destination": "/servers/proxy",
|
| 93 |
+
"source": "/patterns/proxy"
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"destination": "/servers/composition",
|
| 97 |
+
"source": "/patterns/composition"
|
| 98 |
+
}
|
| 99 |
+
],
|
| 100 |
"theme": "mint"
|
| 101 |
}
|
docs/{patterns → servers}/composition.mdx
RENAMED
|
File without changes
|
docs/{patterns → servers}/proxy.mdx
RENAMED
|
File without changes
|
src/fastmcp/cli/cli.py
CHANGED
|
@@ -327,14 +327,14 @@ def run(
|
|
| 327 |
typer.Option(
|
| 328 |
"--transport",
|
| 329 |
"-t",
|
| 330 |
-
help="Transport protocol to use (stdio or sse)",
|
| 331 |
),
|
| 332 |
] = None,
|
| 333 |
host: Annotated[
|
| 334 |
str | None,
|
| 335 |
typer.Option(
|
| 336 |
"--host",
|
| 337 |
-
help="Host to bind to when using
|
| 338 |
),
|
| 339 |
] = None,
|
| 340 |
port: Annotated[
|
|
@@ -342,7 +342,7 @@ def run(
|
|
| 342 |
typer.Option(
|
| 343 |
"--port",
|
| 344 |
"-p",
|
| 345 |
-
help="Port to bind to when using
|
| 346 |
),
|
| 347 |
] = None,
|
| 348 |
log_level: Annotated[
|
|
@@ -350,20 +350,19 @@ def run(
|
|
| 350 |
typer.Option(
|
| 351 |
"--log-level",
|
| 352 |
"-l",
|
| 353 |
-
help="Log level
|
| 354 |
),
|
| 355 |
] = None,
|
| 356 |
) -> None:
|
| 357 |
"""Run a MCP server.
|
| 358 |
|
| 359 |
-
The server can be specified in two ways:
|
| 360 |
1. Module approach: server.py - runs the module directly, expecting a server.run() call.\n
|
| 361 |
2. Import approach: server.py:app - imports and runs the specified server object.\n\n
|
| 362 |
|
| 363 |
Note: This command runs the server directly. You are responsible for ensuring
|
| 364 |
-
all dependencies are available.
|
| 365 |
-
|
| 366 |
-
""" # noqa: E501
|
| 367 |
file, server_object = _parse_file_path(file_spec)
|
| 368 |
|
| 369 |
logger.debug(
|
|
|
|
| 327 |
typer.Option(
|
| 328 |
"--transport",
|
| 329 |
"-t",
|
| 330 |
+
help="Transport protocol to use (stdio, streamable-http, or sse)",
|
| 331 |
),
|
| 332 |
] = None,
|
| 333 |
host: Annotated[
|
| 334 |
str | None,
|
| 335 |
typer.Option(
|
| 336 |
"--host",
|
| 337 |
+
help="Host to bind to when using http transport (default: 127.0.0.1)",
|
| 338 |
),
|
| 339 |
] = None,
|
| 340 |
port: Annotated[
|
|
|
|
| 342 |
typer.Option(
|
| 343 |
"--port",
|
| 344 |
"-p",
|
| 345 |
+
help="Port to bind to when using http transport (default: 8000)",
|
| 346 |
),
|
| 347 |
] = None,
|
| 348 |
log_level: Annotated[
|
|
|
|
| 350 |
typer.Option(
|
| 351 |
"--log-level",
|
| 352 |
"-l",
|
| 353 |
+
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
|
| 354 |
),
|
| 355 |
] = None,
|
| 356 |
) -> None:
|
| 357 |
"""Run a MCP server.
|
| 358 |
|
| 359 |
+
The server can be specified in two ways:
|
| 360 |
1. Module approach: server.py - runs the module directly, expecting a server.run() call.\n
|
| 361 |
2. Import approach: server.py:app - imports and runs the specified server object.\n\n
|
| 362 |
|
| 363 |
Note: This command runs the server directly. You are responsible for ensuring
|
| 364 |
+
all dependencies are available.
|
| 365 |
+
"""
|
|
|
|
| 366 |
file, server_object = _parse_file_path(file_spec)
|
| 367 |
|
| 368 |
logger.debug(
|