浏览器自动化服务器

一个基于Playwright的模型上下文协议服务器,提供浏览器自动化能力,使LLM能够与网页交互、截图、生成测试代码、抓取网页内容并在真实浏览器环境中执行JavaScript。

  • by Shiva2717
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Shiva2717/playwright-MCP

使用说明

MseeP.ai Security Assessment Special thanks to Warp, the AI terminal for developers

剧作家MCP服务器🎭

使用Playwright提供浏览器自动化功能的模型上下文协议服务器。此服务器使LLM能够在真实的浏览器环境中与网页交互、截图、生成测试代码、对页面进行web裁剪和执行JavaScript。

截图

文档 | api参考

安装

您可以使用npm、mcp-get或Smithery安装该包:

使用npm:

npm install -g @executeautomation/playwright-mcp-server

使用mcp get:

npx @michaellatman/mcp-get@latest install @executeautomation/playwright-mcp-server

使用Smithery

通过以下方式自动安装Playwright MCP for Claude Desktop 史密瑟里:

npx @smithery/cli install @executeautomation/playwright-mcp-server --client claude

在VS代码中安装

使用以下按钮之一在VS Code中安装Playwright MCP服务器:

或者,您可以使用VS Code CLI安装Playwright MCP服务器:

# For VS Code
code --add-mcp '{"name":"playwright","command":"npx","args":["@executeautomation/playwright-mcp-server"]}'
# For VS Code Insiders
code-insiders --add-mcp '{"name":"playwright","command":"npx","args":["@executeautomation/playwright-mcp-server"]}'

安装后,ExecuteAutomation Playwright MCP服务器将可用于VS Code中的GitHub Copilot代理。

使用Playwright服务器的配置

以下是使用Playwright服务器的Claude Desktop配置:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}

Docker支持

Playwright MCP服务器可以在Docker中运行,用于隔离和容器化执行。

构建Docker镜像

在构建Docker镜像之前,您需要构建具有生产依赖关系的TypeScript项目:

# Install production dependencies and build
npm install --omit=dev
npm run build

# Build the Docker image
docker build -t mcp-playwright .

或者使用提供的便利脚本:

chmod +x docker-build.sh
./docker-build.sh

使用Docker运行

您可以通过多种方式使用Docker运行MCP服务器:

直接使用Docker

# Run the server (stdin/stdout communication)
docker run -i mcp-playwright

使用Docker Compose

A. docker-compose.yml 提供文件以便于管理:

# Run the server with docker-compose
docker compose run --rm playwright-mcp

在MCP客户端上使用Docker

要将Docker化服务器与Claude Desktop或其他MCP客户端一起使用,您可以将它们配置为使用Docker:

{
  "mcpServers": {
    "playwright": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "mcp-playwright"]
    }
  }
}

备注Docker镜像使用基于Debian的瘦Node.js镜像,仅包含核心依赖项。Playwright浏览器没有预先安装在容器中,以保持图像大小较小。如果需要,浏览器将在首次使用时下载。

测试

此项目使用Jest进行测试。测试位于 src/__tests__ 目录。

运行测试

您可以使用以下命令之一运行测试:

# Run tests using the custom script (with coverage)
node run-tests.cjs

# Run tests using npm scripts
npm test           # Run tests without coverage
npm run test:coverage  # Run tests with coverage
npm run test:custom    # Run tests with custom script (same as node run-tests.cjs)

测试覆盖率报告将在 coverage 目录。

运行评估

evals包加载一个mcp客户端,然后运行index.ts文件,因此不需要在测试之间重建。您可以通过在npx命令前加前缀来加载环境变量。可以找到完整的文档 这里.

OPENAI_API_KEY=your-key  npx mcp-eval src/evals/evals.ts src/tools/codegen/index.ts

贡献

添加新工具时,请注意工具名称的长度。一些客户端(如Cursor)对服务器和工具的组合名称有60个字符的限制(server_name:tool_name).

我们的服务器名称是 playwright-mcp。请确保您的工具名称足够短,不会超过此限制。

星迹