本地浏览器自动化服务

MCP Server Local Browser 是一个基于AI的本地浏览器自动化服务,支持自然语言操作,无需云端处理,确保数据隐私和安全。

  • by btree1970
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 btree1970/stage-hand-local-mcp

使用说明

MCP服务器本地浏览器

用于AI驱动的浏览器自动化的模型上下文协议(MCP)服务器,可在您的机器上100%本地运行。由舞台手和剧作家建造。

特性

  • 🖥️ 100%本地:直接在您的计算机上运行Chrome/Chromium
  • 🤖 AI驱动:使用Stagehand实现自然语言浏览器自动化
  • 🚀 快速:没有云延迟,一切都在本地运行
  • 🔒 私人:您的数据永远不会离开您的机器
  • 🎯 MCP兼容:适用于Claude Desktop、Cursor和其他MCP客户端

先决条件

  • Node.js 18或更高版本
  • Chrome或Chromium浏览器
  • 人工智能模型API密钥(选择一个):
    • Google Gemini API密钥(推荐)
    • OpenAI API密钥
    • 无烟煤API键

安装

来自npm(即将推出)

npm install -g mcp-server-local-browser

来源

git clone https://github.com/yourusername/mcp-server-local-browser.git
cd mcp-server-local-browser
pnpm install
pnpm build
pnpm playwright install chromium

配置

克劳德代码(VSCode扩展)

使用Claude Code命令面板添加服务器:

claude mcp add browser /path/to/mcp-server-local-browser/cli.js --env GEMINI_API_KEY=your-api-key-here

例如,如果您已将此仓库克隆到主目录:

claude mcp add browser ~/mcp-server-local-browser/cli.js --env GEMINI_API_KEY=AIzaSyD...your-key

您还可以添加其他选项:

claude mcp add browser ~/mcp-server-local-browser/cli.js \
  --env GEMINI_API_KEY=your-api-key-here \
  --arg "--headless" \
  --arg "--width" --arg "1920" \
  --arg "--height" --arg "1080"

克劳德桌面

添加到您的Claude Desktop配置(~/Library/Application Support/Claude/claude_desktop_config.json 在 macOS 上:

{
  "mcpServers": {
    "browser": {
      "command": "npx",
      "args": ["mcp-server-local-browser"],
      "env": {
        "GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}

来源

{
  "mcpServers": {
    "browser": {
      "command": "node",
      "args": ["/path/to/mcp-server-local-browser/cli.js"],
      "env": {
        "GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}

可用工具

导航

导航到任何URL。

{
  "url": "https://example.com"
}

截图

捕获页面或特定元素的屏幕截图。

{
  "fullPage": true,        // Optional: capture full page
  "selector": "#element",  // Optional: capture specific element
  "name": "screenshot"     // Optional: name for the file
}

行动

使用自然语言执行操作。

{
  "action": "Click the login button and enter username 'john@example.com'"
}

提取

从页面中提取结构化数据。

{
  "instruction": "Extract all product names and prices"
}

观察

获取有关页面内容的AI观察结果。

{
  "instruction": "Describe the main navigation menu"
}

CLI选项

mcp-local-browser [options]

Options:
  --headless              Run browser in headless mode
  --browser-path <path>   Path to Chrome/Chromium executable
  --user-data-dir <path>  Browser profile directory
  --width <width>         Viewport width (default: 1280)
  --height <height>       Viewport height (default: 720)
  --model-name <model>    AI model to use
  --model-api-key <key>   API key for the model
  --verbose <level>       Verbosity level 0-2 (default: 1)
  --debug-dom            Enable DOM debugging
  --enable-caching       Enable caching
  --experimental         Enable experimental features

环境变量

  • GEMINI_API_KEY:Google Gemini API密钥
  • OPENAI_API_KEY:OpenAI API密钥
  • ANTHROPIC_API_KEY:无烟煤API键

例子

Claude Desktop的基本用法

配置后,您可以询问Claude:

  • “导航到GitHub并搜索MCP服务器”
  • “截取当前页面的屏幕截图”
  • “单击登录按钮”
  • “提取此页面的所有链接”
  • “这个网页上有什么?”

使用自定义Chrome配置文件

要使用已保存Cookie和扩展程序的现有Chrome个人资料:

{
  "args": [
    "mcp-server-local-browser",
    "--user-data-dir",
    "/Users/you/Library/Application Support/Google/Chrome/Default"
  ]
}

以无头模式运行

对于服务器环境或当您不需要看到浏览器时:

{
  "args": ["mcp-server-local-browser", "--headless"]
}

发展

# Install dependencies
pnpm install

# Build TypeScript
pnpm build

# Run tests
pnpm test

# Development mode with watch
pnpm watch

建筑

服务器使用:

  • 舞台工作人员:AI驱动的浏览器自动化库
  • 剧作家:跨浏览器自动化
  • MCP-SDK:模型上下文协议实现

故障排除

未找到浏览器

明确指定Chrome路径:

--browser-path "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"  # macOS
--browser-path "/usr/bin/google-chrome"  # Linux
--browser-path "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"  # Windows

API关键问题

确保您的API密钥已在环境中设置或通过CLI传递:

export GEMINI_API_KEY="your-key-here"
# or
mcp-local-browser --model-api-key "your-key-here"

贡献

欢迎投稿!请随时提交拉取请求。

许可证

麻省理工学院

鸣谢

构建于: