A MCP server for generating web page screenshots using Playwright
Project description
webshot-mcp
一个用于生成网页截图的 MCP (Model Context Protocol) 服务器,基于 Playwright 和 Pillow 实现。
功能特性
- 🌐 支持任意网页截图
- 📱 支持多种设备类型(桌面、手机、平板)
- 🎨 支持多种图片格式(PNG、JPEG、WebP)
- 📏 支持自定义尺寸和 DPI 缩放
- 🖼️ 支持全页面截图
- 🗜️ 支持图片质量压缩
- ⚡ 异步处理,性能优异
安装
从源码安装
git clone <repository-url>
cd webshot-mcp
uv sync --extra dev
安装 Playwright 浏览器
uv run playwright install chromium
使用方法
作为 MCP 服务器
方式 1:使用 pip 安装后运行(推荐)
pip install webshot-mcp
然后在 MCP 客户端配置中添加:
{
"mcpServers": {
"webshot": {
"command": "webshot-mcp"
}
}
}
方式 2:使用 uvx 直接运行(无需安装)
{
"mcpServers": {
"webshot": {
"command": "uvx",
"args": ["webshot-mcp"]
}
}
}
方式 3:开发模式(从源码运行)
{
"mcpServers": {
"webshot": {
"command": "uv",
"args": ["run", "python", "-m", "webshot_mcp.server"],
"cwd": "/path/to/webshot-mcp"
}
}
}
工具参数
webshot 工具支持以下参数:
必需参数
url(string): 要截图的网页 URLoutput(string): 截图文件保存路径
可选参数
width(integer): 浏览器窗口宽度,默认 1280height(integer): 浏览器窗口高度,默认 768。设置为 0 时进行全页面截图dpi_scale(number): DPI 缩放比例,默认 2device(string): 设备类型,可选值:desktop(默认): 桌面设备mobile: 移动设备 (iPhone 13)tablet: 平板设备 (iPad Pro)
format(string): 图片格式,可选值:png(默认): PNG 格式jpeg: JPEG 格式webp: WebP 格式
quality(integer): 图片质量 (0-100),默认 100。仅对 JPEG 和 WebP 格式有效
使用示例
基本截图
{
"name": "webshot",
"arguments": {
"url": "https://example.com",
"output": "/tmp/screenshot.png"
}
}
全页面截图
{
"name": "webshot",
"arguments": {
"url": "https://example.com",
"output": "/tmp/fullpage.png",
"height": 0
}
}
移动设备截图
{
"name": "webshot",
"arguments": {
"url": "https://example.com",
"output": "/tmp/mobile.png",
"device": "mobile"
}
}
高质量 JPEG 截图
{
"name": "webshot",
"arguments": {
"url": "https://example.com",
"output": "/tmp/screenshot.jpg",
"format": "jpeg",
"quality": 90
}
}
自定义尺寸截图
{
"name": "webshot",
"arguments": {
"url": "https://example.com",
"output": "/tmp/custom.png",
"width": 1920,
"height": 1080,
"dpi_scale": 1
}
}
开发
运行测试
uv run pytest
代码结构
webshot-mcp/
├── src/webshot_mcp/
│ ├── __init__.py
│ ├── cli.py # CLI 入口
│ └── server.py # MCP 服务器实现
├── tests/
│ └── test_server.py # 测试用例
├── pyproject.toml # 项目配置
└── README.md
技术栈
- MCP: Model Context Protocol 框架
- Playwright: 浏览器自动化和截图
- Pillow: 图片处理和压缩
- asyncio: 异步编程支持
发布
构建和发布到 PyPI
# 安装构建工具
uv add --dev build twine
# 构建包
uv run python -m build
# 发布到 PyPI
uv run twine upload dist/*
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
更新日志
v0.1.0
- 初始版本
- 支持基本网页截图功能
- 支持多种设备类型和图片格式
- 支持图片质量压缩和尺寸调整
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
webshot_mcp-0.1.1.tar.gz
(60.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file webshot_mcp-0.1.1.tar.gz.
File metadata
- Download URL: webshot_mcp-0.1.1.tar.gz
- Upload date:
- Size: 60.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f53a8cd9fcf0d212087972263b3b32bf5e60697f124bb8c0ce066f554b48d24
|
|
| MD5 |
a690f84a9cd0b5ca32335b56cd9b3d66
|
|
| BLAKE2b-256 |
fb5326b8e4034456cbcb05fe3370c009630d76385cfffc00e21609beebbbff5f
|
File details
Details for the file webshot_mcp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: webshot_mcp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a4c5cee91ecf907610df3ae70f98a2669e37952677a0d988200927dce253ce2
|
|
| MD5 |
5dd112daede8783446d284c89c16d5aa
|
|
| BLAKE2b-256 |
0a8586a65b9aa137628c8588110951bc27d4380b0ac47f065d07ce822fd3bc18
|