柏树mcp
Cypress的MCP服务器——让AI代理运行测试、管理规范、快照页面和自动化浏览器。
](https://www.npmjs.com/package/cypress-mcp)  
______________________________________________________________________
这是什么?
cypress-mcp 是一个 模型上下文协议 服务器,将Cypress作为一组AI可用工具公开。将其连接到Claude、Cursor、VS Code或任何MCP客户端,让您的AI助手:
- 运行Cypress测试 并获得结构化的通过/失败结果
- 读写规范文件 --从自然语言生成新测试
- 快照任何页面 通过ARIA可访问性树——无需截图
- 自动化浏览器 --导航、单击、键入、评估JavaScript
把它想象成赛普拉斯的等价物 @playwright/mcp.
______________________________________________________________________
运作原理
Your AI (Claude / Cursor / VS Code)
│
│ MCP protocol (stdio or HTTP/SSE)
▼
cypress-mcp server
│
├── Spec tools ──────────► Filesystem (list / read / write .cy.ts files)
├── Runner tools ─────────► Cypress CLI (run tests, open GUI, get results)
└── Browser tools ────────► Playwright-core (navigate, snapshot, screenshot)浏览器自动化使用一个单独的Playwright核心实例,而不是Cypress浏览器,将自动化和测试问题清晰地分开。
______________________________________________________________________
快速开始
1.安装浏览器(一次性)
npx playwright install chromium2.连接到您的MCP客户端
克劳德桌面版 (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"cypress": {
"command": "npx",
"args": ["cypress-mcp", "--project", "/path/to/your/app"]
}
}
}VS代码/光标 (HTTP/SSE模式):
npx cypress-mcp --port 8932 --project /path/to/your/app然后将您的MCP客户端指向 http://localhost:8932/sse.
3.开始问你的AI
> List the spec files in my project
> Navigate to http://localhost:3000/login and take a snapshot
> Write a Cypress test for the login form based on what you see
> Run the login spec and tell me what failed______________________________________________________________________
工具
规范文件工具
| 工具 | 说明 |
|---|---|
cypress_list_specs | 列出所有与Cypress图案匹配的规格文件 |
cypress_read_spec | 读取规范文件的内容 |
cypress_write_spec | 创建或覆盖规范文件 |
cypress_get_config | 阅读 cypress.config.ts/js |
测试流道工具
| 工具 | 说明 |
|---|---|
cypress_run | 运行测试--返回通过/失败计数和错误详细信息 |
cypress_open | 打开Cypress图形用户界面 |
cypress_get_last_run | 读取上次运行的结果 |
浏览器自动化工具
| 工具 | 说明 |
|---|---|
cypress_navigate | 导航到URL |
cypress_snapshot | 获取页面的ARIA可访问性树 |
cypress_screenshot | 截图(整页或元素) |
cypress_click | 按选择器或文本单击元素 |
cypress_type | 在输入字段中键入 |
cypress_evaluate | 运行JavaScript并返回结果 |
cypress_get_url | 获取当前URL |
cypress_wait_for | 等待元素或文本出现 |
cypress_close_browser | 关闭自动化浏览器 |
______________________________________________________________________
工作流程示例
以下是当你要求人工智能为你的应用程序编写测试时会发生的情况:
1.快照页面 — cypress_navigate + cypress_snapshot
Accessibility Snapshot:
- heading "My Todo List" [level=1]
- textbox "New todo"
- button "Add"
- list "Todo list"
- listitem: No todos yet. Add one above!2.AI编写规范 — cypress_write_spec
describe('Todo App', () => {
it('adds a new todo', () => {
cy.visit('http://localhost:4000');
cy.get('[aria-label="New todo"]').type('Buy groceries');
cy.get('button').contains('Add').click();
cy.get('#todo-list').should('contain', 'Buy groceries');
});
});3.运行测试 — cypress_run
✅ Cypress Run PASSED
Tests: 10
Passed: 10
Failed: 0
Duration: 3.21s______________________________________________________________________
CLI选项
cypress-mcp [options]
--project
Cypress project root (default: current directory)
--port Start HTTP/SSE server instead of stdio
--browser Browser for automation: chromium | firefox | webkit (default: chromium)
--headed Show the automation browser window
--help Show help
--version Show version______________________________________________________________________
本地运行
git clone https://github.com/yashpreetbathla/cypress-mcp.git
cd cypress-mcp
npm install
npx playwright install chromium
npm run build
npm test开发模式
npm run dev # TypeScript watch mode
npm test # Run unit tests (Vitest)
npm run test:watch # Watch mode______________________________________________________________________
需求
| 要求 | 版本 |
|---|---|
| Node.js | >=18 |
| Cypress(在您的项目中) | >=12 |
| Chromium(用于浏览器工具) | 通过 npx playwright install chromium |
柏树是一种 对等依赖 --在项目中安装它,而不是全局安装。MCP服务器自动从 node_modules/.bin/cypress.
______________________________________________________________________
建筑
cypress-mcp/
├── src/
│ ├── index.ts CLI entry point
│ ├── server.ts MCP server (stdio + HTTP/SSE transports)
│ ├── context.ts Playwright-core browser context singleton
│ ├── toolHandler.ts Central tool dispatcher
│ ├── tools/
│ │ ├── specs.ts Spec file management (filesystem)
│ │ ├── runner.ts Cypress test execution (CLI)
│ │ └── browser.ts Browser automation (Playwright-core)
│ ├── types.ts TypeScript interfaces
│ └── version.ts Version constant
└── tests/
└── unit/
├── specs.test.ts 13 tests for file tools
├── tools.test.ts 8 tests for tool definitions
└── toolHandler.test.ts 4 tests for dispatch logic为什么Playwright是浏览器自动化的核心?
Cypress是一个测试框架-它的浏览器不能作为实时自动化API访问。与其试图侵入Cypress浏览器, cypress-mcp 运行一个轻量级的独立Playwright核心实例,用于自动化任务(导航、快照、截图)。Cypress浏览器仅在通过以下方式运行实际测试时使用 cypress_run.
______________________________________________________________________
与@description/mcp的比较
| 特点 | cypress-mcp | @playwright/mcp |
|---|---|---|
| 浏览器自动化 | ✅ (通过剧作家核心) | ✅ (本地) |
| 辅助功能快照 | ✅ ARIA树 | ✅ ARIA树 |
| 运行现有测试 | ✅ 柏树测试 | ❌ |
| 写入测试文件 | ✅ .cy.ts / .cy.js | ❌ |
| 测试结果解析 | ✅ 结构化JSON | ❌ |
| 视觉/坐标工具 | ❌ (即将到来) | ✅ |
| 最适合 | 使用Cypress进行E2E的团队 | 通用浏览器自动化 |
______________________________________________________________________
贡献
欢迎发布问题和PR。请在开始重要工作之前打开一个问题。
npm test # must pass
npm run build # must compile cleanly______________________________________________________________________
许可证
MIT© 雅什普里特巴特拉
