浏览器自动化服务器

一个基于Playwright的MCP服务器,为AI代理提供完整的浏览器自动化功能,包括导航、数据提取、交互和视觉工具。

  • by jatingodnani
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 jatingodnani/mcp-server

使用说明

Web自动化MCP服务器

一种模型上下文协议(MCP)服务器,使用Playwright为AI代理提供浏览器自动化功能。

特性

  • 15个自动化工具 用于完全控制浏览器
  • 无头浏览器 效率操作
  • 屏幕截图 具有元素定位功能
  • 表单自动化 具有输入填充和选择功能
  • DOM提取 用于文本、HTML和链接
  • 自定义JavaScript执行 用于高级场景

安装

# Install dependencies
npm install

# Install Playwright browser
npx playwright install chromium

# Build the project
npm run build

用法

启动服务器

npm start

使用Claude代码进行配置

添加到MCP设置(~/.claude/settings.json 或项目 .claude/settings.json):

{
  "mcpServers": {
    "web-automation": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-server/dist/index.js"]
    }
  }
}

可用工具

导航

工具 说明 参数
navigate 转到URL url (必填)
go_back 返回历史记录 无
go_forward 在历史中向前导航 无

数据提取

工具 说明 参数
extract_text 从页面/元素获取文本 selector (可选)
get_html 获取HTML内容 selector (可选), outer (布尔值)
get_links 提取所有链接 selector (可选)
get_page_info 获取URL、标题、描述 无

交互

工具 说明 参数
click 单击元素 selector (必填)
type 在输入中键入文本 selector (必填), text (必填)
select_option 选择下拉选项 selector (必填), value (必填)
hover 将鼠标悬停在元素上 selector (必填)

视觉的

工具 说明 参数
screenshot 捕获页面/元素 selector (可选), fullPage (布尔值)

公用事业

工具 说明 参数
wait_for 等待元素 selector (必填), timeout (毫秒)
scroll 滚动页面 direction 或 selector
evaluate 运行自定义JavaScript script (必填)

示例用法

基本导航和屏幕截图

User: "Go to https://news.ycombinator.com and take a screenshot"

AI will call:
1. navigate({ url: "https://news.ycombinator.com" })
2. screenshot({ fullPage: true })

提取数据

User: "Get all the links from the page"

AI will call:
1. get_links()

表单自动化

User: "Search for 'AI news' on the page"

AI will call:
1. type({ selector: "input[type='search']", text: "AI news" })
2. click({ selector: "button[type='submit']" })

自定义JavaScript

User: "Get the number of images on the page"

AI will call:
1. evaluate({ script: "return document.images.length" })

发展

# Build
npm run build

# Run in development
npm run dev

建筑

┌─────────────────────────────────────┐
│         MCP Client (Claude)         │
└──────────────┬──────────────────────┘
               │ JSON-RPC / stdio
┌──────────────▼──────────────────────┐
│     Web Automation MCP Server       │
│  ┌─────────────────────────────┐    │
│  │   15 Tool Definitions       │    │
│  └─────────────┬───────────────┘    │
│  ┌─────────────▼───────────────┐    │
│  │   Playwright Browser        │    │
│  │   (Chromium, headless)      │    │
│  └─────────────────────────────┘    │
└─────────────────────────────────────┘

局限性

  • 一些具有机器人保护的网站(Cloudflare、CAPTCHA)可能会阻止自动化
  • 始终遵守网站服务条款
  • 在抓取之前检查robots.txt
  • 使用可用的官方API

许可证

麻省理工学院