mcpField
F
fastmcp-client-cli

fastmcp-client-cli

github.com/prefecthqAgent 工作流28.2k148 次安装今天更新
代码仓库

关于 fastmcp-client-cli

fastmcp-client-cli 提供通过命令行发现 MCP 服务、列出工具并调用工具的能力,面向需要检查或操作已配置服务的开发者。它支持多种服务目标,并可扫描常见编辑器和项目配置。

主要功能

  1. 01发现已配置的 MCP 服务
  2. 02列出工具及其参数结构
  3. 03调用工具并自动转换参数类型
  4. 04支持 HTTP、SSE、stdio 和 Python 文件
  5. 05支持 OAuth 与结构化输出

适用场景

  1. 01查看编辑器配置中可用的 MCP 服务
  2. 02检查远程或本地服务提供的工具
  3. 03从命令行执行工具并传入参数
  4. 04调试工具输入和输出结构

MCP 相关

通过命令行连接 MCP 服务,列出其工具并调用工具。目标可来自 URL、本地 Python 文件、MCPConfig、stdio 命令或已发现的配置名称。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/prefecthq/fastmcp --skill fastmcp-client-cli

安装后在 Claude Code 中输入/fastmcp-client-cli确认已加载。

详细介绍

FastMCP 命令行工具:列出和调用

使用 fastmcp list 和 fastmcp call,通过命令行与任意 MCP 服务交互。

列出工具

# 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 Schema,使用 --json 获取结构化输出。

调用工具

# 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

系统会自动进行类型转换:根据工具的输入 Schema,limit=5 会转换为整数,verbose=true 会转换为布尔值。

服务目标

所有命令均接受相同的服务目标:

目标示例
HTTP/HTTPS URLhttp://localhost:8000/mcp
Python 文件server.py
MCPConfig JSONmcp.json(必须包含 mcpServers 键)
Stdio 命令--command 'npx -y @mcp/server'
已发现的名称weather 或 source:name

可按名称引用编辑器配置(Claude Desktop、Claude Code、Cursor、Gemini CLI、Goose)或项目级 mcp.json 中配置的服务。使用 source:name(例如 claude-code:my-server、cursor:weather)指定特定来源。运行 fastmcp discover 查看可用名称。

对于 SSE 服务,请传入 --transport sse:

fastmcp list http://localhost:8000/mcp --transport sse

身份验证

HTTP 目标会自动使用 OAuth(如果服务不需要身份验证,则不执行任何操作)。使用 --auth none 禁用:

fastmcp call http://server/mcp tool --auth none

发现已配置的服务

# See all MCP servers in editor/project configs
fastmcp discover

# Filter by source
fastmcp discover --source claude-code

# JSON output
fastmcp discover --json

扫描 Claude Desktop、Claude Code、Cursor、Gemini CLI、Goose 和 ./mcp.json。来源:claude-desktop、claude-code、cursor、gemini、goose、project。

工作流模式

先发现工具,然后调用它们:

# 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 会建议名称相近的工具。

评论

支持 Markdown