Cypress Test Generator MCP server

Automates Cypress test generation by analyzing web pages with Puppeteer to extract DOM elements and generate structured page object models with appropriate selectors and test patterns for end-to-end test automation.
Back to servers
Setup instructions
Provider
Juan P. Realini
Release date
Aug 20, 2025
Language
JavaScript
Stats
14 stars

The MCP Cypress Page Object & Test Generator is a powerful tool that automatically creates TypeScript Page Object classes and Cypress test suites for web pages. It uses web scraping and HTML parsing to analyze page elements and generate comprehensive, ready-to-use test code.

Installation

To install the MCP Cypress Page Object & Test Generator, run:

npm install

Starting the Server

Launch the server with the following command:

npx tsx main.ts

Using the Generator

Making a Request with an MCP Client

The server provides a generateLocator tool that accepts a URL parameter. Here's how to call it:

{
  "method": "tools/call",
  "params": {
    "name": "generateLocator",
    "arguments": {
      "url": "https://example.com/login"
    }
  }
}

Understanding the Response

The response contains two generated files:

  1. A Page Object Class ({ClassName}.ts)
  2. A Test Suite ({ClassName}.cy.ts)

Example Page Object Class

export class ExampleComLoginPage {
  // Private elements
  #elements = {
    button_login: () => cy.get('#login-button'),
    input_username: () => cy.get('input[name="username"]'),
    link_home: () => cy.contains('a', 'Home')
  }

  // Public getters
  get ButtonLogin() { return this.#elements.button_login() }
  get InputUsername() { return this.#elements.input_username() }
  get LinkHome() { return this.#elements.link_home() }

  // Interaction methods
  clickButtonLogin() { return this.#elements.button_login().click() }
  typeInputUsername(text: string) { return this.#elements.input_username().type(text) }
  clickLinkHome() { return this.#elements.link_home().click() }

  // Workflow methods
  login(username: string, password: string) {
    this.typeInputUsername(username)
    this.typeInputPassword(password)
    this.clickButtonLogin()
    return this
  }
}

Example Test Suite

import { ExampleComLoginPage } from './ExampleComLoginPage'

describe('ExampleComLoginPage Tests', () => {
  let page: ExampleComLoginPage
  
  beforeEach(() => {
    cy.visit('https://example.com/login')
    page = new ExampleComLoginPage()
  })
  
  describe('Element Interactions', () => {
    it('should click button_login', () => {
      page.clickButtonLogin()
    })
    
    it('should type in input_username', () => {
      page.typeInputUsername('test input')
      page.getInputUsername().should('have.value', 'test input')
    })
  })
  
  describe('Login Workflow', () => {
    it('should login with valid credentials', () => {
      page.login('[email protected]', 'validpassword')
      cy.url().should('not.include', '/login')
    })
    
    it('should show error with invalid credentials', () => {
      page.login('[email protected]', 'wrongpassword')
      cy.contains('Invalid credentials').should('be.visible')
    })
  })
  
  describe('Error Handling', () => {
    it('should handle network errors gracefully', () => {
      cy.intercept('GET', '**', { forceNetworkError: true })
      cy.visit('https://example.com/login')
    })
  })
})

Using the Generated Code

To use the generated Page Object in your own tests:

// Import the generated Page Object
import { ExampleComLoginPage } from './ExampleComLoginPage'

describe('Login Page', () => {
  const page = new ExampleComLoginPage()
  
  it('should login successfully', () => {
    page.login('username', 'password')
    page.verifyPageLoaded()
  })
})

To run the generated test suite:

npx cypress run --spec "cypress/e2e/ExampleComLoginPage.cy.ts"

Features and Capabilities

Generated Test Categories

The generator creates multiple types of tests:

  • Positive Test Cases: Element interactions, workflows, form validation
  • Negative Test Cases: Error handling, validation errors, edge cases
  • Additional Test Types: Performance, responsive, accessibility, security

Supported Element Types

The generator handles various HTML elements:

  • Buttons
  • Input fields
  • Links
  • Select dropdowns
  • Textareas
  • Forms

Workflow Detection

The tool intelligently identifies common patterns:

  • Login forms
  • Search forms
  • Navigation elements
  • Form submissions

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "cypress-test-generator" '{"command":"npx","args":["tsx","main.ts"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cypress-test-generator": {
            "command": "npx",
            "args": [
                "tsx",
                "main.ts"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "cypress-test-generator": {
            "command": "npx",
            "args": [
                "tsx",
                "main.ts"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later