|
| 1 | +# MCP Inspector CLI Client |
| 2 | + |
| 3 | +The CLI mode enables programmatic interaction with MCP servers from the command line. It is ideal for scripting, automation, continuous integration, and establishing an efficient feedback loop with AI coding assistants. |
| 4 | + |
| 5 | +## Running the CLI |
| 6 | + |
| 7 | +You can run the CLI client directly via `npx`: |
| 8 | + |
| 9 | +```bash |
| 10 | +npx @modelcontextprotocol/inspector --cli node build/index.js |
| 11 | +``` |
| 12 | + |
| 13 | +The CLI mode supports operations across tools, resources, and prompts, returning structured JSON output. |
| 14 | + |
| 15 | +### Examples |
| 16 | + |
| 17 | +**Basic usage** |
| 18 | + |
| 19 | +```bash |
| 20 | +npx @modelcontextprotocol/inspector --cli node build/index.js |
| 21 | +``` |
| 22 | + |
| 23 | +**With a configuration file** |
| 24 | + |
| 25 | +```bash |
| 26 | +npx @modelcontextprotocol/inspector --cli --config path/to/config.json --server myserver |
| 27 | +``` |
| 28 | + |
| 29 | +**List available tools** |
| 30 | + |
| 31 | +```bash |
| 32 | +npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list |
| 33 | +``` |
| 34 | + |
| 35 | +**Call a specific tool** |
| 36 | + |
| 37 | +```bash |
| 38 | +npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name mytool --tool-arg key=value --tool-arg another=value2 |
| 39 | +``` |
| 40 | + |
| 41 | +**Call a tool with JSON arguments** |
| 42 | + |
| 43 | +```bash |
| 44 | +npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name mytool --tool-arg 'options={"format": "json", "max_tokens": 100}' |
| 45 | +``` |
| 46 | + |
| 47 | +**List available resources** |
| 48 | + |
| 49 | +```bash |
| 50 | +npx @modelcontextprotocol/inspector --cli node build/index.js --method resources/list |
| 51 | +``` |
| 52 | + |
| 53 | +**List available prompts** |
| 54 | + |
| 55 | +```bash |
| 56 | +npx @modelcontextprotocol/inspector --cli node build/index.js --method prompts/list |
| 57 | +``` |
| 58 | + |
| 59 | +### Remote Servers |
| 60 | + |
| 61 | +You can also connect to remote MCP servers using HTTP or SSE transports. |
| 62 | + |
| 63 | +**Connect to a remote MCP server (default is SSE)** |
| 64 | + |
| 65 | +```bash |
| 66 | +npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com |
| 67 | +``` |
| 68 | + |
| 69 | +**Connect with Streamable HTTP transport** |
| 70 | + |
| 71 | +```bash |
| 72 | +npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --transport http --method tools/list |
| 73 | +``` |
| 74 | + |
| 75 | +**Pass custom headers** |
| 76 | + |
| 77 | +```bash |
| 78 | +npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --transport http --method tools/list --header "X-API-Key: your-api-key" |
| 79 | +``` |
| 80 | + |
| 81 | +## Options |
| 82 | + |
| 83 | +### MCP server (which server to connect to) |
| 84 | + |
| 85 | +Options that specify the MCP server (config file, ad-hoc command/URL, env vars, headers) are shared by the Web, CLI, and TUI and are documented in [MCP server configuration](../../docs/mcp-server-configuration.md): `--config`, `--server`, `-e`, `--cwd`, `--header`, `--transport`, `--server-url`, and the positional `[target...]`. |
| 86 | + |
| 87 | +### CLI-specific (what to invoke) |
| 88 | + |
| 89 | +| Option | Description | |
| 90 | +| ----------------------------- | ----------------------------------------------------------------------------------------- | |
| 91 | +| `--method <method>` | MCP method to invoke (e.g. `tools/list`, `tools/call`, `resources/list`, `prompts/list`). | |
| 92 | +| `--tool-name <name>` | Tool name (for `tools/call`). | |
| 93 | +| `--tool-arg <key=value>` | Tool argument; repeat for multiple. Use `key='{"json":true}'` for JSON. | |
| 94 | +| `--uri <uri>` | Resource URI (for `resources/read`). | |
| 95 | +| `--prompt-name <name>` | Prompt name (for `prompts/get`). | |
| 96 | +| `--prompt-args <key=value>` | Prompt arguments; repeat for multiple. | |
| 97 | +| `--log-level <level>` | Logging level for `logging/setLevel` (e.g. `debug`, `info`). | |
| 98 | +| `--metadata <key=value>` | General metadata (key=value); applied to all methods. | |
| 99 | +| `--tool-metadata <key=value>` | Tool-specific metadata for `tools/call`. | |
| 100 | + |
| 101 | +## Why use the CLI? |
| 102 | + |
| 103 | +While the Web Client provides a rich visual interface, the CLI is designed for: |
| 104 | + |
| 105 | +- **Automation**: Ideal for CI/CD pipelines and batch processing. |
| 106 | +- **AI Coding Assistants**: Provides a direct, machine-readable interface (JSON) for tools like Cursor or Claude to verify changes immediately. |
| 107 | +- **Log Analysis**: Easier integration with command-line utilities (like `jq`) to process and analyze MCP server output. |
0 commit comments