chore: import upstream snapshot with attribution
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
---
|
||||
title: Auth Utilities
|
||||
sidebarTitle: Auth
|
||||
description: Create and validate CIMD documents for OAuth
|
||||
icon: key
|
||||
---
|
||||
|
||||
import { VersionBadge } from '/snippets/version-badge.mdx'
|
||||
|
||||
<VersionBadge version="3.0.0" />
|
||||
|
||||
The `fastmcp auth` commands help with CIMD (Client ID Metadata Document) management — part of MCP's OAuth authentication flow. A CIMD is a JSON document you host at an HTTPS URL to identify your client application to MCP servers.
|
||||
|
||||
## Creating a CIMD
|
||||
|
||||
`fastmcp auth cimd create` generates a CIMD document:
|
||||
|
||||
```bash
|
||||
fastmcp auth cimd create \
|
||||
--name "My App" \
|
||||
--redirect-uri "http://localhost:*/callback"
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"client_id": "https://your-domain.com/oauth/client.json",
|
||||
"client_name": "My App",
|
||||
"redirect_uris": ["http://localhost:*/callback"],
|
||||
"token_endpoint_auth_method": "none"
|
||||
}
|
||||
```
|
||||
|
||||
The generated document includes a placeholder `client_id` — update it to match the URL where you'll host the document before deploying.
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Name | `--name` | **Required.** Human-readable client name |
|
||||
| Redirect URI | `--redirect-uri` | **Required.** Allowed redirect URIs (repeatable) |
|
||||
| Client URI | `--client-uri` | Client's home page URL |
|
||||
| Logo URI | `--logo-uri` | Client's logo URL |
|
||||
| Scope | `--scope` | Space-separated list of scopes |
|
||||
| Output | `--output`, `-o` | Save to file (default: stdout) |
|
||||
| Pretty | `--pretty` | Pretty-print JSON (default: true) |
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
fastmcp auth cimd create \
|
||||
--name "My Production App" \
|
||||
--redirect-uri "http://localhost:*/callback" \
|
||||
--redirect-uri "https://myapp.example.com/callback" \
|
||||
--client-uri "https://myapp.example.com" \
|
||||
--scope "read write" \
|
||||
--output client.json
|
||||
```
|
||||
|
||||
## Validating a CIMD
|
||||
|
||||
`fastmcp auth cimd validate` fetches a hosted CIMD and verifies it conforms to the spec:
|
||||
|
||||
```bash
|
||||
fastmcp auth cimd validate https://myapp.example.com/oauth/client.json
|
||||
```
|
||||
|
||||
The validator checks that the URL is valid (HTTPS, non-root path), the document is valid JSON, the `client_id` matches the URL, and no shared-secret auth methods are used.
|
||||
|
||||
On success:
|
||||
|
||||
```
|
||||
→ Fetching https://myapp.example.com/oauth/client.json...
|
||||
✓ Valid CIMD document
|
||||
|
||||
Document details:
|
||||
client_id: https://myapp.example.com/oauth/client.json
|
||||
client_name: My App
|
||||
token_endpoint_auth_method: none
|
||||
redirect_uris:
|
||||
• http://localhost:*/callback
|
||||
```
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Timeout | `--timeout`, `-t` | HTTP request timeout in seconds (default: 10) |
|
||||
@@ -0,0 +1,144 @@
|
||||
---
|
||||
title: Client Commands
|
||||
sidebarTitle: Client
|
||||
description: List tools, call them, and discover configured servers
|
||||
icon: satellite-dish
|
||||
---
|
||||
|
||||
import { VersionBadge } from '/snippets/version-badge.mdx'
|
||||
|
||||
<VersionBadge version="3.0.0" />
|
||||
|
||||
The CLI can act as an MCP client — connecting to any server (local or remote) to list what it exposes and call its tools directly. This is useful for development, debugging, scripting, and giving shell-capable LLM agents access to MCP servers.
|
||||
|
||||
## Listing Tools
|
||||
|
||||
`fastmcp list` connects to a server and prints its tools as function signatures, showing parameter names, types, and descriptions at a glance:
|
||||
|
||||
```bash
|
||||
fastmcp list http://localhost:8000/mcp
|
||||
fastmcp list server.py
|
||||
fastmcp list weather # name-based resolution
|
||||
```
|
||||
|
||||
When you need the full JSON Schema for a tool's inputs or outputs — for understanding nested objects, enum constraints, or complex types — opt in with `--input-schema` or `--output-schema`:
|
||||
|
||||
```bash
|
||||
fastmcp list server.py --input-schema
|
||||
```
|
||||
|
||||
### Resources and Prompts
|
||||
|
||||
By default, only tools are shown. Add `--resources` or `--prompts` to include those:
|
||||
|
||||
```bash
|
||||
fastmcp list server.py --resources --prompts
|
||||
```
|
||||
|
||||
### Machine-Readable Output
|
||||
|
||||
The `--json` flag switches to structured JSON with full schemas included. This is the format to use when feeding tool definitions to an LLM or building automation:
|
||||
|
||||
```bash
|
||||
fastmcp list server.py --json
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Command | `--command` | Connect via stdio (e.g., `'npx -y @mcp/server'`) |
|
||||
| Transport | `--transport`, `-t` | Force `http` or `sse` for URL targets |
|
||||
| Resources | `--resources` | Include resources in output |
|
||||
| Prompts | `--prompts` | Include prompts in output |
|
||||
| Input Schema | `--input-schema` | Show full input schemas |
|
||||
| Output Schema | `--output-schema` | Show full output schemas |
|
||||
| JSON | `--json` | Structured JSON output |
|
||||
| Timeout | `--timeout` | Connection timeout in seconds |
|
||||
| Auth | `--auth` | `oauth` (default for HTTP), a bearer token, or `none` |
|
||||
|
||||
## Calling Tools
|
||||
|
||||
`fastmcp call` invokes a single tool on a server. Pass arguments as `key=value` pairs — the CLI fetches the tool's schema and coerces your string values to the right types automatically:
|
||||
|
||||
```bash
|
||||
fastmcp call server.py greet name=World
|
||||
fastmcp call http://localhost:8000/mcp search query=hello limit=5
|
||||
```
|
||||
|
||||
Type coercion is schema-driven: `"5"` becomes the integer `5` when the schema expects an integer. Booleans accept `true`/`false`, `yes`/`no`, and `1`/`0`. Arrays and objects are parsed as JSON.
|
||||
|
||||
### Complex Arguments
|
||||
|
||||
For tools with nested or structured parameters, `key=value` syntax gets awkward. Pass a single JSON object instead:
|
||||
|
||||
```bash
|
||||
fastmcp call server.py create_item '{"name": "Widget", "tags": ["sale"], "metadata": {"color": "blue"}}'
|
||||
```
|
||||
|
||||
Or use `--input-json` to provide a base dictionary, then override individual keys with `key=value` pairs:
|
||||
|
||||
```bash
|
||||
fastmcp call server.py search --input-json '{"query": "hello", "limit": 5}' limit=10
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
|
||||
If you misspell a tool name, the CLI suggests corrections via fuzzy matching. Missing required arguments produce a clear message with the tool's signature as a reminder. Tool execution errors are printed with a non-zero exit code, making the CLI straightforward to use in scripts.
|
||||
|
||||
### Structured Output
|
||||
|
||||
`--json` emits the raw result including content blocks, error status, and structured content:
|
||||
|
||||
```bash
|
||||
fastmcp call server.py get_weather city=London --json
|
||||
```
|
||||
|
||||
### Interactive Elicitation
|
||||
|
||||
Some tools request additional input during execution through MCP's elicitation mechanism. When this happens, the CLI prompts you in the terminal — showing each field's name, type, and whether it's required. You can type `decline` to skip a question or `cancel` to abort the call entirely.
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Command | `--command` | Connect via stdio |
|
||||
| Transport | `--transport`, `-t` | Force `http` or `sse` |
|
||||
| Input JSON | `--input-json` | Base arguments as JSON (merged with `key=value`) |
|
||||
| JSON | `--json` | Raw JSON output |
|
||||
| Timeout | `--timeout` | Connection timeout in seconds |
|
||||
| Auth | `--auth` | `oauth`, a bearer token, or `none` |
|
||||
|
||||
## Discovering Configured Servers
|
||||
|
||||
`fastmcp discover` scans your machine for MCP servers configured in editors and tools. It checks:
|
||||
|
||||
- **Claude Desktop** — `claude_desktop_config.json`
|
||||
- **Claude Code** — `~/.claude.json`
|
||||
- **Cursor** — `.cursor/mcp.json` (walks up from current directory)
|
||||
- **Gemini CLI** — `~/.gemini/settings.json`
|
||||
- **Goose** — `~/.config/goose/config.yaml`
|
||||
- **Project** — `./mcp.json` in the current directory
|
||||
|
||||
```bash
|
||||
fastmcp discover
|
||||
```
|
||||
|
||||
The output groups servers by source, showing each server's name and transport. Filter by source or get machine-readable output:
|
||||
|
||||
```bash
|
||||
fastmcp discover --source claude-code
|
||||
fastmcp discover --source cursor --source gemini --json
|
||||
```
|
||||
|
||||
Any server that appears here can be used by name with `list`, `call`, and other commands — so you can go from "I have a server in Claude Code" to querying it without copying URLs or paths.
|
||||
|
||||
## LLM Agent Integration
|
||||
|
||||
For LLM agents that can execute shell commands but don't have native MCP support, the CLI provides a clean bridge. The agent calls `fastmcp list --json` to discover available tools with full schemas, then `fastmcp call --json` to invoke them with structured results.
|
||||
|
||||
Because the CLI handles connection management, transport selection, and type coercion internally, the agent doesn't need to understand MCP protocol details — it just reads JSON and constructs shell commands.
|
||||
|
||||
## Remote Stdio Bridges
|
||||
|
||||
For MCP hosts that expect a local stdio command but need to connect to a remote HTTP server, use [`fastmcp-remote`](/clients/fastmcp-remote). It provides a small standalone bridge for host configuration, while `fastmcp list` and `fastmcp call` remain focused on direct inspection and invocation from the terminal.
|
||||
@@ -0,0 +1,106 @@
|
||||
---
|
||||
title: Generate CLI
|
||||
sidebarTitle: Generate CLI
|
||||
description: Scaffold a standalone typed CLI from any MCP server
|
||||
icon: wand-magic-sparkles
|
||||
---
|
||||
|
||||
import { VersionBadge } from '/snippets/version-badge.mdx'
|
||||
|
||||
<VersionBadge version="3.0.0" />
|
||||
|
||||
`fastmcp list` and `fastmcp call` are general-purpose — you always specify the server, the tool name, and the arguments from scratch. `fastmcp generate-cli` goes further: it connects to a server, reads its tool schemas, and writes a standalone Python script where every tool is a proper subcommand with typed flags, help text, and tab completion. The result is a CLI that feels hand-written for that specific server.
|
||||
|
||||
MCP tool schemas already contain everything a CLI framework needs — parameter names, types, descriptions, required/optional status, and defaults. `generate-cli` maps that into [cyclopts](https://cyclopts.readthedocs.io/) commands, so JSON Schema types become Python type annotations, descriptions become `--help` text, and required parameters become mandatory flags.
|
||||
|
||||
## Generating a Script
|
||||
|
||||
Point the command at any [server target](/cli/overview#server-targets) and it writes a CLI script:
|
||||
|
||||
```bash
|
||||
fastmcp generate-cli weather
|
||||
fastmcp generate-cli http://localhost:8000/mcp
|
||||
fastmcp generate-cli server.py my_weather_cli.py
|
||||
```
|
||||
|
||||
The second positional argument sets the output path (defaults to `cli.py`). If the file already exists, pass `-f` to overwrite:
|
||||
|
||||
```bash
|
||||
fastmcp generate-cli weather -f
|
||||
```
|
||||
|
||||
## What You Get
|
||||
|
||||
The generated script is a regular Python file — executable, editable, and yours:
|
||||
|
||||
```
|
||||
$ python cli.py call-tool --help
|
||||
Usage: weather-cli call-tool COMMAND
|
||||
|
||||
Call a tool on the server
|
||||
|
||||
Commands:
|
||||
get_forecast Get the weather forecast for a city.
|
||||
search_city Search for a city by name.
|
||||
```
|
||||
|
||||
Each tool has typed parameters with help text pulled directly from the server's schema:
|
||||
|
||||
```
|
||||
$ python cli.py call-tool get_forecast --help
|
||||
Usage: weather-cli call-tool get_forecast [OPTIONS]
|
||||
|
||||
Get the weather forecast for a city.
|
||||
|
||||
Options:
|
||||
--city [str] City name (required)
|
||||
--days [int] Number of forecast days (default: 3)
|
||||
```
|
||||
|
||||
Beyond tool commands, the script includes generic MCP operations — `list-tools`, `list-resources`, `read-resource`, `list-prompts`, and `get-prompt` — that always reflect the server's current state, even if tools have changed since generation.
|
||||
|
||||
## Parameter Handling
|
||||
|
||||
Parameters are mapped based on their JSON Schema type:
|
||||
|
||||
**Simple types** (`string`, `integer`, `number`, `boolean`) become typed flags:
|
||||
|
||||
```bash
|
||||
python cli.py call-tool get_forecast --city London --days 3
|
||||
```
|
||||
|
||||
**Arrays of simple types** become repeatable flags:
|
||||
|
||||
```bash
|
||||
python cli.py call-tool tag_items --tags python --tags fastapi --tags mcp
|
||||
```
|
||||
|
||||
**Complex types** (objects, nested arrays, unions) accept JSON strings. The `--help` output shows the full schema so you know what structure to pass:
|
||||
|
||||
```bash
|
||||
python cli.py call-tool create_user \
|
||||
--name John \
|
||||
--metadata '{"role": "admin", "dept": "engineering"}'
|
||||
```
|
||||
|
||||
## Agent Skill
|
||||
|
||||
Alongside the CLI script, `generate-cli` writes a `SKILL.md` file — a [Claude Code agent skill](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/skills) that documents every tool's exact invocation syntax, parameter flags, types, and descriptions. An agent can pick up the CLI immediately without running `--help` or experimenting with flag names.
|
||||
|
||||
To skip skill generation:
|
||||
|
||||
```bash
|
||||
fastmcp generate-cli weather --no-skill
|
||||
```
|
||||
|
||||
## How It Works
|
||||
|
||||
The generated script is a *client*, not a server — it connects to the server on every invocation rather than bundling it. A `CLIENT_SPEC` variable at the top holds the resolved transport (a URL string or `StdioTransport` with baked-in command and arguments).
|
||||
|
||||
The most common edit is changing `CLIENT_SPEC` — for example, pointing a script generated from a dev server at production. Beyond that, the helper functions (`_call_tool`, `_print_tool_result`) are thin wrappers around `fastmcp.Client` that are easy to adapt.
|
||||
|
||||
The script requires `fastmcp` as a dependency. If it lives outside a project that already has FastMCP installed:
|
||||
|
||||
```bash
|
||||
uv run --with fastmcp python cli.py call-tool get_forecast --city London
|
||||
```
|
||||
@@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Inspecting Servers
|
||||
sidebarTitle: Inspecting
|
||||
description: View a server's components and metadata
|
||||
icon: magnifying-glass
|
||||
---
|
||||
|
||||
import { VersionBadge } from '/snippets/version-badge.mdx'
|
||||
|
||||
<VersionBadge version="2.9.0" />
|
||||
|
||||
`fastmcp inspect` loads a server and reports what it contains — its tools, resources, prompts, version, and metadata. The default output is a human-readable summary:
|
||||
|
||||
```bash
|
||||
fastmcp inspect server.py
|
||||
```
|
||||
|
||||
```
|
||||
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
|
||||
```
|
||||
|
||||
## JSON Output
|
||||
|
||||
For programmatic use, two JSON formats are available:
|
||||
|
||||
**FastMCP format** (`--format fastmcp`) includes everything FastMCP knows about the server — tool tags, enabled status, output schemas, annotations, and custom metadata. Field names use `snake_case`. This is the format for debugging and introspecting FastMCP servers.
|
||||
|
||||
**MCP protocol format** (`--format mcp`) shows exactly what MCP clients see through the protocol — only standard MCP fields, `camelCase` names, no FastMCP-specific extensions. This is the format for verifying client compatibility and debugging what clients actually receive.
|
||||
|
||||
```bash
|
||||
# Full FastMCP metadata to stdout
|
||||
fastmcp inspect server.py --format fastmcp
|
||||
|
||||
# MCP protocol view saved to file
|
||||
fastmcp inspect server.py --format mcp -o manifest.json
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Format | `--format`, `-f` | `fastmcp` or `mcp` (required when using `-o`) |
|
||||
| Output File | `--output`, `-o` | Save to file instead of stdout |
|
||||
|
||||
## Entrypoints
|
||||
|
||||
The `inspect` command supports the same local entrypoints as [`fastmcp run`](/cli/running): inferred instances, explicit entrypoints, factory functions, and `fastmcp.json` configs.
|
||||
|
||||
```bash
|
||||
fastmcp inspect server.py # inferred instance
|
||||
fastmcp inspect server.py:my_server # explicit entrypoint
|
||||
fastmcp inspect server.py:create_server # factory function
|
||||
fastmcp inspect fastmcp.json # config file
|
||||
```
|
||||
|
||||
<Warning>
|
||||
`inspect` only works with local files and `fastmcp.json` — it doesn't connect to remote URLs or standard MCP config files.
|
||||
</Warning>
|
||||
@@ -0,0 +1,146 @@
|
||||
---
|
||||
title: Install MCP Servers
|
||||
sidebarTitle: Install MCPs
|
||||
description: Install MCP servers into Claude, Cursor, Gemini, and other clients
|
||||
icon: download
|
||||
---
|
||||
|
||||
import { VersionBadge } from '/snippets/version-badge.mdx'
|
||||
|
||||
<VersionBadge version="2.10.3" />
|
||||
|
||||
`fastmcp install` registers a server with an MCP client application so the client can launch it automatically. Each MCP client runs servers in its own isolated environment, which means dependencies need to be explicitly declared — you can't rely on whatever happens to be installed locally.
|
||||
|
||||
```bash
|
||||
fastmcp install claude-desktop server.py
|
||||
fastmcp install claude-code server.py --with pandas --with matplotlib
|
||||
fastmcp install cursor server.py -e .
|
||||
```
|
||||
|
||||
<Warning>
|
||||
`uv` must be installed and available in your system PATH. Both Claude Desktop and Cursor run servers in isolated environments managed by `uv`. On macOS, install it globally with Homebrew for Claude Desktop compatibility: `brew install uv`.
|
||||
</Warning>
|
||||
|
||||
## Supported Clients
|
||||
|
||||
| Client | Install method |
|
||||
| ------ | -------------- |
|
||||
| `claude-code` | Claude Code's built-in MCP management |
|
||||
| `claude-desktop` | Direct config file modification |
|
||||
| `cursor` | Deeplink that opens Cursor for confirmation |
|
||||
| `gemini-cli` | Gemini CLI's built-in MCP management |
|
||||
| `goose` | Deeplink that opens Goose for confirmation (uses `uvx`) |
|
||||
| `mcp-json` | Generates standard MCP JSON config for manual use |
|
||||
| `stdio` | Outputs the shell command to run via stdio |
|
||||
|
||||
## Declaring Dependencies
|
||||
|
||||
Because MCP clients run servers in isolation, you need to tell the install command what your server needs. There are two approaches:
|
||||
|
||||
**Command-line flags** let you specify dependencies directly:
|
||||
|
||||
```bash
|
||||
fastmcp install claude-desktop server.py --with pandas --with "sqlalchemy>=2.0"
|
||||
fastmcp install cursor server.py -e . --with-requirements requirements.txt
|
||||
```
|
||||
|
||||
**`fastmcp.json`** configuration files declare dependencies alongside the server definition. When you install from a config file, dependencies are picked up automatically:
|
||||
|
||||
```bash
|
||||
fastmcp install claude-desktop fastmcp.json
|
||||
fastmcp install claude-desktop # auto-detects fastmcp.json in current directory
|
||||
```
|
||||
|
||||
See [Server Configuration](/deployment/server-configuration) for the full config format.
|
||||
|
||||
## Options
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Server Name | `--server-name`, `-n` | Custom name for the server |
|
||||
| Editable Package | `--with-editable`, `-e` | Install a directory in editable mode |
|
||||
| Extra Packages | `--with` | Additional packages (repeatable) |
|
||||
| Environment Variables | `--env` | `KEY=VALUE` pairs (repeatable) |
|
||||
| Environment File | `--env-file`, `-f` | Load env vars from a `.env` file |
|
||||
| Python | `--python` | Python version (e.g., `3.11`) |
|
||||
| Project | `--project` | Run within a uv project directory |
|
||||
| Requirements | `--with-requirements` | Install from a requirements file |
|
||||
| Config Path | `--config-path` | Custom path to Claude Desktop config directory (`claude-desktop` only) |
|
||||
|
||||
## Examples
|
||||
|
||||
```bash
|
||||
# Basic install with auto-detected server instance
|
||||
fastmcp install claude-desktop server.py
|
||||
|
||||
# Install from fastmcp.json with auto-detection
|
||||
fastmcp install claude-desktop
|
||||
|
||||
# Explicit entrypoint with dependencies
|
||||
fastmcp install claude-desktop server.py:my_server \
|
||||
--server-name "My Analysis Server" \
|
||||
--with pandas
|
||||
|
||||
# With environment variables
|
||||
fastmcp install claude-code server.py \
|
||||
--env API_KEY=secret \
|
||||
--env DEBUG=true
|
||||
|
||||
# With env file
|
||||
fastmcp install cursor server.py --env-file .env
|
||||
|
||||
# Specific Python version and requirements file
|
||||
fastmcp install claude-desktop server.py \
|
||||
--python 3.11 \
|
||||
--with-requirements requirements.txt
|
||||
|
||||
# With custom config path (claude-desktop only)
|
||||
fastmcp install claude-desktop server.py \
|
||||
--config-path "C:\Users\username\AppData\Local\Packages\Claude_xyz\LocalCache\Roaming\Claude"
|
||||
```
|
||||
|
||||
## Generating MCP JSON
|
||||
|
||||
The `mcp-json` target generates standard MCP configuration JSON instead of installing into a specific client. This is useful for clients that FastMCP doesn't directly support, for CI/CD environments, or for sharing server configs:
|
||||
|
||||
```bash
|
||||
fastmcp install mcp-json server.py
|
||||
```
|
||||
|
||||
The output follows the standard format used by Claude Desktop, Cursor, and other MCP clients:
|
||||
|
||||
```json
|
||||
{
|
||||
"server-name": {
|
||||
"command": "uv",
|
||||
"args": ["run", "--with", "fastmcp", "fastmcp", "run", "/path/to/server.py"],
|
||||
"env": {
|
||||
"API_KEY": "value"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Use `--copy` to send it to your clipboard instead of stdout.
|
||||
|
||||
## Generating Stdio Commands
|
||||
|
||||
The `stdio` target outputs the shell command an MCP host would use to start your server over stdio:
|
||||
|
||||
```bash
|
||||
fastmcp install stdio server.py
|
||||
# Output: uv run --with fastmcp fastmcp run /absolute/path/to/server.py
|
||||
```
|
||||
|
||||
When installing from a `fastmcp.json`, dependencies from the config are included automatically:
|
||||
|
||||
```bash
|
||||
fastmcp install stdio fastmcp.json
|
||||
# Output: uv run --with fastmcp --with pillow --with 'qrcode[pil]>=8.0' fastmcp run /path/to/server.py
|
||||
```
|
||||
|
||||
Use `--copy` to copy to clipboard.
|
||||
|
||||
<Tip>
|
||||
`fastmcp install` is designed for local server files with stdio transport. For remote servers running over HTTP, use your client's native configuration — FastMCP's value here is simplifying the complex local setup with `uv`, dependencies, and environment variables.
|
||||
</Tip>
|
||||
@@ -0,0 +1,104 @@
|
||||
---
|
||||
title: CLI
|
||||
sidebarTitle: Overview
|
||||
description: The fastmcp command-line interface
|
||||
icon: terminal
|
||||
---
|
||||
|
||||
import { VersionBadge } from '/snippets/version-badge.mdx'
|
||||
|
||||
The `fastmcp` CLI is installed automatically with FastMCP. It's the primary way to run, test, install, and interact with MCP servers from your terminal.
|
||||
|
||||
```bash
|
||||
fastmcp --help
|
||||
```
|
||||
|
||||
## Commands at a Glance
|
||||
|
||||
| Command | What it does |
|
||||
| ------- | ------------ |
|
||||
| [`run`](/cli/running) | Run a server (local file, factory function, remote URL, or config file) |
|
||||
| [`dev apps`](/cli/running#previewing-apps) | Launch a browser-based preview UI for Prefab App tools |
|
||||
| [`dev inspector`](/cli/running#development-with-the-inspector) | Launch a server inside the MCP Inspector for interactive testing |
|
||||
| [`install`](/cli/install-mcp) | Install a server into Claude Code, Claude Desktop, Cursor, Gemini CLI, or Goose |
|
||||
| [`inspect`](/cli/inspecting) | Print a server's tools, resources, and prompts as a summary or JSON report |
|
||||
| [`list`](/cli/client) | List a server's tools (and optionally resources and prompts) |
|
||||
| [`call`](/cli/client#calling-tools) | Call a single tool with arguments |
|
||||
| [`discover`](/cli/client#discovering-configured-servers) | Find MCP servers configured in your editors and tools |
|
||||
| [`generate-cli`](/cli/generate-cli) | Scaffold a standalone typed CLI from a server's tool schemas |
|
||||
| [`project prepare`](/cli/running#pre-building-environments) | Pre-install dependencies into a reusable uv project |
|
||||
| [`auth cimd`](/cli/auth) | Create and validate CIMD documents for OAuth |
|
||||
| `version` | Print version info (`--copy` to copy to clipboard) |
|
||||
|
||||
## Server Targets
|
||||
|
||||
Most commands need to know *which server* to talk to. You pass a "server spec" as the first argument, and FastMCP resolves the right transport automatically.
|
||||
|
||||
**URLs** connect to a running HTTP server:
|
||||
|
||||
```bash
|
||||
fastmcp list http://localhost:8000/mcp
|
||||
fastmcp call http://localhost:8000/mcp get_forecast city=London
|
||||
```
|
||||
|
||||
**Python files** are loaded directly — no `mcp.run()` boilerplate needed. FastMCP finds a server instance named `mcp`, `server`, or `app` in the file, or you can specify one explicitly:
|
||||
|
||||
```bash
|
||||
fastmcp list server.py
|
||||
fastmcp run server.py:my_custom_server
|
||||
```
|
||||
|
||||
**Config files** work too — both FastMCP's own `fastmcp.json` format and standard MCP config files with an `mcpServers` key:
|
||||
|
||||
```bash
|
||||
fastmcp run fastmcp.json
|
||||
fastmcp list mcp-config.json
|
||||
```
|
||||
|
||||
**Stdio commands** connect to any MCP server that speaks over standard I/O. Use `--command` instead of a positional argument:
|
||||
|
||||
```bash
|
||||
fastmcp list --command 'npx -y @modelcontextprotocol/server-github'
|
||||
```
|
||||
|
||||
### Name-Based Resolution
|
||||
|
||||
If your servers are already configured in an editor or tool, you can refer to them by name. FastMCP scans configs from Claude Desktop, Claude Code, Cursor, Gemini CLI, and Goose:
|
||||
|
||||
```bash
|
||||
fastmcp list weather
|
||||
fastmcp call weather get_forecast city=London
|
||||
```
|
||||
|
||||
When the same name appears in multiple configs, use the `source:name` form to be specific:
|
||||
|
||||
```bash
|
||||
fastmcp list claude-code:my-server
|
||||
fastmcp call cursor:weather get_forecast city=London
|
||||
```
|
||||
|
||||
Run [`fastmcp discover`](/cli/client#discovering-configured-servers) to see what's available on your machine.
|
||||
|
||||
## Authentication
|
||||
|
||||
When targeting an HTTP URL, the CLI enables OAuth authentication by default. If the server requires it, you'll be guided through the flow (typically opening a browser). If it doesn't, the setup is a silent no-op.
|
||||
|
||||
To skip authentication entirely — useful for local development servers — pass `--auth none`:
|
||||
|
||||
```bash
|
||||
fastmcp call http://localhost:8000/mcp my_tool --auth none
|
||||
```
|
||||
|
||||
You can also pass a bearer token directly:
|
||||
|
||||
```bash
|
||||
fastmcp list http://localhost:8000/mcp --auth "Bearer sk-..."
|
||||
```
|
||||
|
||||
## Transport Override
|
||||
|
||||
FastMCP defaults to Streamable HTTP for URL targets. If the server only supports Server-Sent Events (SSE), force the older transport:
|
||||
|
||||
```bash
|
||||
fastmcp list http://localhost:8000 --transport sse
|
||||
```
|
||||
@@ -0,0 +1,166 @@
|
||||
---
|
||||
title: Running Servers
|
||||
sidebarTitle: Running
|
||||
description: Start, develop, and configure servers from the command line
|
||||
icon: play
|
||||
---
|
||||
|
||||
import { VersionBadge } from '/snippets/version-badge.mdx'
|
||||
|
||||
## Starting a Server
|
||||
|
||||
`fastmcp run` starts a server. Point it at a Python file, a factory function, a remote URL, or a config file:
|
||||
|
||||
```bash
|
||||
fastmcp run server.py
|
||||
fastmcp run server.py:create_server
|
||||
fastmcp run https://example.com/mcp
|
||||
fastmcp run fastmcp.json
|
||||
```
|
||||
|
||||
By default, the server runs over **stdio** — the transport that MCP clients like Claude Desktop expect. To serve over HTTP instead, specify the transport:
|
||||
|
||||
```bash
|
||||
fastmcp run server.py --transport http
|
||||
fastmcp run server.py --transport http --host 0.0.0.0 --port 9000
|
||||
```
|
||||
|
||||
### Entrypoints
|
||||
|
||||
FastMCP supports several ways to locate and start your server:
|
||||
|
||||
**Inferred instance** — FastMCP imports the file and looks for a variable named `mcp`, `server`, or `app`:
|
||||
|
||||
```bash
|
||||
fastmcp run server.py
|
||||
```
|
||||
|
||||
**Explicit instance** — point at a specific variable:
|
||||
|
||||
```bash
|
||||
fastmcp run server.py:my_server
|
||||
```
|
||||
|
||||
**Factory function** — FastMCP calls the function and uses the returned server. Useful when your server needs async setup or configuration that runs before startup:
|
||||
|
||||
```bash
|
||||
fastmcp run server.py:create_server
|
||||
```
|
||||
|
||||
**Remote URL** — starts a local proxy that bridges to a remote server. Handy for local development against a deployed server, or for bridging a remote HTTP server to stdio:
|
||||
|
||||
```bash
|
||||
fastmcp run https://example.com/mcp
|
||||
```
|
||||
|
||||
**FastMCP config** — uses a `fastmcp.json` file that declaratively specifies the server, its dependencies, and deployment settings. When you run `fastmcp run` with no arguments, it auto-detects `fastmcp.json` in the current directory:
|
||||
|
||||
```bash
|
||||
fastmcp run
|
||||
fastmcp run my-config.fastmcp.json
|
||||
```
|
||||
|
||||
See [Server Configuration](/deployment/server-configuration) for the full `fastmcp.json` format.
|
||||
|
||||
**MCP config** — runs servers defined in a standard MCP configuration file (any `.json` with an `mcpServers` key):
|
||||
|
||||
```bash
|
||||
fastmcp run mcp.json
|
||||
```
|
||||
|
||||
<Warning>
|
||||
`fastmcp run` completely ignores the `if __name__ == "__main__"` block. Any setup code in that block won't execute. If you need initialization logic to run, use a [factory function](/cli/overview#factory-functions).
|
||||
</Warning>
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Transport | `--transport`, `-t` | `stdio` (default), `http`, or `sse` |
|
||||
| Host | `--host` | Bind address for HTTP (default: `127.0.0.1`) |
|
||||
| Port | `--port`, `-p` | Bind port for HTTP (default: `8000`) |
|
||||
| Path | `--path` | URL path for HTTP (default: `/mcp/`) |
|
||||
| Log Level | `--log-level`, `-l` | `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
|
||||
| No Banner | `--no-banner` | Suppress the startup banner |
|
||||
| Auto-Reload | `--reload` / `--no-reload` | Watch for file changes and restart automatically |
|
||||
| Reload Dirs | `--reload-dir` | Directories to watch (repeatable) |
|
||||
| Skip Env | `--skip-env` | Don't set up a uv environment (use when already in one) |
|
||||
| Python | `--python` | Python version to use (e.g., `3.11`) |
|
||||
| Extra Packages | `--with` | Additional packages to install (repeatable) |
|
||||
| Project | `--project` | Run within a specific uv project directory |
|
||||
| Requirements | `--with-requirements` | Install from a requirements file |
|
||||
|
||||
### Dependency Management
|
||||
|
||||
By default, `fastmcp run` uses your current Python environment directly. When you pass `--python`, `--with`, `--project`, or `--with-requirements`, it switches to running via `uv run` in a subprocess, which handles dependency isolation automatically.
|
||||
|
||||
The `--skip-env` flag is useful when you're already inside an activated venv, a Docker container with pre-installed dependencies, or a uv-managed project — it prevents uv from trying to set up another environment layer.
|
||||
|
||||
## Previewing Apps
|
||||
|
||||
<VersionBadge version="3.2.0" />
|
||||
|
||||
`fastmcp dev apps` launches a browser-based preview UI for servers with [Prefab App tools](/apps/prefab). It starts your MCP server on one port and a local dev UI on another — giving you a live, interactive picker where you can call app tools and see their rendered output without needing a full MCP host client.
|
||||
|
||||
```bash
|
||||
fastmcp dev apps server.py
|
||||
fastmcp dev apps server.py:mcp --mcp-port 9000 --dev-port 9090
|
||||
```
|
||||
|
||||
The picker auto-generates a form from each tool's input schema. Submit the form and the result opens in a new tab as a rendered Prefab UI.
|
||||
|
||||
Auto-reload is on by default — save a file and the MCP server restarts automatically.
|
||||
|
||||
<Tip>
|
||||
`fastmcp dev apps` requires `fastmcp[apps]` — install with `pip install "fastmcp[apps]"`.
|
||||
</Tip>
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| MCP Port | `--mcp-port` | Port for the MCP server (default: `8000`) |
|
||||
| Dev Port | `--dev-port` | Port for the dev UI (default: `8080`) |
|
||||
| Auto-Reload | `--reload` / `--no-reload` | Watch for file changes (default: on) |
|
||||
|
||||
## Development with the Inspector
|
||||
|
||||
`fastmcp dev inspector` launches your server inside the [MCP Inspector](https://github.com/modelcontextprotocol/inspector), a browser-based tool for interactively testing MCP servers. Auto-reload is on by default, so your server restarts when you save changes.
|
||||
|
||||
```bash
|
||||
fastmcp dev inspector server.py
|
||||
fastmcp dev inspector server.py -e . --with pandas
|
||||
```
|
||||
|
||||
<Tip>
|
||||
The Inspector always runs your server via `uv run` in a subprocess — it never uses your local environment directly. Specify dependencies with `--with`, `--with-editable`, `--with-requirements`, or through a `fastmcp.json` file.
|
||||
</Tip>
|
||||
|
||||
<Warning>
|
||||
The Inspector connects over **stdio only**. When it launches, you may need to select "STDIO" from the transport dropdown and click connect. To test a server over HTTP, start it separately with `fastmcp run server.py --transport http` and point the Inspector at the URL.
|
||||
</Warning>
|
||||
|
||||
| Option | Flag | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| Editable Package | `--with-editable`, `-e` | Install a directory in editable mode |
|
||||
| Extra Packages | `--with` | Additional packages (repeatable) |
|
||||
| Inspector Version | `--inspector-version` | MCP Inspector version to use |
|
||||
| UI Port | `--ui-port` | Port for the Inspector UI |
|
||||
| Server Port | `--server-port` | Port for the Inspector proxy |
|
||||
| Auto-Reload | `--reload` / `--no-reload` | File watching (default: on) |
|
||||
| Reload Dirs | `--reload-dir` | Directories to watch (repeatable) |
|
||||
| Python | `--python` | Python version |
|
||||
| Project | `--project` | Run within a uv project directory |
|
||||
| Requirements | `--with-requirements` | Install from a requirements file |
|
||||
|
||||
## Pre-Building Environments
|
||||
|
||||
`fastmcp project prepare` creates a persistent uv project from a `fastmcp.json` file, pre-installing all dependencies. This separates environment setup from server execution — install once, run many times.
|
||||
|
||||
```bash
|
||||
# Step 1: Build the environment (slow, does dependency resolution)
|
||||
fastmcp project prepare fastmcp.json --output-dir ./env
|
||||
|
||||
# Step 2: Run using the prepared environment (fast, no install step)
|
||||
fastmcp run fastmcp.json --project ./env
|
||||
```
|
||||
|
||||
The prepared directory contains a `pyproject.toml`, a `.venv` with all packages installed, and a `uv.lock` for reproducibility. This is particularly useful in deployment scenarios where you want deterministic, pre-built environments.
|
||||
Reference in New Issue
Block a user