计算机控制工具集

一个基于MCP协议的计算机控制工具集,提供屏幕截图、点击、输入、滚动等14种计算机控制功能,支持跨平台操作和安全检查。

  • by Sundeepg98
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 Sundeepg98/computer-use-mcp

使用说明

计算机使用MCP

[!注意] ✅ 生产准备就绪-清洁架构

此存储库具有 干净、生产就绪的架构 通过适当的依赖注入和全面的测试:

  • 零测试模式反模式 -在整个代码库中完全消除
  • 实际功能测试 -所有功能都经过适当的模拟和隔离测试
  • 安全功能 -全面的安全检查,涵盖全部测试
  • 与跨平台支持 -在Windows、Linux、WSL2和无头环境中进行了测试

准备投入生产使用 具有干净的依赖注入架构和100%的工作功能。

一个功能强大的MCP(模型上下文协议)服务器,为Claude和其他MCP兼容客户端提供计算机使用工具。通过全面的安全检查和视觉分析以编程方式控制您的计算机。

特性

  • 14计算机控制工具:屏幕截图、单击、键入、按键、滚动、拖动、等待、自动化,以及6个服务器管理工具
  • X服务器管理:内置对X服务器安装、配置和生命周期管理的支持
  • 视觉分析:深入分析屏幕内容和智能行动计划
  • 安全检查:全面保护,防止危险命令和敏感数据泄露
  • 与跨平台支持:适用于Linux、macOS和Windows(使用WSL2)
  • WSL2集成:Linux版Windows子系统的自动X11转发配置
  • 虚拟显示支持:用于CI/CD环境的Xvfb无头操作
  • MCP本地:与Claude和其他MCP兼容客户端无缝集成

安装

来源(当前方法)

这是一个需要从源代码安装的自定义MCP服务器:

# Clone the repository
git clone https://github.com/Sundeepg98/computer-use-mcp.git
cd computer-use-mcp

# Install dependencies
pip install -r requirements.txt

# Test the server (optional)
python3 start_mcp_server.py

# Add to Claude Code
claude mcp add -s user computer-use -- python3 $(pwd)/start_mcp_server.py

软件包管理器安装(未来)

我们计划在未来将其发布为npm和pip包:

# Coming soon:
# npm install -g computer-use-mcp
# pip install computer-use-mcp

X服务器设置

计算机使用MCP需要一个X服务器来实现屏幕截图和交互功能。该软件包包括自动X服务器检测和管理。

快速设置

运行附带的安装脚本以检查您的X服务器配置:

./setup_xserver.sh

WSL2设置

对于Linux用户的Windows子系统:

  1. 在Windows上安装X服务器 (选择一个):

    • VcXsrv (免费,推荐)
    • X410 (付费,来自微软商店)
    • Xming (免费)
  2. 配置X服务器:

    • 以“多窗口”模式启动
    • 禁用访问控制
    • 允许来自WSL2的连接
  3. 在WSL2中设置显示:

    export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0
    
  4. 添加到~/.bashrc 为了坚持:

    echo 'export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0' >> ~/.bashrc
    

虚拟显示器(无头)

对于CI/CD或无头环境,请使用Xvfb:

# Install Xvfb
sudo apt-get install xvfb

# Start virtual display
Xvfb :99 -screen 0 1920x1080x24 &
export DISPLAY=:99

或者使用内置的MCP工具:

  • install_xserver -安装所需的软件包
  • start_xserver -启动虚拟显示
  • xserver_status -检查状态

配置

克劳德代码

使用claude mcp add(推荐)

# Clone the repository first
git clone https://github.com/Sundeepg98/computer-use-mcp.git
cd computer-use-mcp

# Add to Claude Code using official command
claude mcp add -s user computer-use -- python3 $(pwd)/start_mcp_server.py

手动配置(备选)

如果您更喜欢手动配置,请在Claude Code配置中添加:

{
  "mcpServers": {
    "computer-use": {
      "type": "stdio",
      "command": "python3",
      "args": ["/path/to/computer-use-mcp/start_mcp_server.py"],
      "env": {}
    }
  }
}

备注:替换 /path/to/computer-use-mcp/ 使用克隆存储库的实际路径。

验证安装

添加MCP服务器后,验证其是否正常工作:

# Check MCP server status
claude mcp list

# You should see:
# computer-use: python3 /path/to/start_mcp_server.py - ✓ Connected

# Get detailed server info
claude mcp get computer-use

独立使用

from computer_use_mcp import ComputerUseServer

server = ComputerUseServer()
server.run()

可用工具

📸 截图

通过视觉分析捕捉和分析当前屏幕。

{
  "tool": "screenshot",
  "arguments": {
    "analyze": "Find the submit button"
  }
}

🖱️ 点击

单击特定坐标或所描述的元素。

{
  "tool": "click",
  "arguments": {
    "x": 500,
    "y": 300,
    "button": "left"
  }
}

