mcp-playwright
Enables browser automation for AI assistants via Playwright, supporting multiple browsers, sessions, and tools for web interaction and testing.
README
MCP Playwright
A Model Context Protocol (MCP) server that provides Playwright browser automation capabilities. This package allows AI assistants and other MCP clients to control web browsers, interact with web pages, and perform automated testing tasks.
Features
- 🌐 Support for multiple browsers (Chromium, Firefox, WebKit)
- 🔄 Multiple browser session management
- 📸 Screenshot capture
- 🖱️ Element interaction (click, fill, etc.)
- ⏱️ Wait for elements and conditions
- 📜 JavaScript execution
- 📄 Page content extraction
- 🎯 CSS selector and text-based element targeting
Installation
npm install -g mcp-playwright
Or for local development:
npm install mcp-playwright
Usage
As a Standalone Server
mcp-playwright serve
With MCP Client Configuration
Add to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"playwright": {
"command": "mcp-playwright",
"args": ["serve"]
}
}
}
Programmatic Usage
import PlaywrightMCPServer from 'mcp-playwright';
const server = new PlaywrightMCPServer();
await server.run();
Available Tools
launch_browser
Launch a new browser instance.
Parameters:
browserType(optional): "chromium", "firefox", or "webkit" (default: "chromium")headless(optional): Run in headless mode (default: true)sessionId(optional): Unique session identifier (default: "default")
navigate_to
Navigate to a specific URL.
Parameters:
url(required): URL to navigate tosessionId(optional): Browser session ID (default: "default")
click_element
Click on an element using CSS selector or text.
Parameters:
selector(required): CSS selector or text content to clicksessionId(optional): Browser session ID (default: "default")
fill_input
Fill an input field with text.
Parameters:
selector(required): CSS selector for the input fieldtext(required): Text to fill in the inputsessionId(optional): Browser session ID (default: "default")
get_text
Get text content from an element.
Parameters:
selector(required): CSS selector for the elementsessionId(optional): Browser session ID (default: "default")
take_screenshot
Take a screenshot of the current page.
Parameters:
path(optional): Path to save the screenshot (default: "screenshot.png")fullPage(optional): Capture full page (default: false)sessionId(optional): Browser session ID (default: "default")
wait_for_element
Wait for an element to appear on the page.
Parameters:
selector(required): CSS selector to wait fortimeout(optional): Timeout in milliseconds (default: 30000)sessionId(optional): Browser session ID (default: "default")
execute_script
Execute JavaScript code in the browser context.
Parameters:
script(required): JavaScript code to executesessionId(optional): Browser session ID (default: "default")
get_page_source
Get the HTML source of the current page.
Parameters:
sessionId(optional): Browser session ID (default: "default")
close_browser
Close a browser session.
Parameters:
sessionId(optional): Browser session ID to close (default: "default")
Examples
Basic Web Automation
- Launch a browser:
{
"tool": "launch_browser",
"arguments": {
"browserType": "chromium",
"headless": false,
"sessionId": "my-session"
}
}
- Navigate to a website:
{
"tool": "navigate_to",
"arguments": {
"url": "https://example.com",
"sessionId": "my-session"
}
}
- Interact with elements:
{
"tool": "click_element",
"arguments": {
"selector": "button[type='submit']",
"sessionId": "my-session"
}
}
Web Scraping
- Extract text content:
{
"tool": "get_text",
"arguments": {
"selector": "h1.title",
"sessionId": "my-session"
}
}
- Take screenshots:
{
"tool": "take_screenshot",
"arguments": {
"path": "./screenshots/page.png",
"fullPage": true,
"sessionId": "my-session"
}
}
Advanced Automation
- Execute custom JavaScript:
{
"tool": "execute_script",
"arguments": {
"script": "return document.querySelectorAll('a').length;",
"sessionId": "my-session"
}
}
- Wait for dynamic content:
{
"tool": "wait_for_element",
"arguments": {
"selector": ".dynamic-content",
"timeout": 10000,
"sessionId": "my-session"
}
}
Multiple Browser Sessions
You can manage multiple browser sessions simultaneously by using different sessionId values:
// Launch first browser
{
"tool": "launch_browser",
"arguments": {
"sessionId": "browser-1",
"browserType": "chromium"
}
}
// Launch second browser
{
"tool": "launch_browser",
"arguments": {
"sessionId": "browser-2",
"browserType": "firefox"
}
}
Requirements
- Node.js 18+
- The package automatically installs Playwright browsers on first use
Development
- Clone the repository:
git clone https://github.com/devcodingskill/mcp-playwright.git
cd mcp-playwright
- Install dependencies:
npm install
- Build the project:
npm run build
- Run in development mode:
npm run dev
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
Troubleshooting
Browser Installation Issues
If you encounter browser installation issues, try:
npx playwright install
Permission Issues
On Linux/macOS, you might need to install additional dependencies:
npx playwright install-deps
Memory Issues
For large-scale automation, consider:
- Using headless mode
- Closing browser sessions when done
- Managing multiple sessions carefully
Security Considerations
- This tool provides powerful browser automation capabilities
- Be cautious when executing untrusted JavaScript code
- Consider running in isolated environments for production use
- Review and sanitize any user-provided selectors or scripts
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。