MCP E2E测试工具
用于对模型上下文协议(MCP)服务器运行端到端测试的命令行工具。
特性
- 基于YAML的配置:在简单的YAML文件中定义服务器和测试用例
- 多服务器支持:同时测试多个MCP服务器
- 多个配置文件:支持加载具有自动命名空间的多个配置文件
- 灵活的测试过滤:使用名称筛选器运行特定测试
- 多种输出格式:支持人类可读文本和JSON输出
- 超时控制:服务器启动和测试执行的可配置超时
- 平滑关闭:正确清理服务器进程
安装
go build -o mcp-e2e .用法
基本用法
# Run all tests using default configuration (sample.yaml)
./mcp-e2e
# Use a custom configuration file
./mcp-e2e example.yaml
# Use multiple configuration files (automatic namespacing)
./mcp-e2e config1.yaml config2.yaml
# Run specific tests by name filter
./mcp-e2e --test echo
# Output results in JSON format
./mcp-e2e --output json
# Set custom timeout
./mcp-e2e --timeout 60s多个配置文件
使用多个配置文件时,mcp-e2e会自动应用命名空间以防止服务器名称冲突:
# These files can have the same server names
./mcp-e2e file1.yaml file2.yaml如果两者都有 file1.yaml 和 file2.yaml 定义一个名为的服务器 echo_server,它们将被自动命名为:
file1:echo_serverfile2:echo_server
命名空间基于文件名(不带扩展名),并将特殊字符转换为下划线以确保安全。
例子:
my-config.yaml→ 命名空间:my_configtest_server@v1.yaml→ 命名空间:test_server_v1
配置文件格式
配置文件使用具有以下结构的YAML格式:
version: 1
servers:
server_name:
type: stdio # Currently only 'stdio' is supported
cmd: command_name # Command to start the server
args: # Command arguments
- arg1
- arg2
tests:
- name: test_name # Unique test name
server: server_name # Reference to server defined above
method: method_name # MCP method to call
params: # Parameters to pass to the method
key: value支持的MCP方法
tools/list:列出可用工具tools/call:调用特定工具resources/list:列出可用资源prompts/list:列出可用提示
配置示例
看 sample.yaml 和 example.yaml 查看完整示例。
回声工具的示例测试
version: 1
servers:
everything:
type: stdio
cmd: npx
args:
- -y
- "@modelcontextprotocol/server-everything"
tests:
- name: echo_test
server: everything
method: tools/call
params:
name: echo
arguments:
message: "Hello, MCP!"命令行选项
[files...]:配置文件的路径(默认:“sample.yaml”)-t, --test:按名称筛选测试(子字符串匹配)-o, --output:输出格式:“text”或“json”(默认为“text”)--timeout:服务器启动和测试执行超时(默认值:30秒)-l, --log-level:日志级别:调试、信息、警告、错误(默认值:“信息”)-r, --raw:输出原始MCP服务器响应-h, --help:显示帮助消息
输出格式
文本输出(默认)
显示测试结果和详细信息的人类可读格式。
JSON输出
适合与其他工具集成的机器可读JSON格式:
{
"results": [
{
"name": "test_name",
"server": "server_name",
"method": "method_name",
"success": true,
"duration": 1234567,
"response": { ... }
}
],
"summary": {
"total": 1,
"passed": 1,
"failed": 0
}
}退出代码
0:所有测试均通过1:一个或多个测试失败或发生错误
需求
- 转到1.24.2或更高版本
- Node.js和npm(用于MCP服务器示例)
