An MCP (Model Context Protocol) server that exposes Playwright automation capabilities through a standardized protocol interface. This allows AI applications to control web browsers and interact with web pages programmatically.
This MCP server integrates the popular Playwright automation library with the Model Context Protocol, enabling seamless browser automation through AI assistants and other MCP clients.
- Chromium - Full Chromium support
- Firefox - Mozilla Firefox support
- WebKit - Safari/WebKit support
The server exposes the following tools:
- launch_browser - Launch a new browser instance with optional URL navigation
- close_browser - Close an existing browser instance and clean up resources
- navigate - Navigate to a specific URL with configurable wait conditions
- get_url - Retrieve the current URL of the active page
- wait_for_navigation - Wait for a page navigation to complete
- click_element - Click an element using CSS selector
- fill_input - Fill input fields with text
- get_text - Get text content from an element
- get_title - Get the current page title
- screenshot - Take a screenshot of the current page
- Node.js 17 or higher
- npm or yarn package manager
The easiest way to get started is to install from NPM:
npm install playwright-mcp-rashaideh93Then start the server:
npx playwright-mcp-rashaideh93Alternatively, you can clone and build from source:
-
Clone or download the project:
git clone https://github.com/rashaideh93/playwright-mcp-server.git cd playwright-mcp-server -
Install dependencies:
npm install
-
Build the TypeScript code:
npm run build
For Users:
npm install playwright-mcp-rashaideh93
npx playwright-mcp-rashaideh93For Developers:
git clone https://github.com/rashaideh93/playwright-mcp-server.git
cd playwright-mcp-server
npm install
npm test # Run validation tests
npm run build # Compile TypeScript
npm start # Start the servernpm startOr in development mode with auto-rebuild:
npm run dev- Open VS Code and press
Cmd+Shift+P(Mac) orCtrl+Shift+P(Windows/Linux) - Select MCP: Add server...
- Choose Stdio and enter the command:
node ./build/index.js - Give it a name like "Playwright MCP"
Add to your claude_desktop_config.json:
{
"mcpServers": {
"playwright-mcp": {
"command": "node",
"args": ["/absolute/path/to/playwright-mcp-server/build/index.js"]
}
}
}Configure your MCP client to connect to this server using stdio transport on the node build/index.js command.
1. launch_browser with browserType: "chromium", headless: true, url: "https://example.com"
→ Returns: browser-1
2. screenshot with browserId: "browser-1", filename: "example.png"
→ Screenshot saved
3. close_browser with browserId: "browser-1"
→ Browser closed
1. launch_browser with browserType: "chromium"
→ Returns: browser-1
2. navigate with browserId: "browser-1", url: "https://example.com/form"
3. fill_input with browserId: "browser-1", selector: "input[name='username']", text: "myuser"
4. fill_input with browserId: "browser-1", selector: "input[name='password']", text: "mypass"
5. click_element with browserId: "browser-1", selector: "button[type='submit']"
6. close_browser with browserId: "browser-1"
1. launch_browser with browserType: "chromium", url: "https://news.example.com"
→ Returns: browser-1
2. get_title with browserId: "browser-1"
→ Returns page title
3. get_text with browserId: "browser-1", selector: ".article-title"
→ Returns article title text
4. close_browser with browserId: "browser-1"
- Each browser instance is assigned a unique ID (e.g.,
browser-1,browser-2) - Browser instances include:
- The browser process
- A default browser context
- A default page
- Instances are stored in memory and cleaned up when closed
All tools use Zod for schema validation, ensuring type-safe inputs and clear error messages.
The server gracefully handles errors and returns meaningful error messages:
- Invalid browser IDs
- Navigation timeouts
- Element not found errors
- Playwright runtime errors
The server includes Jest for developers to write unit tests:
npm test # Run all tests
npm run test:watch # Watch mode (auto-rerun on changes)
npm run test:coverage # Generate coverage reportFor Developers: See DEVELOPER_TESTING_GUIDE.md for:
- How to write unit tests for your code
- Example test files
- Testing best practices
- Jest configuration and commands
- Running specific tests
playwright-mcp-server/
├── src/
│ └── index.ts # Main server implementation
├── build/ # Compiled JavaScript (generated)
├── .vscode/
│ └── mcp.json # MCP server configuration
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # This file
npm run buildThis compiles TypeScript to JavaScript and makes the script executable.
The server can be tested using the MCP Inspector:
npx @modelcontextprotocol/inspector node ./build/index.jsThis opens a web interface where you can:
- Test individual tools
- Inspect tool schemas
- View tool outputs
- Debug server behavior
Once connected, Copilot can:
- Control browsers through natural language
- Perform automated testing
- Extract data from web pages
- Fill forms and interact with web applications
When configured in Claude Desktop:
- Use natural language to script browser interactions
- Automate web scraping tasks
- Generate test scripts
- Create end-to-end automation workflows
Any MCP-compatible client can use these browser automation tools:
- LM Studio
- Cursor
- Windsurf
- Cline
- And others in the MCP ecosystem
The launch_browser tool accepts:
browserType- "chromium", "firefox", or "webkit"headless- Run in headless mode (default: true)url- Optional URL to navigate to immediately
The navigate tool supports:
"load"- Wait for the load event (default)"domcontentloaded"- Wait for DOM content loaded"networkidle"- Wait for network to be idle
- Ensure Node.js 17+ is installed
- Check that all dependencies are installed:
npm install - Verify the build succeeded:
npm run build
- Verify the absolute path in mcp.json is correct
- Check that the build folder exists and contains
index.js - Look for stderr output for connection errors
- Ensure the browser ID is valid
- Verify CSS selectors are correct
- Check that elements exist before interaction
- Review Playwright documentation for specific element interactions
- Headless mode is faster than headed mode
- Close browsers when done to free resources
- Use appropriate wait conditions for navigation
- Consider browser context cleanup for long-running sessions
Description: Launch a new browser instance
Parameters:
browserType(enum: "chromium" | "firefox" | "webkit") - Browser to launchheadless(boolean, optional, default: true) - Headless modeurl(string, optional) - URL to navigate to
Returns: Browser ID string
Description: Navigate to a URL
Parameters:
browserId(string) - Browser instance IDurl(string) - URL to navigate towaitUntil(enum: "load" | "domcontentloaded" | "networkidle", optional, default: "load")
Returns: Navigation result
Description: Click an element
Parameters:
browserId(string) - Browser instance IDselector(string) - CSS selector
Returns: Click result
Description: Fill an input field
Parameters:
browserId(string) - Browser instance IDselector(string) - CSS selector of inputtext(string) - Text to fill
Returns: Fill result
Description: Get text content
Parameters:
browserId(string) - Browser instance IDselector(string) - CSS selector
Returns: Text content
Description: Get page title
Parameters:
browserId(string) - Browser instance ID
Returns: Page title
Description: Get current URL
Parameters:
browserId(string) - Browser instance ID
Returns: Current URL
Description: Take a screenshot
Parameters:
browserId(string) - Browser instance IDfilename(string, optional) - Output filename
Returns: Screenshot path
Description: Wait for navigation
Parameters:
browserId(string) - Browser instance IDtimeout(number, optional, default: 30000) - Timeout in ms
Returns: Navigation completion result
Description: Close a browser
Parameters:
browserId(string) - Browser instance ID
Returns: Close result
- @modelcontextprotocol/sdk - MCP protocol implementation
- playwright - Browser automation library
- zod - Runtime type validation
MIT
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
For issues, questions, or suggestions:
- Check the Playwright documentation for browser-specific issues
- Review MCP documentation for protocol-related questions
- Consult the troubleshooting section above
- Open an issue on the GitHub repository