playwright-ai-integration
Submit natural language prompts to an AI chatbot, which will use a browser through an MCP (Model Context Protocol) server to perform actions and generate Playwright tests automatically.
claude mcp add --transport stdio chrisminnick-playwright-ai-integration node src/server.js
How to use
This MCP server enables natural language prompts to drive a Playwright-enabled browser session via an AI agent. Users can describe tests or interactions in plain language, and the system will translate those prompts into browser actions such as launching a browser, navigating to pages, clicking elements, filling forms, taking screenshots, and generating Playwright test code. Real-time feedback is streamed back over WebSocket, so you can watch actions as they happen and view the generated test code for reuse in your projects.
Key capabilities include launching and controlling a browser, navigating to URLs, interacting with page elements through CSS selectors, waiting for elements to appear, capturing screenshots, retrieving page content, and generating Playwright test scripts. The MCP tools exposed by this server include launch_browser, navigate_to, click_element, fill_input, wait_for_element, take_screenshot, get_page_content, generate_test, and close_browser. You can start a session, submit prompts like “Go to google.com and search for Playwright testing” or “Open example.com and take a screenshot,” and monitor live updates as the AI executes tasks and builds the corresponding tests.
How to install
Prerequisites:
- Node.js v18 or higher
- An OpenAI API key
- A modern web browser
Installation steps:
-
Clone the repository or download the project files.
-
Navigate to the project directory:
cd playwright-ai-integration
-
Install dependencies:
npm install
-
Install Playwright browsers (required for browser automation):
npm run install-browsers
-
Set up environment variables:
cp .env.example .env
Edit .env and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here
-
Start the server:
npm start
-
Open the web interface in your browser at:
Additional notes
Tips and troubleshooting:
- Ensure your OPENAI_API_KEY is valid and has access to the required model (gpt-4o-mini is commonly recommended).
- If you encounter browser launch issues, run npm run install-browsers to verify Playwright binaries are installed.
- If you see MCP connection errors, verify that the Node server is running and that the port (default 3000) is not in use by another process.
- The OPENAI_MODEL setting can be adjusted in .env to balance performance and cost (options include gpt-4o-mini, gpt-4o, gpt-4-turbo, gpt-3.5-turbo).
- For debugging, export DEBUG=* before starting the server to get verbose logs.
- The MCP server can generate Playwright test code via the generate_test tool; copy this code into your project to reuse or customize tests.
Related MCP Servers
sdk-typescript
A model-driven approach to building AI agents in just a few lines of code.
mongodb-lens
🍃🔎 MongoDB Lens: Full Featured MCP Server for MongoDB Databases
sample-agentic-ai-web
This project demonstrates how to use AWS Bedrock with Anthropic Claude and Amazon Nova models to create a web automation assistant with tool use, human-in-the-loop interaction, and vision capabilities.
short-url
简单易用的短链接生成工具,完全开源、免费、无需登录,可私有化部署,链接永久有效!
pega-dx
Pega DX MCP Server - Enabling conversational interaction with Pega Infinity™ applications. This MCP Server transforms Pega Infinity™ interactions into intuitive, conversational experiences through the Model Context Protocol.
llms-txt-generator
The ultimate AI-powered generator for llms.txt and llms-full.txt files.