用途:为 MCP 服务器工具生成 Playwright 测试文件,使用 @gleanwork/mcp-server-tester 在直连模式下调用工具并做断言。
主要能力:通过 mcp.callTool 调用工具后,可用 toContainToolText、toBeToolError、toMatchToolPattern、toMatchToolSchema(Zod)做内容与结构校验;用 toMatchToolSnapshot 做快照对比,并支持 uuid、timestamp、iso-date、remove、pattern 等清洗器;用 toHaveToolResponseSize 校验响应大小;用 toPassToolJudge 调用 LLM 按内置或自定义评分标准评估,内置标准包括 correctness、completeness、groundedness、instruction-following、conciseness;还可用 toSatisfyToolPredicate 自定义断言,以及 toMatchToolResponse 做精确匹配。
必要用法:项目需安装 @gleanwork/mcp-server-tester 与 @playwright/test,playwright.config.ts 中至少一个项目需配置 mcpConfig,可选择 stdio 或 http 传输;测试文件必须从 @gleanwork/mcp-server-tester/fixtures/mcp 导入 test 与 expect,不可从根路径导入;需要认证时改用 fixtures/mcpAuth 并在 mcpConfig 中配置 auth。异步断言需 await,快照测试需从第二个参数取 testInfo,更新快照用 npx playwright test --update-snapshots,运行测试用 npx playwright test。
适用场景:为 MCP 服务器工具编写回归测试、错误处理测试、结构校验与质量评估。
限制:依赖外部 LLM 的评测与具体配置细节、收费标准、平台支持等资料暂未提供,需以实际项目配置为准。