Skip to main content
Glama
MCP Screenshot Server

MCP Screenshot Server

by sethbang

通用截图 MCP

npm version MCP Registry License

一个 MCP (Model Context Protocol) 服务器,为 AI 助手提供截图功能——既包括通过 Puppeteer 进行的网页截图,也包括使用原生操作系统工具进行的跨平台系统截图。

功能特性

  • 网页截图 — 使用无头 Chromium 浏览器捕获任何公共 URL

  • 跨平台系统截图 — 使用原生操作系统工具进行全屏、窗口或区域捕获(macOS screencapture,Linux maim/scrot/gnome-screenshot/等,Windows PowerShell+.NET)

  • 安全优先设计 — 防范 SSRF、路径遍历、DNS 重绑定、命令注入及拒绝服务 (DoS) 限制

  • MCP 原生 — 直接与 Claude Desktop、Cursor 及任何兼容 MCP 的客户端集成

Related MCP server: Chrome DevTools MCP

要求

  • Node.js >= 18.0.0

  • Chromium 在首次运行时由 Puppeteer 自动下载

take_system_screenshot 的平台特定要求

平台

所需工具

备注

macOS

screencapture (内置)

无需额外安装

Linux

以下之一:maim, scrot, gnome-screenshot, spectacle, grim, 或 import (ImageMagick)

推荐使用 maim 或 scrot 以获得完整功能支持。若需按名称捕获窗口,请同时安装 xdotool。

Windows

powershell (内置)

使用 .NET System.Drawing — 无需额外安装

Linux 安装示例

# Ubuntu/Debian (recommended)
sudo apt install maim xdotool

# Fedora
sudo dnf install maim xdotool

# Arch Linux
sudo pacman -S maim xdotool

# Wayland (Sway, etc.)
sudo apt install grim

安装后,您可以使用以下命令验证您的设置:

npx universal-screenshot-mcp --doctor

该命令会探测主机,并针对您检测到的发行版打印出缺失工具的复制粘贴安装命令。

快速入门

从 npm 安装

npm install -g universal-screenshot-mcp

或者直接使用 npx 运行:

npx universal-screenshot-mcp

从源码安装

git clone https://github.com/sethbang/mcp-screenshot-server.git
cd mcp-screenshot-server
npm install
npm run build

配置您的 MCP 客户端

将服务器添加到您的 MCP 客户端配置中。对于 Claude Desktop,编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "screenshot-server": {
      "command": "npx",
      "args": ["-y", "universal-screenshot-mcp"]
    }
  }
}

如果是从源码安装:

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

对于 Claude Code,使用 claude mcp add 命令注册服务器:

# Project scope (current directory only)
claude mcp add screenshot-server -- npx -y universal-screenshot-mcp

# User scope (available across all projects)
claude mcp add --scope user screenshot-server -- npx -y universal-screenshot-mcp

如果是从源码安装:

claude mcp add screenshot-server -- node /absolute/path/to/mcp-screenshot-server/build/index.js

使用 claude mcp list 验证服务器是否已注册,或在会话中使用 /mcp 查看实时状态。

对于 Cursor 或其他 MCP 客户端,请查阅其文档以获取相应的配置方法。

工具

该服务器公开了两个 MCP 工具:

take_screenshot

通过无头 Puppeteer 浏览器捕获网页(或特定元素)。

参数

类型

必需

描述

url

string

✅

要捕获的 URL (仅限 http/https)

width

number

—

视口宽度 (1–3840)

height

number

—

视口高度 (1–2160)

fullPage

boolean

—

捕获整个可滚动页面

selector

string

—

用于捕获特定元素的 CSS 选择器

waitForSelector

string

—

捕获前等待此选择器出现

waitForTimeout

number

—

延迟毫秒数 (0–30000)

outputPath

string

—

输出文件路径 (默认: ~/Documents/screenshots)

示例提示词:

对 https://example.com 进行 1920x1080 的截图

take_system_screenshot

使用原生操作系统工具捕获桌面、特定应用程序窗口或屏幕区域。适用于 macOS、Linux 和 Windows。

参数

类型

必需

描述

mode

enum

✅

fullscreen (全屏), window (窗口), 或 region (区域)

windowId

number

—

窗口模式下的窗口 ID

windowName

string

—

窗口模式下的应用名称 (例如 "Safari", "Firefox")

region

object

—

区域模式下的 { x, y, width, height }

display

number

—

多显示器设置下的显示器编号

includeCursor

boolean

—

在捕获中包含鼠标光标

format

enum

—

png (默认) 或 jpg

delay

number

—

捕获延迟秒数 (0–10)

outputPath

string

—

输出文件路径 (默认: ~/Documents/screenshots)

跨平台功能支持

功能

macOS

Linux

Windows

全屏

✅

✅

✅

区域

✅

✅ (maim, scrot, grim, import)

✅

按名称窗口

✅

⚠️ X11 + xdotool

⚠️ 尽力而为

按 ID 窗口

✅

✅ 仅限 X11

⚠️ HWND

多显示器

✅

⚠️ 依赖工具

✅

包含光标

✅

⚠️ 依赖工具

⚠️

延迟

✅

✅

✅

示例提示词:

对 Safari 窗口进行系统截图

配置

环境变量

变量

默认值

描述

SCREENSHOT_OUTPUT_DIR

Documents/screenshots

相对于 ~ 的默认输出目录

ALLOW_LOCAL

false

设置为 true 以允许对 localhost/127.x.x.x/[::1] 进行截图 (适用于本地开发服务器)

输出目录

截图默认保存到 ~/Documents/screenshots (可通过 SCREENSHOT_OUTPUT_DIR 配置)。自定义输出路径必须解析为以下允许的目录之一:

