MCP测试库

一个用于运行模型上下文协议(MCP)测试的CLI工具,支持单个测试文件或测试模式运行,可配置测试超时和排除模式,具有详细的输出模式和全面的测试覆盖。

  • by moeki0
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 moekiorg/mcp-testing-library

使用说明

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 <patterns>  Exclude files matching the pattern (comma-separated)
                           (default: "**/node_modules/**,**/dist/**")
  -t, --timeout <ms>        Set test timeout in milliseconds (default: "30000")
  --pattern <glob>          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...
  }
);

许可证

麻省理工学院