
MCP Testing Library

2025.04.10
0
TypeScript测试工具CLI工具开发效率
MCP Testing Library 是一个用于运行 Model Context Protocol (MCP) 测试的 CLI 工具。它提供了丰富的功能来帮助开发者高效地运行和调试 MCP 测试。
View on GitHub
Overview
基本能力
产品定位
MCP Testing Library 是一个专门为 Model Context Protocol (MCP) 测试设计的命令行工具,旨在简化测试流程并提供丰富的测试功能。
核心功能
- CLI 工具,支持运行单个测试文件或测试模式
- 可配置的测试超时和排除模式
- 详细输出模式(Verbose mode)
- 使用 TypeScript 编写,提供完整的类型支持
- 与 Model Context Protocol SDK 兼容
- 彩色测试输出,提高可读性
- 全面的测试覆盖率
适用场景
- 开发过程中运行 MCP 测试
- 调试 MCP 服务器或工具
- 自动化测试流程
工具列表
mcpt
:主命令行工具,用于运行 MCP 测试- 支持多种命令行选项,如超时设置、排除模式、彩色输出等
- 可以直接在代码中使用测试工具
常见问题解答
- 如何安装?
- 使用
npm install --save-dev mcp-testing-library
安装 - 如何运行特定测试文件?
- 使用
mcpt sample/index.test.ts
命令 - 如何设置测试超时?
- 使用
--timeout
选项,如mcpt --timeout 10000
使用教程
使用依赖
- 需要安装 Node.js 和 npm
安装教程
npm install --save-dev mcp-testing-library
调试方式
运行所有测试:
mcpt
运行特定测试文件:
mcpt sample/index.test.ts
设置测试超时:
mcpt --timeout 10000
禁用彩色输出:
mcpt --no-color
排除特定目录:
mcpt --exclude "**/node_modules/**,**/dist/**,**/build/**"
在代码中使用测试工具:
import { mcpt, expect } from 'mcp-testing-library';
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);
}
);