目录

描述

~/Documents/screenshots

默认输出位置 (可配置)

~/Desktop/Screenshots

原始默认位置

~/Downloads

用户下载文件夹

~/Documents

用户文档文件夹

/tmp

系统临时目录

安全性

本服务器实现了多层安全加固:

ID

威胁

缓解措施

SEC-001

SSRF / DNS 重绑定

URL 针对被阻止的 IP 范围进行验证;通过 --host-resolver-rules 在请求前解析 DNS 并锁定 IP;导航重定向会重新验证

SEC-003

命令注入

所有子进程均使用 execFile (无 shell);应用名称针对 SAFE_APP_NAME_PATTERN 进行验证

SEC-004

路径遍历

输出路径使用 fs.realpath() 符号链接解析进行验证;限制在允许的目录内

SEC-005

拒绝服务

并发的 Puppeteer 实例通过信号量限制为 3 个

详情请参阅 docs/security.md。

开发

脚本

命令

描述

npm run build

将 TypeScript 编译为 build/

npm run watch

文件更改时重新编译

npm test

单元测试 (快速,完全模拟)

npm run test:integration

集成测试 (真实 DNS/文件系统)

npm run test:e2e

端到端测试 (真实 Puppeteer/原生工具)

npm run test:all

运行所有层级的测试

npm run test:linux

通过 Docker 进行 Linux 端到端测试 (需要 Docker)

npm run test:watch

在监视模式下运行测试

npm run test:coverage

运行测试并生成覆盖率报告

npm run lint

使用 ESLint 对源码进行 Lint 检查

npm run inspector

启动 MCP Inspector 进行调试

项目结构

src/
├── index.ts                 # Entry point — stdio transport
├── server.ts                # MCP server factory
├── config/
│   ├── index.ts             # Static constants (limits, allowed dirs)
│   └── runtime.ts           # Singleton semaphore, default directory
├── tools/
│   ├── take-screenshot.ts   # Web page capture tool
│   └── take-system-screenshot.ts  # macOS system capture tool
├── types/
│   └── index.ts             # Shared TypeScript interfaces
├── utils/
│   ├── helpers.ts           # Response builders, file utilities
│   ├── screenshot-provider.ts # Cross-platform provider interface + factory
│   ├── macos-provider.ts    # macOS: screencapture wrapper
│   ├── linux-provider.ts    # Linux: maim/scrot/gnome-screenshot/etc.
│   ├── windows-provider.ts  # Windows: PowerShell + .NET System.Drawing
│   ├── macos.ts             # Window ID lookup via CoreGraphics
│   └── semaphore.ts         # Async concurrency limiter
└── validators/
    ├── path.ts              # Output path validation (SEC-004)
    └── url.ts               # URL/SSRF validation (SEC-001)

测试

测试使用 Vitest 分为三个层级:

  • 单元测试 (npm test) — 完全依赖注入,无真实 I/O。快速反馈循环。

  • 集成测试 (npm run test:integration) — 真实 DNS 解析,带有临时目录的真实文件系统,针对本地 HTTP 服务器的真实 Puppeteer。

  • 端到端测试 (npm run test:e2e) — 真实原生截图工具。macOS 测试在本地运行;Linux 测试通过 npm run test:linux 在 Docker 中运行。

npm test                 # Unit tests (~300ms)
npm run test:linux       # Linux provider tests in Docker
npm run test:all         # Everything

使用 MCP Inspector 调试

npm run inspector

这将启动连接到您已构建服务器的 MCP Inspector,允许您交互式地调用工具。

许可证

Apache-2.0 — 版权所有 2026 Seth Bang

Available Tools

2 tools
take_screenshotB

Capture web page or element via headless browser. Saves to ~/Documents/screenshots by default (configurable via SCREENSHOT_OUTPUT_DIR env var).

Inputs: url (required), width, height, fullPage, +4 more.

take_system_screenshotA

Capture desktop, window, or region screenshot. Cross-platform: macOS (screencapture), Linux (maim/scrot/gnome-screenshot/etc.), Windows (PowerShell+.NET). Saves to ~/Documents/screenshots by default (configurable via SCREENSHOT_OUTPUT_DIR env var). For window mode, provide windowName (app name like "Safari") or windowId.

Inputs: mode (required), delay, format, region, +5 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 2 tools

    Disambiguation4/5

    The two tools split cleanly along rendering source: headless browser page capture vs. OS-level desktop/window/region capture, and descriptions make this explicit. Minor risk remains because the generic name 'take_screenshot' doesn't signal 'web page only', so an agent skimming names could pick it for a desktop capture.

    Naming Consistency5/5

    Both follow the same verb_noun convention (take_screenshot, take_system_screenshot) with a consistent qualifier modifier. Predictable and readable as a set.

    Tool Count4/5

    Two tools are proportionate for a narrow screenshot-capture domain, and each covers a genuinely separate surface. It is on the thin side — a third tool (e.g., listing or re-opening saved captures) would round out the set.

    Completeness4/5

    Core capture scenarios are covered: web pages (including elements) and desktop, window, or region captures across all three OSes, with configurable output. Minor gaps around browsing/retrieving saved screenshots or format/full-page options, but agents can work around these via the filesystem.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      D
      maintenance
      Enables taking screenshots of web pages with support for multiple devices (desktop, mobile, tablet), custom dimensions, full-page capture, and various image formats. Built with Playwright for reliable web page rendering and screenshot generation.
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to capture any public URL as PNG, JPEG, or PDF via REST API or MCP tools, including screenshot capture, page description, and PDF rendering.
      22 npm
      MIT