Playwright MCP Server

1.0.0 · active · verified Sun Apr 19

The Playwright MCP Server provides an integration with Cursor IDE to enable AI-powered generation of Playwright tests. Operating as a custom Model Context Protocol (MCP) server, it analyzes a project's site context, existing test patterns, and authentication configurations to generate new tests based on user prompts. The server is currently at version 1.0.0, suggesting its initial stable release. Its release cadence is not explicitly stated but is likely tied to its primary use case with the Cursor IDE. Key differentiators include its deep integration with Cursor's chat interface, intelligent code reuse from existing tests, and sophisticated project structure analysis to ensure generated tests adhere to established conventions, making it a specialized tool for accelerating Playwright test development within the Cursor ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the essential steps to set up the OpenAI API key, install dependencies, start the Playwright MCP server, and configure the Cursor IDE to interact with it for AI-powered test generation.

/* quickstart.ts: Setup and Configuration for Playwright MCP Server */

// 1. Ensure your OpenAI API Key is set as an environment variable.
// This is crucial for the server to generate tests using AI models.
// Example (run in your shell or .env file):
// export OPENAI_API_KEY="sk-your-actual-api-key"

// For demonstration purposes in a script, you might access it like:
const openaiApiKey = process.env.OPENAI_API_KEY ?? '';

if (!openaiApiKey) {
  console.warn("WARNING: OPENAI_API_KEY environment variable is not set. The MCP server will fail to generate tests.\nPlease set it before starting the server.");
}

console.log("\n2. Install dependencies for the Playwright MCP Server:");
console.log("   $ npm install");

console.log("\n3. Start the Playwright MCP Server (typically in a separate terminal):");
console.log("   $ npm start");
console.log("   (or using npx if globally available: $ npx playwright-mcp-server)");

console.log("\n4. Configure Cursor IDE to use this MCP server. Create or update your project's `.cursor/settings.json` file:");
console.log(JSON.stringify({
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": [
        "playwright-mcp-server"
      ]
    }
  }
}, null, 2));

console.log("\nOnce the server is running and Cursor is configured, you can interact with it via Cursor's chat interface, e.g.:");
console.log("   /mcp playwright Create a test on the login page that validates user authentication.");

// Note: This TypeScript quickstart primarily outlines the setup and command execution,
// as the package is a server rather than a library for direct programmatic import.

view raw JSON →