mcp-assert 是做什么的?
MCP服务器的确定性测试标准。通过真实的 stdio/SSE/HTTP 传输连接,使用真实参数调用工具,通过 YAML 定义的 18 种断言类型验证结果。支持任何语言、任何传输方式,无需模拟。单个 Go 二进制文件。
特性
- 真实传输连接:通过 stdio、SSE 或 HTTP 直接连接到 MCP 服务器,不使用任何模拟或存根。
- 真实参数调用:使用实际参数调用工具,测试真实行为。
- 18 种断言类型:通过 YAML 定义的丰富断言类型,涵盖相等性、类型、范围、包含、正则匹配等。
- 语言无关:支持任何实现了 MCP 协议的服务器,无论其开发语言是什么。
- 传输无关:支持所有标准的 MCP 传输方式。
- 无模拟:测试真实行为,不依赖模拟对象或模拟服务。
- 单二进制分发:作为单一的 Go 二进制文件提供,易于集成和部署。
安装
# 下载适用于您平台的最新版本
curl -LO https://github.com/blackwell-systems/mcp-assert/releases/latest/download/mcp-assert-linux-amd64.tar.gz
tar -xzf mcp-assert-linux-amd64.tar.gz
sudo mv mcp-assert /usr/local/bin/
或者从 Releases 页面 手动下载。
基本用法
- 编写一个包含测试用例的 YAML 文件(例如
tests.yaml):
transport:
type: stdio
command: python
args: ["server.py"]
tests:
- name: "测试示例工具"
tool: "example_tool"
arguments:
input: "hello"
assertions:
- type: equals
path: "$.result"
value: "HELLO"
- 运行测试:
mcp-assert --file tests.yaml
断言类型
mcp-assert 支持以下 18 种断言类型:
| 断言类型 | 描述 |
|---|---|
equals | 值与预期完全相同 |
notEquals | 值不等于预期 |
contains | 字符串或数组包含预期值 |
notContains | 字符串或数组不包含预期值 |
type | 值的类型与预期匹配 |
pattern | 字符串匹配正则表达式 |
greaterThan | 数值大于预期值 |
lessThan | 数值小于预期值 |
greaterThanOrEqual | 数值大于等于预期值 |
lessThanOrEqual | 数值小于等于预期值 |
isPresent | 路径存在 |
isAbsent | 路径不存在 |
length | 数组或字符串长度等于预期值 |
isEmpty | 数组或字符串为空 |
isNotEmpty | 数组或字符串不为空 |
isNull | 值为 null |
isNotNull | 值不为 null |
isBoolean | 值为布尔类型 |
传输配置
stdio
transport:
type: stdio
command: node
args: ["server.js"]
env:
DEBUG: true
SSE
transport:
type: sse
url: "http://localhost:3000/sse"
headers:
Authorization: "Bearer token123"
HTTP
transport:
type: http
url: "http://localhost:8080"
CI/CD 集成
GitHub Actions
name: 测试 MCP 服务器
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 安装 mcp-assert
run: |
curl -LO https://github.com/blackwell-systems/mcp-assert/releases/latest/download/mcp-assert-linux-amd64.tar.gz
tar -xzf mcp-assert-linux-amd64.tar.gz
sudo mv mcp-assert /usr/local/bin/
- name: 运行测试
run: mcp-assert --file tests.yaml
完整示例
查看 examples/ 目录获取完整的示例项目。
许可证
本项目采用 MIT 许可证。
贡献
欢迎贡献!请参阅 CONTRIBUTING.md 了解详情。