⌨️ Type

键入带有自动安全验证的文本。

{
  "tool": "type",
  "arguments": {
    "text": "Hello, World!"
  }
}

🔤 按键

按键盘键或组合键。

{
  "tool": "key",
  "arguments": {
    "key": "Enter"
  }
}

📜 滚动

向任何方向滚动。

{
  "tool": "scroll",
  "arguments": {
    "direction": "down",
    "amount": 5
  }
}

✋ 拖拽

在两点之间单击并拖动。

{
  "tool": "drag",
  "arguments": {
    "start_x": 100,
    "start_y": 100,
    "end_x": 300,
    "end_y": 300
  }
}

⏱️ 等待

等待指定的持续时间。

{
  "tool": "wait",
  "arguments": {
    "seconds": 2.5
  }
}

🤖 自动化

通过智能规划自动化复杂任务。

{
  "tool": "automate",
  "arguments": {
    "task": "Fill out the login form and submit"
  }
}

🖥️ 安装X服务器

安装所需的X服务器软件包以获得显示支持。

{
  "tool": "install_xserver",
  "arguments": {}
}

🚀 启动X服务器

使用自定义分辨率启动虚拟X服务器。

{
  "tool": "start_xserver",
  "arguments": {
    "display_num": 99,
    "width": 1920,
    "height": 1080
  }
}

🛑 停止X服务器

按显示名称停止正在运行的X服务器。

{
  "tool": "stop_xserver",
  "arguments": {
    "display": ":99"
  }
}

🔗 设置WSL X转发

配置WSL2到Windows主机的X11转发。

{
  "tool": "setup_wsl_xforwarding",
  "arguments": {}
}

📊 X服务器状态

获取X服务器的状态并显示配置。

{
  "tool": "xserver_status",
  "arguments": {}
}

🧪 试验显示

测试当前显示配置。

{
  "tool": "test_display",
  "arguments": {}
}

安全

服务器包括全面的安全检查:

  • 命令阻止:防止危险的系统命令(rm-rf、format等)
  • 凭证保护:检测并屏蔽密码、API密钥和令牌
  • PII检测:识别和保护SSN、信用卡、电子邮件
  • 路径穿越预防:阻止对敏感系统目录的访问
  • URL验证:防止恶意URL方案(javascript:、file://等)

用法

克劳德代码

添加到您的 .mcp.json 如配置部分所示。

Python API

# Using the launcher script
import subprocess
subprocess.run(['python3', 'start_mcp_server.py'])

# Or directly with the MCP module
import sys
sys.path.append('src')
from mcp.mcp_server import main
main()

CLI使用情况

# Run the MCP server directly
python3 start_mcp_server.py

# Or test tools via JSON-RPC (for debugging)
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | python3 start_mcp_server.py

测试

运行综合测试套件:

# All tests
python3 -m pytest tests/

# Specific test categories
python3 -m pytest tests/test_safety.py
python3 -m pytest tests/test_visual.py
python3 -m pytest tests/test_mcp_protocol.py

# With coverage
python3 -m pytest --cov=src tests/

📊 建筑

computer-use-mcp/
├── src/mcp/                   # Clean MCP implementation
│   ├── mcp_server.py          # Main MCP server
│   ├── computer_use_refactored.py  # Core with dependency injection
│   ├── factory_refactored.py  # Factory pattern for DI
│   ├── safety_checks.py       # Safety validation
│   ├── visual_analyzer.py     # Visual analysis
│   ├── abstractions/          # Protocol definitions
│   ├── implementations/       # Platform implementations
│   ├── screenshot/            # Screenshot providers
│   └── input/                 # Input providers
├── start_mcp_server.py        # Server launcher
├── tests/                     # Comprehensive test suite
│   ├── test_mcp_protocol.py   # MCP protocol tests
│   ├── test_safety_security.py # Security tests
│   └── test_refactored_example.py # DI pattern tests
├── examples/
│   ├── basic_usage.py         # Simple examples
│   └── advanced_automation.py # Complex workflows
└── docs/
    ├── API.md                 # API documentation
    └── REFACTORING_GUIDE.md   # Architecture details

🔐 安全考虑

  • 切勿以提升的权限运行 除非绝对必要
  • 查看自动化脚本 执行前
  • 使用环境变量 敏感数据
  • 启用额外的安全检查 用于生产用途
  • 监控日志 可疑活动

贡献

欢迎投稿!请看 贡献.md 作为指导方针。

  1. 分叉存储库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 了解详情。

🙏 致谢

  • Anthropic 对于MCP协议
  • 开源社区的宝贵贡献

🐛 已知问题

  • 截图可能需要在Linux上配置X服务器
  • WSL2需要额外的显示设置
  • 某些键盘快捷键可能无法在所有应用程序中使用

📮 支持


采用清洁架构构建-通过依赖注入为生产做好准备