屏幕截图服务

一个MCP服务器,为AI代理提供在Linux系统上捕获运行中应用程序窗口截图的功能,支持X11和Wayland/KDE Plasma 6。

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

使用说明

MCP服务器截图

MCP(模型上下文协议)服务器,使AI代理能够捕获Linux系统上运行的应用程序窗口的屏幕截图。支持X11和Wayland/KDE Plasma 6。

概述

此MCP服务器为AI代理提供了列出所有正在运行的应用程序窗口并捕获特定窗口屏幕截图的能力。它专为与Claude、Cursor和其他MCP兼容的AI助手一起使用而设计。

主要特点:

  • 列出所有带有标题和进程ID的可见应用程序窗口
  • 按ID捕获任何正在运行的窗口的屏幕截图
  • 自动平台检测(X11或Wayland/KDE)
  • 返回文件路径,便于与AI工作流集成
  • 优雅的错误处理和有用的安装提示

需求

X11系统

# Arch Linux
sudo pacman -S xdotool imagemagick

# Ubuntu/Debian
sudo apt install xdotool imagemagick

# Fedora
sudo dnf install xdotool ImageMagick

Wayland/KDE等离子系统

# Arch Linux
sudo pacman -S grim xdotool  # xdotool for fallback window listing

# Ubuntu/Debian
sudo apt install grim wl-clipboard

# Fedora
sudo dnf install grim

python

  • Python 3.10或更高版本
  • MCP-SDK(mcp>=1.0.0)

安装

来源

# Clone the repository
git clone https://github.com/adityachauhan0/screenshot-mcp.git
cd screenshot-mcp

# Install in development mode
pip install -e .

# Or install dependencies only
pip install -r requirements.txt

配置MCP客户端

添加到您的MCP客户端配置中(例如,Claude Desktop、Cursor):

{
  "mcpServers": {
    "screenshot": {
      "command": "screenshot-mcp"
    }
  }
}

用法

可用工具

list_windows

返回所有可见应用程序窗口的列表。

退货:

{
  "windows": [
    {
      "id": "1234567890",
      "title": "Firefox - MCP Server Documentation",
      "pid": 1234,
      "is_active": true
    }
  ]
}

capture_window

捕获指定窗口的屏幕截图。

输入:

  • window_id (string,必填):要捕获的窗口ID

退货:

{
  "path": "/tmp/screenshot_mcp_20260325_143022.png",
  "success": true
}

AI代理对话示例

Agent: List all open windows
User: [
  {id: "12345", title: "Terminal", pid: 1000, is_active: true},
  {id: "67890", title: "Firefox", pid: 2000, is_active: false}
]

Agent: Take a screenshot of the Firefox window
User: {path: "/tmp/screenshot_mcp_20260325_143022.png", success: true}

平台检测

服务器会自动检测您的显示服务器:

环境变量 平台
WAYLAND_DISPLAY set Wayland/KDE Plasma
DISPLAY 设置 X11
均未设置 X11(默认)

错误处理

服务器提供明确的错误消息和安装提示:

错误 原因 解决方案
“未安装屏幕截图工具” 缺少依赖关系 为您的发行版运行install命令
“找不到窗口” 无效的Window_id 运行 list_windows 获取有效ID
“权限被拒绝” 窗口访问问题 检查窗口权限

发展

# Clone and setup
git clone https://github.com/adityachauhan0/screenshot-mcp.git
cd screenshot-mcp
pip install -e .

# Run tests
pytest tests/ -v

# Install dev dependencies
pip install pytest pytest-asyncio

项目结构

screenshot_mcp/
├── src/screenshot_mcp/
│   ├── server.py          # MCP server implementation
│   ├── platform/
│   │   ├── base.py       # Abstract base class
│   │   ├── x11.py        # X11 window capture
│   │   └── wayland.py    # Wayland/KDE window capture
│   └── utils.py           # Utilities
├── tests/                 # Unit tests
├── LICENSE
└── README.md

贡献

欢迎投稿!请打开问题或提交拉取请求。

许可证

MIT许可证-请参阅 许可证 了解详情。

相关