Learn how to use the FastMCP command-line interface
Command | Purpose | Dependency Management |
---|---|---|
run | Run a FastMCP server directly | Supports: Local files, factory functions, URLs, fastmcp.json configs, MCP configs. Deps: Uses your local environment directly. With --python , --with , --project , or --with-requirements : Runs via uv run subprocess. With fastmcp.json: Automatically manages dependencies based on configuration |
dev | Run a server with the MCP Inspector for testing | Supports: Local files and fastmcp.json configs. Deps: Always runs via uv run subprocess (never uses your local environment); dependencies must be specified or available in a uv-managed project. With fastmcp.json: Uses configured dependencies |
install | Install a server in MCP client applications | Supports: Local files and fastmcp.json configs. Deps: Creates an isolated environment; dependencies must be explicitly specified with --with and/or --with-editable . With fastmcp.json: Uses configured dependencies |
inspect | Generate a JSON report about a FastMCP server | Supports: Local files and fastmcp.json configs. Deps: Uses your current environment; you are responsible for ensuring all dependencies are available |
project prepare | Create a persistent uv project from fastmcp.json environment config | Supports: fastmcp.json configs only. Deps: Creates a uv project directory with all dependencies pre-installed for reuse with --project flag |
version | Display version information | N/A |
fastmcp run
--python
, --with
, --project
, or --with-requirements
options, it runs the server via uv run
subprocess instead.Option | Flag | Description |
---|---|---|
Transport | --transport , -t | Transport protocol to use (stdio , http , or sse ) |
Host | --host | Host to bind to when using http transport (default: 127.0.0.1) |
Port | --port , -p | Port to bind to when using http transport (default: 8000) |
Path | --path | Path to bind to when using http transport (default: /mcp/ or /sse/ for SSE) |
Log Level | --log-level , -l | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
No Banner | --no-banner | Disable the startup banner display |
No Environment | --skip-env | Skip environment setup with uv (use when already in a uv environment) |
Python Version | --python | Python version to use (e.g., 3.10, 3.11) |
Additional Packages | --with | Additional packages to install (can be used multiple times) |
Project Directory | --project | Run the command within the given project directory |
Requirements File | --with-requirements | Requirements file to install dependencies from |
New in version: 2.3.5
The fastmcp run
command supports the following entrypoints:
server.py
- imports the module and looks for a FastMCP server instance named mcp
, server
, or app
. Errors if no such object is found.server.py:custom_name
- imports and uses the specified server entrypointserver.py:create_server
- calls the specified function (sync or async) to create a server instancehttps://example.com/mcp-server
- connects to a remote server and creates a local proxy serverfastmcp.json
- runs servers using FastMCP’s declarative configuration format (auto-detects files in current directory)mcp.json
- runs servers defined in a standard MCP configuration filefastmcp run
with a local file, it completely ignores the if __name__ == "__main__"
block. This means:__main__
will NOT run__main__
is bypassedfastmcp run
finds your server entrypoint/factory and runs it with its own transport settingsfastmcp run
will load the file and look for a FastMCP server instance stored as a variable named mcp
, server
, or app
. If no such object is found, it will raise an error.
For example, if you have a file called server.py
with the following content:
server.py
with the following content:
New in version: 2.11.2
Since fastmcp run
ignores the if __name__ == "__main__"
block, you can use a factory function to run setup code before your server starts. Factory functions are called without any arguments and must return a FastMCP server instance. Both sync and async factory functions are supported.
The syntax for using a factory function is the same as for an explicit server entrypoint: fastmcp run server.py:factory_fn
. FastMCP will automatically detect that you have identified a function rather than a server Instance
For example, if you have a file called server.py
with the following content:
New in version: 2.11.4
FastMCP supports declarative configuration through fastmcp.json
files. When you run fastmcp run
without arguments, it automatically looks for a fastmcp.json
file in the current directory:
--skip-env
flag is useful when:fastmcp dev
uv run
subprocess (never your local environment) to work with the MCP Inspector. Dependencies can be:--with
and/or --with-editable
optionsfastmcp.json
configuration filefastmcp.json
, the dev command automatically uses the configured dependencies.dev
command is a shortcut for testing a server over STDIO only. When the Inspector launches, you may need to:Option | Flag | Description |
---|---|---|
Editable Package | --with-editable , -e | Directory containing pyproject.toml to install in editable mode |
Additional Packages | --with | Additional packages to install (can be used multiple times) |
Inspector Version | --inspector-version | Version of the MCP Inspector to use |
UI Port | --ui-port | Port for the MCP Inspector UI |
Server Port | --server-port | Port for the MCP Inspector Proxy server |
Python Version | --python | Python version to use (e.g., 3.10, 3.11) |
Project Directory | --project | Run the command within the given project directory |
Requirements File | --with-requirements | Requirements file to install dependencies from |
dev
command supports local FastMCP server files and configuration:
server.py
- imports the module and looks for a FastMCP server instance named mcp
, server
, or app
. Errors if no such object is found.server.py:custom_name
- imports and uses the specified server entrypointserver.py:create_server
- calls the specified function (sync or async) to create a server instancefastmcp.json
- uses FastMCP’s declarative configuration (auto-detects in current directory)dev
command only supports local files and fastmcp.json - no URLs, remote servers, or standard MCP configuration files.fastmcp install
New in version: 2.10.3
Install a MCP server in MCP client applications. FastMCP currently supports the following clients:
--with
and/or --with-editable
options (following uv
conventions) or by attaching them to your server in code via the dependencies
parameter. You should not assume that the MCP server will have access to your local environment.
uv
must be installed and available in your system PATH. Both Claude Desktop and Cursor run in isolated environments and need uv
to manage dependencies. On macOS, install uv
globally with Homebrew for Claude Desktop compatibility: brew install uv
.--python
option to specify a Python version directly. You can also use --project
to run within a specific project directory or --with-requirements
to install dependencies from a requirements file.install
commands focus on local server files with STDIO transport. For remote servers running with HTTP or SSE transport, use your client’s native configuration - FastMCP’s value is simplifying the complex local setup with dependencies and uv
commands.Option | Flag | Description |
---|---|---|
Server Name | --server-name , -n | Custom name for the server (defaults to server’s name attribute or file name) |
Editable Package | --with-editable , -e | Directory containing pyproject.toml to install in editable mode |
Additional Packages | --with | Additional packages to install (can be used multiple times) |
Environment Variables | --env | Environment variables in KEY=VALUE format (can be used multiple times) |
Environment File | --env-file , -f | Load environment variables from a .env file |
Python Version | --python | Python version to use (e.g., 3.10, 3.11) |
Project Directory | --project | Run the command within the given project directory |
Requirements File | --with-requirements | Requirements file to install dependencies from |
install
command supports local FastMCP server files and configuration:
server.py
- imports the module and looks for a FastMCP server instance named mcp
, server
, or app
. Errors if no such object is found.server.py:custom_name
- imports and uses the specified server entrypointserver.py:create_server
- calls the specified function (sync or async) to create a server instancefastmcp.json
- uses FastMCP’s declarative configuration with dependencies and settingsinstall
command only supports local files and fastmcp.json - no URLs, remote servers, or standard MCP configuration files. For remote servers, use your MCP client’s native configuration.mcp-json
subcommand generates standard MCP JSON configuration that can be used with any MCP-compatible client. This is useful when:
mcpServers
object. Consult your client’s documentation for any specific configuration requirements or formatting needs.Option | Flag | Description |
---|---|---|
Copy to Clipboard | --copy | Copy configuration to clipboard instead of printing to stdout |
fastmcp inspect
New in version: 2.9.0
Inspect a FastMCP server to view summary information or generate a detailed JSON report.
Option | Flag | Description |
---|---|---|
Format | --format , -f | Output format: fastmcp (FastMCP-specific) or mcp (MCP protocol). Required when using -o |
Output File | --output , -o | Save JSON report to file instead of stdout. Requires --format |
--format fastmcp
)--format mcp
)client.list_tools()
, client.list_prompts()
, etc.inputSchema
)inspect
command supports local FastMCP server files and configuration:
server.py
- imports the module and looks for a FastMCP server instance named mcp
, server
, or app
. Errors if no such object is found.server.py:custom_name
- imports and uses the specified server entrypointserver.py:create_server
- calls the specified function (sync or async) to create a server instancefastmcp.json
- inspects servers defined with FastMCP’s declarative configurationinspect
command only supports local files and fastmcp.json - no URLs, remote servers, or standard MCP configuration files.fastmcp project prepare
--project
flag.
Option | Flag | Description |
---|---|---|
Output Directory | --output-dir | Required. Directory where the persistent uv project will be created |
pyproject.toml
containing all dependencies from the fastmcp.json.venv
with all packages pre-installeduv.lock
file for reproducible environmentsfastmcp version
Option | Flag | Description |
---|---|---|
Copy to Clipboard | --copy | Copy version information to clipboard |