mcpField
M
MCP Client for Testing

MCP Client for Testing

本地服务
github.com/piebro开发工具278 周前更新

关于 MCP Client for Testing

MCP Client for Testing 是一个用于测试 MCP 服务工具调用的轻量客户端,适合开发者验证服务端工具。它既可通过命令行运行,也可作为 Python 包在代码中调用。

主要功能

  1. 01测试 MCP 工具调用
  2. 02通过命令行运行
  3. 03提供 Python 调用接口

适用场景

  1. 01验证 MCP 服务工具响应
  2. 02在脚本中执行工具调用

MCP 相关

它作为 MCP 客户端连接配置的 MCP 服务,并执行工具调用以进行测试。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"client-for-testing": {
"command": "uvx",
"args": [
"mcp-client-for-testing"
]
}
}
}
启动命令uvx mcp-client-for-testing

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
pypimcp-client-for-testing

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

用于测试的 MCP 客户端

一个精简的 MCP(Model Context Protocol)客户端,用于测试 MCP 服务中的工具调用。

用法

安装 uv,然后像这样测试 MCP 服务中的工具调用:

uvx mcp-client-for-testing \
    --config '
    [
        {
            "name": "name of mcp server",
            "command": "uv",
            "args": [
                "--directory", 
                "path/to/root/dir/", 
                "run", 
                "server.py"
            ],
            "env": {}
        }
    ]
    ' \
    --client_log_level "WARNING" \
    --server_log_level "INFO" \
    --tool_call '{"name": "tool-name", "arguments": {}}'

要在代码中使用它,请安装此软件包:

uv pip install mcp-client-for-testing 

然后像这样使用:

import asyncio

from mcp_client_for_testing.client import execute_tool

async def main():
    config = [
        {
            "name": "name of mcp server",
            "command": "uv",
            "args": [
                "--directory", 
                "path/to/root/dir/", 
                "run", 
                "server.py"
            ],
            "env": {}
        }
    ]
    tool_call = {"name": "tool-name", "arguments": {}}
    
    await execute_tool(config, tool_call)

if __name__ == "__main__":
    asyncio.run(main())

示例

使用 uvx 运行 echo-mcp-server-for-testing,以测试 MCP 客户端。

uvx mcp-client-for-testing \
    --config '
    [
        {
            "name": "echo-mcp-server-for-testing",
            "command": "uvx",
            "args": [
                "echo-mcp-server-for-testing"
            ],
            "env": {
                "SECRET_KEY": "123456789"
            }
        }
    ]
    ' \
    --client_log_level "WARNING" \
	--server_log_level "INFO" \
    --tool_call '{"name": "echo_tool", "arguments": {"message": "Hello, world!"}}'

开发

从源代码安装
  1. 克隆仓库 git clone [email protected]:piebro/mcp-client-for-testing.git。
  2. 进入根目录 cd mcp-client-for-testing。
  3. 以开发模式安装:uv pip install -e .
格式化和代码检查

代码使用 ruff 进行格式化和代码检查:

uv run ruff format
uv run ruff check --fix
使用 uv 构建

使用 uv 构建软件包:

uv build
发布新版本

要向 PyPI 发布新版本的软件包,请创建并推送新的 Git 标签:

  1. 切换到 main 分支并获取当前版本:

    git checkout main
    git pull origin main
    git describe --tags
    
  2. 创建并推送新的 Git 标签:

    git tag v0.2.0
    git push origin v0.2.0
    

推送新标签后,GitHub Actions 工作流会自动构建软件包并将其发布到 PyPI。 Python 软件包的版本号将直接从 Git 标签中获取。

许可证

本项目采用 MIT 许可证。详情请参阅 LICENSE 文件。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。