MCP测试库
用于运行模型上下文协议(MCP)测试的CLI工具。
特性
- 用于运行MCP测试的CLI工具
- 支持运行单个测试文件或测试模式
- 可配置的测试超时和排除模式
- 详细输出的详细模式
- 用TypeScript编写,完全支持类型
- 与模型上下文协议SDK兼容
- 彩色测试输出,可读性更好
- 全面的测试覆盖率
安装
要在项目中作为开发依赖项安装,请执行以下操作:
npm install --save-dev mcp-testing-library用法
命令行选项
Usage: mcpt [options] [test-files...]
Options:
-v, --version output version number
-e, --exclude
Exclude files matching the pattern (comma-separated)
(default: "**/node_modules/**,**/dist/**")
-t, --timeout Set test timeout in milliseconds (default: "30000")
--pattern Test file pattern to match (default: "**/*.test.{js,ts}")
--no-color Disable colored output
-h, --help display help for command例子
运行项目中的所有测试:
mcpt运行特定的测试文件:
mcpt sample/index.test.ts运行超时时间较长的测试:
mcpt --timeout 10000运行没有颜色输出的测试:
mcpt --no-color排除特定目录:
mcpt --exclude "**/node_modules/**,**/dist/**,**/build/**"在代码中使用
您还可以直接在代码中使用MCP测试实用程序:
import { mcpt, expect } from 'mcp-testing-library';
// Test a filesystem MCP server
mcpt(
{
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/path/to/directory'],
},
async ({ tools, prompts, resources, isMethodExist }) => {
expect(tools.length).to.be.greaterThan(0);
expect(await isMethodExist('list-tools')).to.eq(true);
// More assertions...
}
);许可证
麻省理工学院

