Learn how to use the FastMCP command-line interface
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.
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
Run a FastMCP server directly or proxy a remote server.
Copy
fastmcp run server.py
By default, this command runs the server directly in your current Python environment. You are responsible for ensuring all dependencies are available. When using --python, --with, --project, or --with-requirements options, it runs the server via uv run subprocess instead.
New in version 2.3.5The fastmcp run command supports the following entrypoints:
Inferred server instance: server.py - imports the module and looks for a FastMCP server instance named mcp, server, or app. Errors if no such object is found.
If you provide a path to a file, fastmcp 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
Copy
from fastmcp import FastMCPmcp = FastMCP("MyServer")
If your server is stored as a variable with a custom name, or you want to be explicit about which server to run, you can use the following syntax to load a specific server entrypoint:
Copy
fastmcp run server.py:custom_name
For example, if you have a file called server.py with the following content:
Copy
from fastmcp import FastMCPmy_server = FastMCP("CustomServer")@my_server.tooldef hello() -> str: return "Hello from custom server!"
New in version 2.11.2Since 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 InstanceFor example, if you have a file called server.py with the following content:
Copy
from fastmcp import FastMCPasync def create_server() -> FastMCP: mcp = FastMCP("MyServer") @mcp.tool def add(x: int, y: int) -> int: return x + y # Setup that runs with fastmcp run tool = await mcp.get_tool("add") tool.disable() return mcp
FastMCP run can also start a local proxy server that connects to a remote server. This is useful when you want to run a remote server locally for testing or development purposes, or to use with a client that doesn’t support direct connections to remote servers.To start a local proxy, you can use the following syntax:
New in version 2.11.4FastMCP 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:
Copy
# Auto-detect fastmcp.json in current directoryfastmcp run# Or explicitly specify a configuration filefastmcp run my-config.fastmcp.json
The configuration file handles dependencies, environment variables, and transport settings. Command-line arguments override configuration file values:
Copy
# Override port from config filefastmcp run fastmcp.json --port 8080# Skip environment setup when already in a uv environmentfastmcp run fastmcp.json --skip-env
The --skip-env flag is useful when:
You’re already in an activated virtual environment
You’re inside a Docker container with pre-installed dependencies
You’re in a uv-managed environment (prevents infinite recursion)
You want to test the server without environment setup
FastMCP can also run servers defined in a standard MCP configuration file. This is useful when you want to run multiple servers from a single file, or when you want to use a client that doesn’t support direct connections to remote servers.To run a MCP configuration file, you can use the following syntax:
Copy
fastmcp run mcp.json
This will run all the servers defined in the file.
Run a MCP server with the MCP Inspector for testing. Auto-reload is enabled by default, so your server automatically restarts when you save changes to source files.
Copy
fastmcp dev server.py
This command always runs your server via uv run subprocess (never your local environment) to work with the MCP Inspector. Dependencies can be:
Specified using --with and/or --with-editable options
Defined in a fastmcp.json configuration file
Available in a uv-managed project
When using fastmcp.json, the dev command automatically uses the configured dependencies.
The dev command is a shortcut for testing a server over STDIO only. When the Inspector launches, you may need to:
Select “STDIO” from the transport dropdown
Connect manually
This command does not support HTTP testing. To test a server over Streamable HTTP or SSE:
Start your server manually with the appropriate transport using either the command line:
Copy
fastmcp run server.py --transport http
or by setting the transport in your code:
Copy
python server.py # Assuming your __main__ block sets Streamable HTTP transport
Open the MCP Inspector separately and connect to your running server
The dev command supports local FastMCP server files and configuration:
Inferred server instance: server.py - imports the module and looks for a FastMCP server instance named mcp, server, or app. Errors if no such object is found.
Explicit server entrypoint: server.py:custom_name - imports and uses the specified server entrypoint
Factory function: server.py:create_server - calls the specified function (sync or async) to create a server instance
FastMCP configuration: fastmcp.json - uses FastMCP’s declarative configuration (auto-detects in current directory)
The dev command only supports local files and fastmcp.json - no URLs, remote servers, or standard MCP configuration files.
Examples
Copy
# Run dev server with editable mode and additional packagesfastmcp dev server.py -e . --with pandas --with matplotlib# Run dev server with fastmcp.json configuration (auto-detects)fastmcp dev# Run dev server with explicit fastmcp.json filefastmcp dev dev.fastmcp.json# Run dev server with specific Python versionfastmcp dev server.py --python 3.11# Run dev server with requirements filefastmcp dev server.py --with-requirements requirements.txt# Run dev server within a specific project directoryfastmcp dev server.py --project /path/to/project
Note that for security reasons, MCP clients usually run every server in a completely isolated environment. Therefore, all dependencies must be explicitly specified using the --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 Version Considerations: The install commands now support the --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.
FastMCP 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.
The install command supports local FastMCP server files and configuration:
Inferred server instance: server.py - imports the module and looks for a FastMCP server instance named mcp, server, or app. Errors if no such object is found.
Explicit server entrypoint: server.py:custom_name - imports and uses the specified server entrypoint
Factory function: server.py:create_server - calls the specified function (sync or async) to create a server instance
FastMCP configuration: fastmcp.json - uses FastMCP’s declarative configuration with dependencies and settings
Factory functions are particularly useful for install commands since they allow setup code to run that would otherwise be ignored when the MCP client runs your server. When using fastmcp.json, dependencies are automatically handled.
The install 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.
Examples
Copy
# Auto-detects server entrypoint (looks for 'mcp', 'server', or 'app')fastmcp install claude-desktop server.py# Install with fastmcp.json configuration (auto-detects)fastmcp install claude-desktop# Install with explicit fastmcp.json filefastmcp install claude-desktop my-config.fastmcp.json# Uses specific server entrypointfastmcp install claude-desktop server.py:my_server# With custom name and dependenciesfastmcp install claude-desktop server.py:my_server --server-name "My Analysis Server" --with pandas# Install in Claude Code with environment variablesfastmcp install claude-code server.py --env API_KEY=secret --env DEBUG=true# Install in Cursor with environment variablesfastmcp install cursor server.py --env API_KEY=secret --env DEBUG=true# Install with environment filefastmcp install cursor server.py --env-file .env# Install with specific Python versionfastmcp install claude-desktop server.py --python 3.11# Install with requirements filefastmcp install claude-code server.py --with-requirements requirements.txt# Install within a project directoryfastmcp install cursor server.py --project /path/to/project# Generate MCP JSON configurationfastmcp install mcp-json server.py --name "My Server" --with pandas# Copy JSON configuration to clipboardfastmcp install mcp-json server.py --copy
The mcp-json subcommand generates standard MCP JSON configuration that can be used with any MCP-compatible client. This is useful when:
Working with MCP clients not directly supported by FastMCP
Creating configuration for CI/CD environments
Sharing server configurations with others
Integration with custom tooling
The generated JSON follows the standard MCP server configuration format used by Claude Desktop, VS Code, Cursor, and other MCP clients, with the server name as the root key:
To use this configuration with your MCP client, you’ll typically need to add it to the client’s mcpServers object. Consult your client’s documentation for any specific configuration requirements or formatting needs.
Options specific to mcp-json:
Option
Flag
Description
Copy to Clipboard
--copy
Copy configuration to clipboard instead of printing to stdout
New in version 2.9.0Inspect a FastMCP server to view summary information or generate a detailed JSON report.
Copy
# Show text summaryfastmcp inspect server.py# Output FastMCP JSON to stdoutfastmcp inspect server.py --format fastmcp# Save MCP JSON to file (format required with -o)fastmcp inspect server.py --format mcp -o manifest.json
The inspect command supports local FastMCP server files and configuration:
Inferred server instance: server.py - imports the module and looks for a FastMCP server instance named mcp, server, or app. Errors if no such object is found.
Explicit server entrypoint: server.py:custom_name - imports and uses the specified server entrypoint
Factory function: server.py:create_server - calls the specified function (sync or async) to create a server instance
FastMCP configuration: fastmcp.json - inspects servers defined with FastMCP’s declarative configuration
The inspect command only supports local files and fastmcp.json - no URLs, remote servers, or standard MCP configuration files.
# Show text summary (no JSON output)fastmcp inspect server.py# Output: # Server: MyServer# Instructions: A helpful MCP server# Version: 1.0.0## Components:# Tools: 5# Prompts: 2# Resources: 3# Templates: 1## Environment:# FastMCP: 2.0.0# MCP: 1.0.0## Use --format [fastmcp|mcp] for complete JSON output# Output FastMCP format to stdoutfastmcp inspect server.py --format fastmcp# Specify server entrypointfastmcp inspect server.py:my_server# Output MCP protocol format to stdoutfastmcp inspect server.py --format mcp# Save to file (format required)fastmcp inspect server.py --format fastmcp -o server-manifest.json# Save MCP format with custom server objectfastmcp inspect server.py:my_server --format mcp -o mcp-manifest.json# Error: format required with output filefastmcp inspect server.py -o output.json# Error: --format is required when using -o/--output
Create a persistent uv project directory from a fastmcp.json file’s environment configuration. This allows you to pre-install all dependencies once and reuse them with the --project flag.
# Step 1: Prepare the environment (installs dependencies)fastmcp project prepare fastmcp.json --output-dir ./my-env# Step 2: Run using the prepared environment (fast, no dependency installation)fastmcp run fastmcp.json --project ./my-env
The prepare command creates a uv project with:
A pyproject.toml containing all dependencies from the fastmcp.json
A .venv with all packages pre-installed
A uv.lock file for reproducible environments
This is useful when you want to separate environment setup from server execution, such as in deployment scenarios where dependencies are installed once and the server is run multiple times.