Playwright MCP Server 是一个基于 Model Context Protocol 的服务器,借助 Playwright 提供浏览器自动化功能。该服务器能让大语言模型(LLMs)与网页进行交互,实现截图、生成测试代码、网页数据抓取以及在真实浏览器环境中执行 JavaScript 等操作。
特别感谢 Warp,开发者的 AI 终端,它支持 MacOS、Linux 和 Windows 系统。
以下将详细介绍 Playwright MCP Server 的安装、配置、测试等内容。
你可以使用 npm、mcp-get 或 Smithery 来安装该软件包:
npm install -g @executeautomation/playwright-mcp-server
npx @michaellatman/mcp-get@latest install @executeautomation/playwright-mcp-server
若要通过 Smithery 自动为 Claude Desktop 安装 Playwright MCP,可使用以下命令:
npx @smithery/cli install @executeautomation/playwright-mcp-server --client claude
你可以通过以下方式在 VS Code 中安装 Playwright MCP 服务器:
# 对于 VS Code
code --add-mcp '{"name":"playwright","command":"npx","args":["@executeautomation/playwright-mcp-server"]}'
# 对于 VS Code Insiders
code-insiders --add-mcp '{"name":"playwright","command":"npx","args":["@executeautomation/playwright-mcp-server"]}'
安装完成后,ExecuteAutomation Playwright MCP 服务器即可在 VS Code 中与 GitHub Copilot 代理配合使用。
以下是在 Claude Desktop 中使用 Playwright 服务器的配置示例:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["-y", "@executeautomation/playwright-mcp-server"]
}
}
}
本项目使用 Jest 进行测试,测试文件位于 src/__tests__ 目录下。
你可以使用以下命令运行测试:
# 使用自定义脚本运行测试(包含覆盖率)
node run-tests.cjs
# 使用 npm 脚本运行测试
npm test # 不包含覆盖率运行测试
npm run test:coverage # 包含覆盖率运行测试
npm run test:custom # 使用自定义脚本运行测试(与 node run-tests.cjs 相同)
测试覆盖率报告将生成在 coverage 目录中。
评估包会加载一个 mcp 客户端,然后运行 index.ts 文件,因此测试之间无需重新构建。你可以通过在 npx 命令前添加环境变量来加载环境变量。完整文档可参考 此处。
OPENAI_API_KEY=your-key npx mcp-eval src/evals/evals.ts src/tools/codegen/index.ts