用途:@gleanwork/mcp-server-tester 是面向 Model Context Protocol(MCP)服务器的、基于 Playwright 的测试与评估框架,用于自动化测试 MCP 工具、运行数据驱动评估并模拟 MCP 主机。要求 Node.js >= 22.0.0 与 Playwright。
主要能力:提供 Playwright fixtures 进行 MCP 工具测试;支持带可选 LLM-as-a-judge 评分的数据驱动评估数据集;可通过真实 LLM 提供商(Anthropic、OpenAI、Google 等)模拟 MCP 主机;提供带交互式 UI 的自定义 Playwright 报告器。
使用方式:包暴露四个入口——主库(类型、验证器、评估运行器、评审、配置)、测试 fixtures(test 与 expect 及 MCP 匹配器)、认证 fixtures、自定义报告器。测试文件中必须从 @gleanwork/mcp-server-tester/fixtures/mcp 导入 test 和 expect,主入口的 expect 不含 MCP 匹配器。在 playwright.config.ts 的 project.use 中配置 mcpConfig,支持 stdio 与 http(Streamable HTTP/SSE)传输。11 个匹配器包括 toMatchToolResponse、toContainToolText、toMatchToolPattern、toMatchToolSchema、toMatchToolSnapshot、toBeToolError、toPassToolJudge、toHaveToolResponseSize、toSatisfyToolPredicate、toHaveToolCalls、toHaveToolCallCount。评估数据集从 JSON 加载,通过 loadEvalDataset 与 runEvalDataset 运行。两种模式:direct(默认,调用指定工具,快速确定且免费)与 mcp_host(LLM 根据自然语言场景发现工具,非确定、有成本,用于衡量工具描述质量)。CLI 命令:npx mcp-server-tester init、npx mcp-server-tester generate。认证支持静态 token、OAuth 2.1 with PKCE、客户端凭证。快照支持内置与自定义 sanitizer,更新用 npx playwright test --update-snapshots。LLM 评审内置 rubric 与多种提供商,可注册自定义评审。
限制与注意:异步匹配器需 await;toHaveToolCalls 与 toHaveToolCallCount 仅适用于 mcp_host 模式;快照需 Playwright testInfo;mcp_host 模式需安装 ai 及对应提供商包并设置环境变量;runEvalDataset 第一个参数为选项对象,第二个为上下文对象。资料未提供收费、价格与效果信息。