This guide summarizes how to use the MCP CLI.
Introduction
MCP CLI is a tool included in the MCP SDK that helps MCP server development.
This post serves as a quick guide to using MCP CLI.
Note: This article was translated from my original post.
How to Use MCP CLI
Let's see how to use the MCP CLI with the MCP Python SDK.
Installing MCP CLI
To use the MCP CLI, install the MCP SDK with the cli
option:
# Using uv uv add "mcp[cli]" # Using pip pip install "mcp[cli]"
To confirm installation:
$ mcp version MCP version 1.6.0
List of MCP CLI Commands
You can check the list of commands with mcp --help
.
$ mcp --help Usage: mcp [OPTIONS] COMMAND [ARGS]... MCP development tools ╭─ Options ───────────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰─────────────────────────────────────────────────────────────────────╯ ╭─ Commands ──────────────────────────────────────────────────────────╮ │ version Show the MCP version. │ │ dev Run a MCP server with the MCP Inspector. │ │ run Run a MCP server. │ │ install Install a MCP server in the Claude desktop app. │ ╰─────────────────────────────────────────────────────────────────────╯
mcp version
: Check the versionmcp run
: Run the MCP servermcp dev
: Run the MCP server with MCP Inspectormcp install
: Connect the MCP server to Claude Desktop
Let’s now take a look at the three commands other than mcp version
: run, dev, and install.
How to Use mcp run
mcp run
starts the MCP server.
First, check the usage with --help
:
$ mcp run --help Usage: mcp run [OPTIONS] FILE_SPEC Run a MCP server. The server can be specified in two ways: 1. Module approach: server.py - runs the module directly, expecting a server.run() call. 2. Import approach: server.py:app - imports and runs the specified server object. Note: This command runs the server directly. You are responsible for ensuring all dependencies are available. For dependency management, use `mcp install` or `mcp dev` instead. ╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────╮ │ * file_spec TEXT Python file to run, optionally with :object suffix [default: None] │ │ [required] │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────────────────────╮ │ --transport -t TEXT Transport protocol to use (stdio or sse) [default: None] │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯
Specify the MCP server entry point and run mcp run
.
mcp run server.py
(Module approach)mcp run server.py:app
(Import approach)
For example, if the script calls run()
like below, use the module approach. If not, use the import approach.
from mcp.server.fastmcp import FastMCP app = FastMCP("HelloMCP") # ~~ snip ~~ if __name__ == "__main__": app.run(transport='stdio')
How to Use mcp dev
mcp dev
launches MCP Inspector, a browser-based testing tool for MCP servers.
Usage:
$ mcp dev --help Usage: mcp dev [OPTIONS] FILE_SPEC Run a MCP server with the MCP Inspector. ╭─ Arguments ─────────────────────────────────────────────────────────╮ │ * file_spec TEXT Python file to run, optionally with │ │ :object suffix │ │ [default: None] │ │ [required] │ ╰─────────────────────────────────────────────────────────────────────╯ ╭─ Options ───────────────────────────────────────────────────────────╮ │ --with-editable -e DIRECTORY Directory containing │ │ pyproject.toml to install in │ │ editable mode │ │ [default: None] │ │ --with TEXT Additional packages to install │ │ --help Show this message and exit. │ ╰─────────────────────────────────────────────────────────────────────╯
Just like mcp run
, you can specify the entry point using either the module or import approach.
# Module approach mcp dev server.py # Import approach mcp dev server.py:app
For more on how to use MCP Inspector itself, check out my other article:
How to Use mcp install
mcp install
installs an MCP server into Claude Desktop.
If done manually, you’d need to edit the config file in Claude Desktop by hand.
Reference:
en.bioerrorlog.work
Using mcp install
, you can automatically add the server to the Claude Desktop config file.
$ mcp install --help Usage: mcp install [OPTIONS] FILE_SPEC Install a MCP server in the Claude desktop app. Environment variables are preserved once added and only updated if new values are explicitly provided. ╭─ Arguments ─────────────────────────────────────────────────────────────────────────╮ │ * file_spec TEXT Python file to run, optionally with :object suffix │ │ [default: None] │ │ [required] │ ╰─────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ───────────────────────────────────────────────────────────────────────────╮ │ --name -n TEXT Custom name for the server (defaults to │ │ server's name attribute or file name) │ │ [default: None] │ │ --with-editable -e DIRECTORY Directory containing pyproject.toml to install │ │ in editable mode │ │ [default: None] │ │ --with TEXT Additional packages to install │ │ --env-var -v TEXT Environment variables in KEY=VALUE format │ │ --env-file -f FILE Load environment variables from a .env file │ │ [default: None] │ │ --help Show this message and exit. │ ╰─────────────────────────────────────────────────────────────────────────────────────╯
As with mcp run
and mcp dev
, specify the server script and run mcp install
.
Use --name
to set the server display name in Claude Desktop. Use --env-var (-v)
or --env-file (-f)
to define environment variables.
# Example mcp install server.py # Specify server name mcp install server.py --name "My MCP" # Set environment variables mcp install server.py -v API_KEY=abc123 -v DB_URL=postgres://... mcp install server.py -f .env
Example output when running mcp install
with an empty claude_desktop_config.json
:
mcp install main.py --name "My MCP"
# claude_desktop_config.json { "mcpServers": { "My MCP": { "command": "uv", "args": [ "run", "--with", "mcp[cli]", "mcp", "run", "/path/to/main.py" ] } } }
In this way, the claude_desktop_config.json
file is updated, and the MCP server is registered with Claude Desktop.
Conclusion
That wraps up this quick guide to MCP CLI.
Hope it helps someone!
[Related Articles]