Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147---title: clisidebarTitle: cli---
# `fastmcp.cli.cli`
FastMCP CLI tools using Cyclopts.
## Functions
### `with_argv` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/cli.py#L76" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonwith_argv(args: list[str] | None)```
Temporarily replace sys.argv if args provided.
This context manager is used at the CLI boundary to injectserver arguments when needed, without mutating sys.argv deepin the source loading logic.
Args are provided without the script name, so we preserve sys.argv[0]and replace the rest.
### `version` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/cli.py#L99" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonversion()```
Display version information and platform details.
### `inspector` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/cli.py#L145" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoninspector(server_spec: str | None = None) -> None```
Run an MCP server with the MCP Inspector for development.
**Args:**- `server_spec`: Python file to run, optionally with \:object suffix, or None to auto-detect fastmcp.json
### `apps` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/cli.py#L340" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonapps(server_spec: str) -> None```
Preview a FastMCPApp UI in the browser.
Starts the MCP server from SERVER_SPEC on --mcp-port, launches a localdev UI on --dev-port with a tool picker and AppBridge host, then opensthe browser automatically.
Requires fastmcp[apps] to be installed (prefab-ui).
### `run` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/cli.py#L410" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonrun(server_spec: str | None = None, *server_args: str) -> None```
Run an MCP server or connect to a remote one.
The server can be specified in several ways:1. Module approach: "server.py" - runs the module directly, looking for an object named 'mcp', 'server', or 'app'2. Import approach: "server.py:app" - imports and runs the specified server object3. URL approach: "http://server-url" - connects to a remote server and creates a proxy4. MCPConfig file: "mcp.json" - runs as a proxy server for the MCP Servers in the MCPConfig file5. FastMCP config: "fastmcp.json" - runs server using FastMCP configuration6. No argument: looks for fastmcp.json in current directory7. Module mode: "-m my_module" - runs the module directly via python -m
Server arguments can be passed after -- :fastmcp run server.py -- --config config.json --debug
**Args:**- `server_spec`: Python file, object specification (file\:obj), config file, URL, or None to auto-detect
### `inspect` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/cli.py#L795" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoninspect(server_spec: str | None = None) -> None```
Inspect an MCP server and display information or generate a JSON report.
This command analyzes an MCP server. Without flags, it displays a text summary.Use --format to output complete JSON data.
**Examples:**
# Show text summaryfastmcp inspect server.py
# Output FastMCP format JSON to stdoutfastmcp inspect server.py --format fastmcp
# Save MCP protocol format to file (format required with -o)fastmcp inspect server.py --format mcp -o manifest.json
# Inspect from fastmcp.json configurationfastmcp inspect fastmcp.jsonfastmcp inspect # auto-detect fastmcp.json
**Args:**- `server_spec`: Python file to inspect, optionally with \:object suffix, or fastmcp.json
### `prepare` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/cli.py#L1038" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonprepare(config_path: Annotated[str | None, cyclopts.Parameter(help='Path to fastmcp.json configuration file')] = None, output_dir: Annotated[str | None, cyclopts.Parameter(help='Directory to create the persistent environment in')] = None, skip_source: Annotated[bool, cyclopts.Parameter(help='Skip source preparation (e.g., git clone)')] = False) -> None```
Prepare a FastMCP project by creating a persistent uv environment.
This command creates a persistent uv project with all dependencies installed:- Creates a pyproject.toml with dependencies from the config- Installs all Python packages into a .venv- Prepares the source (git clone, download, etc.) unless --skip-source
After running this command, you can use:fastmcp run <config> --project <output-dir>
This is useful for:- CI/CD pipelines with separate build and run stages- Docker images where you prepare during build- Production deployments where you want fast startup times