返回市场
麦克铬服务器

麦克铬服务器

作者:dlwjdtn5352 星标更新:2025-04-14

项目介绍

MCP Chrome Server

smithery 徽章 请我喝杯咖啡

基于MCP(模型-控制器-提示)的浏览器自动化Chrome服务器。

安装

预备条件

  • Python 3.12
  • 已安装的Google Chrome浏览器
  • uv(Python包管理器)或Docker

使用Smithery安装

npx -y @smithery/cli install @dlwjdtn535/mcp-chrome-server --client claude

配置设置

根据您的环境选择以下配置方法之一:

1. 使用uv(推荐)

Windows 设置:

{
  "mcpServers": {
    "mcp-chrome-server": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "%LOCALAPPDATA%\\Programs\\mcp-chrome-server\\src",
        "mcp-chrome-server"
      ],
      "env": {
        "CHROME_PROFILE_PATH": "%LOCALAPPDATA%\\Google\\Chrome\\User Data"
      }
    }
  }
}

macOS 设置:

{
  "mcpServers": {
    "mcp-chrome-server": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/usr/local/bin/mcp-chrome-server/src",
        "mcp-chrome-server"
      ],
      "env": {
        "CHROME_PROFILE_PATH": "$HOME/Library/Application Support/Google/Chrome"
      }
    }
  }
}

Linux 设置:

{
  "mcpServers": {
    "mcp-chrome-server": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/usr/local/bin/mcp-chrome-server/src",
        "mcp-chrome-server"
      ],
      "env": {
        "CHROME_PROFILE_PATH": "$HOME/.config/google-chrome"
      }
    }
  }
}

配置

Chrome 配置文件路径

每个操作系统的默认Chrome配置文件路径:

操作系统路径
Windows%LOCALAPPDATA%\Google\Chrome\User Data
macOS~/Library/Application Support/Google/Chrome
Linux~/.config/google-chrome

注意事项

  • 在启动自动化服务器之前关闭所有正在运行的Chrome实例
  • 确保Chrome配置文件目录具有正确的权限
  • 对于Docker设置,请确保卷挂载路径与您系统的Chrome配置文件路径匹配

凭证管理

使用系统密钥链安全地存储和管理登录信息:

# 保存凭证
result = tool_save_credentials(
    site="example.com",
    username="your_username",
    password="your_password"
)

# 获取已保存的凭证
result = tool_get_credentials(
    site="example.com",
    username="your_username"
)

主要功能

浏览器控制

# 打开浏览器
result = tool_open_browser()

# 导航到URL
result = tool_navigate(url="https://example.com")

# 关闭浏览器
result = tool_close_browser()

网页登录

result = tool_web_login(
    url="https://example.com/login",
    credentials={
        "username": "your_username",
        "password": "your_password"
    },
    selectors={
        "username": "#id",
        "password": "#pw",
        "submit": ".login-button"
    }
)

特殊处理:

  • 当检测到CAPTCHA时等待用户解决
  • 自动检测两步验证
  • 登录失败场景的详细分析

元素操作

# 点击元素
result = tool_click(selector=".button")

# 输入文本
result = tool_type(
    selector="#input-field",
    text="Hello, World!"
)

# 获取文本
result = tool_get_text(selector=".content")

# 获取多个元素
result = tool_get_elements(selector=".items")

重要考虑因素

  1. Chrome 配置文件使用

    • 验证正确的配置文件路径配置
    • 关闭使用该配置文件的所有其他Chrome窗口
  2. 防止自动化检测

    • 模拟自然用户行为
    • 在登录尝试之间保持适当的延迟
  3. 安全性

    • 始终使用系统密钥链来存储重要凭证
    • 不要在环境变量或配置文件中直接暴露凭证