Playwright MCP Server:為大型語言模型提供瀏覽器自動化能力
Playwright MCP Server是什么?
Playwright MCP Server是一個使用Playwright實現的模型上下文協議服務器,能夠為大型語言模型(LLMs)提供瀏覽器自動化能力,例如與網頁交互、截屏以及在真實瀏覽器環境中執行JavaScript。
Playwright MCP Server功能特征
瀏覽器自動化
自動導航到指定網頁。
與網頁元素交互,例如點擊、懸停、填寫表單等。
執行 JavaScript 腳本。
獲取瀏覽器控制臺日志,便于調試。
截圖功能
可以對整個頁面或特定元素進行截圖。
API 測試
支持通過簡單的英文指令測試 API,包括 GET、POST、PUT、PATCH 和 delete 請求。
驗證 API 響應中的特定屬性。
上下文共享
通過 MCP 協議,為 LLM 提供網頁上下文信息,增強模型的理解能力。
工具暴露
暴露瀏覽器操作工具,使 LLM 可以調用這些工具完成復雜任務。
Playwright MCP Server特點
與 LLM 深度集成
允許 LLM 在真實瀏覽器環境中操作網頁。
支持多種主流瀏覽器(如 Chromium、Firefox、WebKit)。
簡單易用
可通過 npm、mcp-get 或 Smithery 快速安裝。
配置簡單,適用于多種開發環境。
高效自動化
支持并發運行多個腳本,提升自動化效率。
無需編寫復雜腳本,通過自然語言描述即可完成任務。
安全性
通過本地服務器運行,避免敏感數據上傳至第三方平臺。
Playwright MCP Server使用場景
自動化測試:自動化測試 Web 應用的功能。
數據抓取:從網頁中抓取數據進行分析。
文檔生成:生成網頁截圖用于文檔或報告。
動態內容操作:在瀏覽器環境中執行復雜腳本,動態操作網頁。
Playwright MCP Server安裝使用
安裝方法
你可以通過以下三種方式安裝 Playwright MCP Server:
使用 npm:
npm install -g @executeautomation/playwright-mcp-server
使用 Smithery:
npx @smithery/cli install @executeautomation/playwright-mcp-server --client claude
使用 mcp-get:
npx @michaellatman/mcp-get@latest install @executeautomation/playwright-mcp-server
配置方法
安裝完成后,需要在 Claude Desktop 的配置文件中進行以下配置:
找到 claude-desktop-config.json 文件,通常位于以下路徑:
Windows:%APPDATA%\Claude\claude_desktop_config.json
macOS:~/Library/Application Support/Claude/claude_desktop_config.json
修改配置文件,添加 Playwright MCP Server 的配置:
{ "mcpServers": { "playwright": { "command": "npx", "args": ["-y", "@executeautomation/playwright-mcp-server"] } } }
使用方法
配置完成后,啟動 Claude Desktop 客戶端,你將看到 Playwright MCP Server 出現在 Attach MCP server 列表中。
項目主頁:https://executeautomation.github.io/mcp-playwright
GitHub倉庫:https://github.com/executeautomation/mcp-playwright