FastMCP 命令行工具列表与调用机制

介绍 FastMCP CLI 的 list 与 call 命令,说明如何从命令行查看 MCP 服务器工具签名与描述,并以键值对或 JSON 传入参数调用工具,同时覆盖服务器目标类型、认证与配置发现。

# FastMCP CLI:列表与呼叫 使用( U) `fastmcp list` 财务报告和财务报告 `fastmcp call` 用于与命令行中的任何MCP服务器交互。 ## 列出工具 ```bash # Remote server fastmcp list http://localhost:8000/mcp # Local Python file (runs via fastmcp run automatically) fastmcp list server.py # MCPConfig with multiple servers fastmcp list mcp.json # Stdio command (npx, uvx, etc.) fastmcp list --command 'npx -y @modelcontextprotocol/server-github' # Include full input/output schemas fastmcp list server.py --input-schema --output-schema # Machine-readable JSON fastmcp list server.py --json # Include resources and prompts fastmcp list server.py --resources --prompts ``` 默认输出显示工具签名和描述。 使用 `--input-schema` 或 时 间 `--output-schema` 包括完整的JSON计划, `--json` 用于结构化输出。 ## 调用工具 ```bash # Key=value arguments (auto-coerced to correct types) fastmcp call server.py greet name=World fastmcp call server.py add a=3 b=4 # Single JSON object for complex/nested args fastmcp call server.py create_item '{"name": "Widget", "tags": ["a", "b"]}' # --input-json with key=value overrides fastmcp call server.py search --input-json '{"query": "hello", "limit": 5}' limit=10 # JSON output for scripting fastmcp call server.py add a=3 b=4 --json ``` 类型强制是自动的 : `limit=5` 变成整数, `verbose=true` 成为布尔,基于工具的输入方案。 ## 服务器目标 所有命令接受相同的服务器目标 : | 目标 | 示例 | |--------|---------| | HTTP/HTTPS URL | `http://localhost:8000/mcp` | | Python 文件 | `server.py` | | CPCONFIG JSON 互联网档案馆的存檔。 | `mcp.json` (必须) `mcpServers` 键) | | Stdio 命令 | `--command 'npx -y @mcp/server'` | | 已发现名称 | `weather` 或 时 间 `source:name` | 在编辑器配置中配置的服务器( Claude 桌面、 Claude 代码、 Cursor、 Gemini CLI、 Goose) 或工程级别 `mcp.json` 名称。使用 `source:name` (e.g. `claude-code:my-server`, `cursor:weather`)以特定源为目标。运行 `fastmcp discover` 以查看可用名称。 对于SSE服务器,通过 `--transport sse`: ```bash fastmcp list http://localhost:8000/mcp --transport sse ``` ## 自动 HTTP 目标自动使用 OAuth( 如果服务器不需要认证则不使用)。 禁用 `--auth none`: ```bash fastmcp call http://server/mcp tool --auth none ``` ## 发现配置的服务器 ```bash # See all MCP servers in editor/project configs fastmcp discover # Filter by source fastmcp discover --source claude-code # JSON output fastmcp discover --json ``` 扫描Claude桌面、Claude代码、Cursor、双子体CLI、Goose和 `./mcp.json`来源 : `claude-desktop`, `claude-code`, `cursor`, `gemini`, `goose`, `project`. ## 工作流程模式 发现工具,然后叫它们: ```bash # 1. See what servers are configured fastmcp discover # 2. See what tools a server has fastmcp list weather # 3. Call a tool fastmcp call weather get_forecast city=London ``` 如果您调用一个不存在的工具, FastMCP 表示接近匹配 。

查看原始来源