cypress-mcp-server

cypress-mcp-server

A Model Context Protocol (MCP) server that integrates Cypress with Cursor AI, enabling AI-powered test automation, debugging, and script generation for Cypress tests.

Category
访问服务器

README

Cypress MCP Server

A Model Context Protocol (MCP) server implementation that integrates Cypress with Cursor AI, enabling AI-powered test automation, debugging, and script generation.

🚀 Features

  • Full Cypress Integration: Supports all major Cypress commands and features
  • MCP Standard Compliant: Follows the official Model Context Protocol specification
  • Cursor AI Compatible: Seamlessly integrates with Cursor's AI assistant
  • Comprehensive Tool Set:
    • Run tests in headless or headed mode
    • Validate test files and code
    • Generate tests from descriptions
    • Retrieve test results, screenshots, and videos
    • Execute Cypress commands programmatically
  • Security: Configurable command allowlist and execution time limits
  • Logging: Comprehensive logging with Winston
  • Flexible Configuration: YAML-based configuration with environment variable support

📋 Prerequisites

  • Node.js 18.0.0 or higher
  • npm or yarn package manager
  • Cypress project (existing or new)

🔧 Installation

Option 1: Install from npm (when published)

npm install -g cypress-mcp-server

Option 2: Install from source

git clone https://github.com/yourusername/cypress-mcp-server.git
cd cypress-mcp-server
npm install
npm link  # Optional: link globally for CLI access

⚙️ Configuration

1. Create Configuration File

Copy the example configuration file:

cp cypress-mcp.config.yaml.example cypress-mcp.config.yaml

2. Configure Cursor

Add the MCP server to Cursor's configuration. Open Cursor settings and add:

On macOS/Linux: ~/.cursor/mcp.json

On Windows: %APPDATA%\Cursor\mcp.json

{
  "mcpServers": {
    "cypress": {
      "command": "node",
      "args": ["/path/to/cypress-mcp-server/src/index.js"],
      "env": {
        "CYPRESS_MCP_CONFIG": "/path/to/cypress-mcp.config.yaml"
      }
    }
  }
}

Or if installed globally:

{
  "mcpServers": {
    "cypress": {
      "command": "cypress-mcp-server"
    }
  }
}

3. Customize Configuration

Edit cypress-mcp.config.yaml:

cypress:
  projectPath: /path/to/your/cypress/project
  browser: chrome
  headless: true
  baseUrl: http://localhost:3000
  viewportWidth: 1280
  viewportHeight: 720
  defaultCommandTimeout: 4000
  requestTimeout: 5000
  responseTimeout: 30000

mcp:
  name: cypress-mcp-server
  version: 1.0.0

security:
  allowedCommands:
    - '*'
  maxExecutionTime: 300000

🎯 Usage

Once configured, you can use natural language prompts in Cursor to interact with Cypress:

Running Tests

Run all Cypress tests in headless mode
Run the test file cypress/e2e/login.cy.js using Firefox
Run Cypress tests with baseUrl set to http://localhost:8080

Generating Tests

Generate a Cypress test that validates user login. The test should visit the login page, enter credentials, click login, and verify redirect to dashboard. Save it to cypress/e2e/login.cy.js

Validating Tests

Validate the Cypress test file cypress/e2e/checkout.cy.js for syntax errors

Getting Results

Show me the results from the last Cypress test run
Get all screenshots from failed tests

📚 Available Tools

The MCP server exposes the following tools:

cypress_run

Run Cypress tests with specified options.

Parameters:

  • spec (string, optional): Specific test file or glob pattern
  • browser (string, optional): Browser to use (chrome, firefox, edge, electron)
  • headless (boolean, optional): Run in headless mode
  • baseUrl (string, optional): Base URL for the application
  • env (object, optional): Environment variables
  • config (object, optional): Additional Cypress configuration

cypress_open

Open Cypress Test Runner in headed mode for interactive debugging.

Parameters:

  • browser (string, optional): Browser to open
  • project (string, optional): Path to Cypress project

cypress_validate

Validate a Cypress test file or test code.

Parameters:

  • testFile (string, optional): Path to test file
  • testCode (string, optional): Test code to validate

cypress_generate

Generate a Cypress test file from a description.

Parameters:

  • description (string, required): Description of the test
  • testName (string, optional): Name for the test
  • outputPath (string, optional): Path to save the generated test

cypress_get_results

Get test results from previous runs.

Parameters:

  • runId (string, optional): Specific run ID, or omit for all results

cypress_get_screenshots

Get screenshots captured during test runs.

Parameters:

  • runId (string, optional): Filter by run ID
  • testPath (string, optional): Filter by test path

cypress_get_videos

Get videos recorded during test runs.

Parameters:

  • runId (string, optional): Filter by run ID

cypress_execute_command

Execute a Cypress command directly (placeholder for advanced use cases).

📖 Examples

See the examples/ directory for:

  • Example Cypress test files
  • Sample Cursor prompts
  • Configuration examples

🧪 Testing

Run the test suite:

npm test

Run tests with coverage:

npm run test:coverage

🔒 Security

The MCP server includes several security features:

  1. Command Allowlist: Configure which Cypress commands are allowed
  2. Execution Time Limits: Prevent long-running tests from blocking
  3. Input Validation: All inputs are validated before execution
  4. Error Handling: Comprehensive error handling prevents crashes

📝 Logging

Logs are written to:

  • Console (development mode)
  • logs/error.log (errors only)
  • logs/combined.log (all logs)

Set the log level with the LOG_LEVEL environment variable:

LOG_LEVEL=debug node src/index.js

🐛 Troubleshooting

Server won't start

  1. Check Node.js version: node --version (should be 18+)
  2. Verify dependencies: npm install
  3. Check configuration file syntax
  4. Review logs in logs/ directory

Tests not running

  1. Verify Cypress is installed: npx cypress verify
  2. Check project path in configuration
  3. Ensure baseUrl is accessible
  4. Check browser permissions

Cursor not connecting

  1. Verify MCP configuration in Cursor settings
  2. Check file paths are absolute
  3. Restart Cursor after configuration changes
  4. Check console for connection errors

Browser issues

  1. Ensure Chrome/Firefox is installed
  2. Check browser permissions
  3. Try running Cypress manually: npx cypress open
  4. Review Cypress documentation for browser setup

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details

🔗 Links

🙏 Acknowledgments

  • Anthropic for the Model Context Protocol specification
  • The Cypress team for an amazing testing framework
  • Cursor for AI-powered development tools

📧 Support

For issues, questions, or contributions:

  • Open an issue on GitHub
  • Check existing documentation
  • Review example files

Note: This is a community project and is not officially affiliated with Cypress, Cursor, or Anthropic.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选