|
| 1 | +--- |
| 2 | +title: Client Commands |
| 3 | +sidebarTitle: Client |
| 4 | +description: List tools, call them, and discover configured servers |
| 5 | +icon: satellite-dish |
| 6 | +--- |
| 7 | + |
| 8 | +import { VersionBadge } from '/snippets/version-badge.mdx' |
| 9 | + |
| 10 | +<VersionBadge version="3.0.0" /> |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | +## Listing Tools |
| 15 | + |
| 16 | +`fastmcp list` connects to a server and prints its tools as function signatures, showing parameter names, types, and descriptions at a glance: |
| 17 | + |
| 18 | +```bash |
| 19 | +fastmcp list http://localhost:8000/mcp |
| 20 | +fastmcp list server.py |
| 21 | +fastmcp list weather # name-based resolution |
| 22 | +``` |
| 23 | + |
| 24 | +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`: |
| 25 | + |
| 26 | +```bash |
| 27 | +fastmcp list server.py --input-schema |
| 28 | +``` |
| 29 | + |
| 30 | +### Resources and Prompts |
| 31 | + |
| 32 | +By default, only tools are shown. Add `--resources` or `--prompts` to include those: |
| 33 | + |
| 34 | +```bash |
| 35 | +fastmcp list server.py --resources --prompts |
| 36 | +``` |
| 37 | + |
| 38 | +### Machine-Readable Output |
| 39 | + |
| 40 | +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: |
| 41 | + |
| 42 | +```bash |
| 43 | +fastmcp list server.py --json |
| 44 | +``` |
| 45 | + |
| 46 | +### Options |
| 47 | + |
| 48 | +| Option | Flag | Description | |
| 49 | +| ------ | ---- | ----------- | |
| 50 | +| Command | `--command` | Connect via stdio (e.g., `'npx -y @mcp/server'`) | |
| 51 | +| Transport | `--transport`, `-t` | Force `http` or `sse` for URL targets | |
| 52 | +| Resources | `--resources` | Include resources in output | |
| 53 | +| Prompts | `--prompts` | Include prompts in output | |
| 54 | +| Input Schema | `--input-schema` | Show full input schemas | |
| 55 | +| Output Schema | `--output-schema` | Show full output schemas | |
| 56 | +| JSON | `--json` | Structured JSON output | |
| 57 | +| Timeout | `--timeout` | Connection timeout in seconds | |
| 58 | +| Auth | `--auth` | `oauth` (default for HTTP), a bearer token, or `none` | |
| 59 | + |
| 60 | +## Calling Tools |
| 61 | + |
| 62 | +`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: |
| 63 | + |
| 64 | +```bash |
| 65 | +fastmcp call server.py greet name=World |
| 66 | +fastmcp call http://localhost:8000/mcp search query=hello limit=5 |
| 67 | +``` |
| 68 | + |
| 69 | +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. |
| 70 | + |
| 71 | +### Complex Arguments |
| 72 | + |
| 73 | +For tools with nested or structured parameters, `key=value` syntax gets awkward. Pass a single JSON object instead: |
| 74 | + |
| 75 | +```bash |
| 76 | +fastmcp call server.py create_item '{"name": "Widget", "tags": ["sale"], "metadata": {"color": "blue"}}' |
| 77 | +``` |
| 78 | + |
| 79 | +Or use `--input-json` to provide a base dictionary, then override individual keys with `key=value` pairs: |
| 80 | + |
| 81 | +```bash |
| 82 | +fastmcp call server.py search --input-json '{"query": "hello", "limit": 5}' limit=10 |
| 83 | +``` |
| 84 | + |
| 85 | +### Error Handling |
| 86 | + |
| 87 | +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. |
| 88 | + |
| 89 | +### Structured Output |
| 90 | + |
| 91 | +`--json` emits the raw result including content blocks, error status, and structured content: |
| 92 | + |
| 93 | +```bash |
| 94 | +fastmcp call server.py get_weather city=London --json |
| 95 | +``` |
| 96 | + |
| 97 | +### Interactive Elicitation |
| 98 | + |
| 99 | +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. |
| 100 | + |
| 101 | +### Options |
| 102 | + |
| 103 | +| Option | Flag | Description | |
| 104 | +| ------ | ---- | ----------- | |
| 105 | +| Command | `--command` | Connect via stdio | |
| 106 | +| Transport | `--transport`, `-t` | Force `http` or `sse` | |
| 107 | +| Input JSON | `--input-json` | Base arguments as JSON (merged with `key=value`) | |
| 108 | +| JSON | `--json` | Raw JSON output | |
| 109 | +| Timeout | `--timeout` | Connection timeout in seconds | |
| 110 | +| Auth | `--auth` | `oauth`, a bearer token, or `none` | |
| 111 | + |
| 112 | +## Discovering Configured Servers |
| 113 | + |
| 114 | +`fastmcp discover` scans your machine for MCP servers configured in editors and tools. It checks: |
| 115 | + |
| 116 | +- **Claude Desktop** — `claude_desktop_config.json` |
| 117 | +- **Claude Code** — `~/.claude.json` |
| 118 | +- **Cursor** — `.cursor/mcp.json` (walks up from current directory) |
| 119 | +- **Gemini CLI** — `~/.gemini/settings.json` |
| 120 | +- **Goose** — `~/.config/goose/config.yaml` |
| 121 | +- **Project** — `./mcp.json` in the current directory |
| 122 | + |
| 123 | +```bash |
| 124 | +fastmcp discover |
| 125 | +``` |
| 126 | + |
| 127 | +The output groups servers by source, showing each server's name and transport. Filter by source or get machine-readable output: |
| 128 | + |
| 129 | +```bash |
| 130 | +fastmcp discover --source claude-code |
| 131 | +fastmcp discover --source cursor --source gemini --json |
| 132 | +``` |
| 133 | + |
| 134 | +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. |
| 135 | + |
| 136 | +## LLM Agent Integration |
| 137 | + |
| 138 | +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. |
| 139 | + |
| 140 | +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. |
0 commit comments