Penpot MCP服务器
通过模型上下文协议访问自托管Penpot的AI驱动设计工具。
   
______________________________________________________________________
这是什么?
一 MCP服务器 它为AI代理(如Claude Code、Cursor或任何兼容MCP的客户端)提供支持 完全程序化访问 到你自己主持 佩普特 例子AI可以通过自然语言读取、创建、修改和导出设计元素——从矩形和文本到完整的UI组件。
将其视为您的AI助手和设计工具之间的桥梁。
它解决的问题
| 问题 | 解决方案 |
|---|---|
| 手工设计工作 | AI直接在Penpot中创建UI组件、布局和原型 |
| Penpot没有可编程的API | 68个工具,涵盖项目、形状、文本、导出、评论等 |
| 设计到代码间隙 | 从任何形状生成CSS,导出为SVG/PNG,提取设计标记 |
| 重复性任务 | 批处理操作——重命名形状、更新颜色、创建变体 |
| 设计系统维护 | 以编程方式读取/写入组件、颜色、排版 |
______________________________________________________________________
建筑
graph TB
AI["AI Agent\n(Claude Code · Cursor · Gemini CLI)"]
subgraph SERVERS["MCP Layer"]
MCP["penpot-mcp — Python\n68 tools · :8787\nDB reads + API writes + Plugin"]
OMCP["Penpot MCP — Official\n~20 tools · penpot/penpot monorepo\nPlugin API only · TypeScript"]
end
subgraph PENPOT["Penpot Stack (Docker)"]
PG["PostgreSQL\n:5432"]
BE["Backend\n:6060"]
FE["Frontend\n:9001"]
EX["Exporter\n:6061"]
end
subgraph BRIDGE["Browser Plugin Bridge"]
WS["WebSocket Server\n:4402"]
UI["ui.html\niframe · full browser API"]
PJ["plugin.js\nworker sandbox · penpot.*"]
end
AI -->|"Streamable HTTP :8787"| MCP
AI -->|"Streamable HTTP"| OMCP
MCP -->|"asyncpg · direct SQL"| PG
MCP -->|"httpx · RPC API"| BE
MCP -->|"PNG / SVG export"| EX
MCP |"WebSocket"| WS
OMCP |"WebSocket :4402"| WS
WS |"ws://localhost:4402"| UI
UI |"postMessage"| PJ
PJ -->|"penpot.* API"| FE
FE -.->|"proxy"| BE
BE --> EX
style AI fill:#7c3aed,color:#fff
style MCP fill:#2563eb,color:#fff
style OMCP fill:#0f766e,color:#fff
style PG fill:#16a34a,color:#fff
style BE fill:#ea580c,color:#fff
style FE fill:#ea580c,color:#fff
style EX fill:#ea580c,color:#fff
style WS fill:#0891b2,color:#fff
style UI fill:#0891b2,color:#fff
style PJ fill:#0891b2,color:#fff三层接入策略:
- 阅读 直接通过以下方式访问PostgreSQL
asyncpg-快速可靠,绕过API开销 - 写入 通过Penpot的RPC API
httpx--确保正确的更改跟踪和撤消历史记录 - 出口 使用Penpot的内置导出器(无头Chromium)实现像素完美的SVG/PNG输出
- 现场画布 通过浏览器插件桥(端口4402)——与 官方Penpot MCP,使两台服务器能够在同一个AI工作流程中共存并相互补充
______________________________________________________________________
技术栈
| 组件 | 技术 | 目的 |
|---|---|---|
| 语言 | Python 3.13 | 运行时 |
| MCP-SDK | FastMCP | 协议处理、工具注册 |
| 数据库 | 异步pg | 直接访问PostgreSQL |
| HTTP客户端 | httpx | Penpot RPC API调用 |
| 验证 | Pydantic v2 | 自动参数验证 |
| 包管理器 | 紫外线 | 快速Python依赖管理 |
| websocket | websockets | 实时浏览器插件桥 |
| 容器 | Docker | 与Penpot一起部署 |
______________________________________________________________________
快速开始
先决条件
选项A:自动设置
git clone https://github.com/ancrz/penpot-mcp-server.git
cd penpot-mcp-server
chmod +x setup.sh
./setup.sh该脚本将指导您完成配置、构建Docker镜像和启动服务器。
选项B:手动设置
1.克隆存储库
git clone https://github.com/ancrz/penpot-mcp-server.git
cd penpot-mcp-server2.创建配置
cp .env.example .env编辑 .env 您的Penpot详细信息:
# Your Penpot access token (see "Enable Access Tokens" below)
PENPOT_ACCESS_TOKEN=your-token-here
# Your Penpot database password (from your Penpot docker-compose.yml)
PENPOT_DB_PASS=your-db-password
# Public URL where you access Penpot in the browser
PENPOT_PUBLIC_URL=http://localhost:90013.将MCP服务添加到您的Penpot Docker堆栈中
添加 penpot-mcp 为您现有的Penpot定义服务 docker-compose.yml。参见 以便复制完整的服务定义。
4.构建并启动
docker compose up -d --build penpot-mcp5.验证它是否正在运行
# Quick health check
curl -s http://localhost:8787/
# → {"service": "Penpot MCP", "status": "ok", "version": "0.1.0"}# Full MCP protocol initialization
curl -s http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'您应该看到具有服务器功能的JSON响应。
______________________________________________________________________
连接您的AI代理
Penpot MCP使用 网络传输 (流式HTTP)——服务器作为Docker容器运行,客户端通过HTTP连接。这意味着:
- 服务器是 一直在跑 独立(通过Docker Compose)
- 客户端只需要URL即可连接,无需生成进程
env在客户端的JSON配置中是不相关的 --凭据位于服务器自己的凭据中.env文件(在 设置)- 同一台机器(或网络)上的任何客户端都可以连接到
http://localhost:8787/mcp
与stdio服务器的主要区别: 对于stdio服务器(如Skill Swarm),客户端启动进程并注入env变量。对于像Penpot MCP这样的网络服务器,服务器管理自己的凭据。这 env 客户端MCP配置中的块无效。______________________________________________________________________
克劳德代码
克劳德代码使用 "type": "http" 用于流式HTTP连接。
全球 (~/.claude.json):
{
"mcpServers": {
"penpot": {
"type": "http",
"url": "http://localhost:8787/mcp"
}
}
}项目级别 (.mcp.json 在项目根目录中):
{
"mcpServers": {
"penpot": {
"type": "http",
"url": "http://localhost:8787/mcp"
}
}
}重新启动克劳德代码。你应该看看 68工具 从 penpot 运行时列出的服务器 /mcp.
注: 使用"type": "http",不"streamable-http".Claude代码映射http内部可流式传输HTTP。使用streamable-http将导致架构验证错误。
______________________________________________________________________
Gemini CLI
Gemini CLI使用 httpUrl (不是 url)用于流式HTTP连接。传输是从字段名推断出来的。
配置文件: ~/.gemini/settings.json
{
"mcpServers": {
"penpot": {
"httpUrl": "http://localhost:8787/mcp"
}
}
}注: Gemini CLI区别于url(苏格兰和南方能源公司运输)和httpUrl(流式HTTP传输)。Penpot MCP使用流式HTTP,因此使用httpUrl不type场需要。
______________________________________________________________________
反重力
反重力用途 serverUrl 用于基于HTTP的MCP服务器。
配置文件: ~/.gemini/antigravity/mcp_config.json
{
"mcpServers": {
"penpot": {
"serverUrl": "http://localhost:8787/mcp"
}
}
}注: 反重力用途serverUrl(不是url或httpUrl).如果Antigravity在Docker中运行,请确保它可以访问localhost:8787在主机上--您可能需要host.docker.internal:8787而不是localhost:8787这取决于你的Docker网络设置。
______________________________________________________________________
快速比较
| 克劳德代码 | 双子座CLI | 反重力 | |
|---|---|---|---|
| 配置文件 | ~/.claude.json 或 .mcp.json | ~/.gemini/settings.json | ~/.gemini/antigravity/mcp_config.json |
| URL字段 | "url" | "httpUrl" | "serverUrl" |
| 类型字段 | "type": "http" (必填) | 不需要(推断) | 不必要(推断) |
env JSON格式 | 无影响(网络服务器) | 无影响(网服务器) | 不影响(网服务) |
| 凭证 | 服务器 .env 文件 | 服务器的 .env 文件 | 服务器的 .env 文件 |
| Docker网络 | localhost:8787 | localhost:8787 | 可能需要 host.docker.internal:8787 |
______________________________________________________________________
示例提示
连接后,您可以向您的AI代理询问以下问题:
- *“列出我的Penpot项目”*
- *“创建一个包含电子邮件/密码字段和提交按钮的登录表单”*
- *“将登录卡框架导出为SVG”*
- *“设计系统中定义了哪些颜色?”*
- *在位置(100200)添加一条评论,说“查看此布局”*
______________________________________________________________________
交互模式:浏览器插件
Penpot MCP插件将AI代理与 现场Penpot画布,实现实时上下文感知:
- 现场选择:AI可以查询您当前选择的形状
- 脚本执行:AI可以通过Penpot插件API直接运行JavaScript
这些功能需要连接浏览器插件。66个无头工具不用它也能工作。
加载插件
- 确保MCP服务器正在运行:
docker compose up -d penpot-mcp - 在浏览器中打开Penpot
- 按 Ctrl+Alt+P (或主菜单->插件管理器)
- 将URL粘贴到输入字段中:
http://localhost:8787/plugin/manifest.json - 点击 安装 → 允许 在“权限”对话框上
- 点击 打开 启动插件面板
插件面板出现在右侧。当状态指示器变为绿色时,AI代理可以实时访问画布。
Penpot标志要求
Penpot后端必须具有 enable-plugins-runtime 在 PENPOT_FLAGS:
PENPOT_FLAGS=enable-login-with-password enable-registration enable-access-tokens enable-plugins-runtime需要重新启动: 添加后enable-plugins-runtime,重新启动两者penpot-backend和penpot-frontend: ``bash docker compose restart penpot-backend penpot-frontend``
浏览器兼容性
| 浏览器 | 状态 | 注释 |
|---|---|---|
| 火狐 | 开箱即用 | 无本地网络限制 |
| 铬/铬 | 需要一次性批准 | 见下文 |
| 勇敢 | 需要禁用屏蔽 | 见下文 |
| 维瓦尔第 | 需要一次性批准 | 与Chrome相同 |
Chrome/Vivaldi:本地网络访问
Chrome可能会显示一个权限弹出窗口: “允许\[localhost:9001\]访问您的本地网络吗?”
- 点击 允许 当弹出窗口出现时
- 插件将自动连接
如果没有弹出窗口出现并且插件保持断开连接,请检查 chrome://flags/#private-network-access-respect-preflight-results --禁用它以进行本地开发。
勇敢:盾牌
- 点击 盾牌图标 地址栏中的(狮子)
- 禁用屏蔽
localhost:9001(或设置为“无阻塞”) - 重新加载Penpot选项卡并重新连接插件
______________________________________________________________________
工具概述
服务器提供 68工具 跨越11个类别。看 TOOLS.md 以获取所有参数的完整参考。
| 类别 | 计数 | 示例 |
|---|---|---|
| 项目和团队 | 4 | list_projects, list_teams, list_files, search_files |
| 文件操作 | 9 | create_file, get_file_pages, rename_file, duplicate_file |
| 形状读取 | 6 | get_shape_tree, get_shape_details, get_shape_css, search_shapes |
| 组件和令牌 | 4 | get_design_tokens, get_colors_library, get_typography_library |
| 评论 | 6 | create_comment, reply_to_comment, resolve_comment |
| 媒体和字体 | 3 | upload_media, list_media_assets, list_fonts |
| 数据库和高级 | 3 | query_database, get_webhooks, get_profile |
| 快照 | 2 | create_snapshot, get_snapshots |
| 导出 | 2 | export_frame_png, export_frame_svg |
| 形状创建 | 8 | create_rectangle, create_frame, create_text, create_path |
| 形状修改 | 12 | set_fill, set_stroke, set_layout, move_shape, resize_shape |
| 文本操作 | 5 | set_text_content, set_font, set_font_size, set_text_align |
| 高级分析 | 2 | get_file_raw_data, compare_revisions |
______________________________________________________________________
配置参考
所有设置都是通过环境变量进行的。看 .env.example 对于模板。
| 变量 | 默认值 | 描述 |
|---|---|---|
PENPOT_BASE_URL | http://penpot-frontend:8080 | 内部Penpot URL(Docker网络) |
PENPOT_PUBLIC_URL | http://localhost:9001 | 您在浏览器中访问Penpot的公共URL |
PENPOT_ACCESS_TOKEN | - | API访问令牌(首选身份验证方法) |
PENPOT_EMAIL | -- | penpot登录电子邮件(回退身份验证) |
PENPOT_PASSWORD | -- | Penpot登录密码(回退身份验证) |
PENPOT_DB_HOST | penpot-postgres | PostgreSQL主机 |
PENPOT_DB_PORT | 5432 | PostgreSQL端口 |
PENPOT_DB_NAME | penpot | 数据库名称 |
PENPOT_DB_USER | penpot | 数据库用户 |
PENPOT_DB_PASS | -- | 数据库密码 |
MCP_HOST | 0.0.0.0 | MCP服务器绑定地址 |
MCP_PORT | 8787 | MCP服务器端口 |
MCP_LOG_LEVEL | info | 日志级别(调试/信息/警告/错误) |
WS_HOST | 0.0.0.0 | WebSocket服务器绑定地址 |
WS_PORT | 4402 | 浏览器插件的WebSocket端口 |
PLUGIN_WS_URL | ws://localhost:4402 | 浏览器插件用于连接的WebSocket URL |
______________________________________________________________________
启用访问令牌
Penpot需要一个功能标志来启用API访问令牌。
1.更新你的Penpot .env 文件
添加 enable-access-tokens 致你的 PENPOT_FLAGS:
PENPOT_FLAGS=enable-login-with-password enable-registration enable-access-tokens2.重新启动Penpot
docker compose restart penpot-backend penpot-frontend3.创建令牌
- 在浏览器中打开Penpot
- 点击您的头像(左下角)→ 访问令牌
- 点击 “生成新令牌”
- 为其命名(例如,“MCP服务器”)
- 复制令牌并将其粘贴到您的
.env作为PENPOT_ACCESS_TOKEN
______________________________________________________________________
Penpot Docker集成
MCP服务器作为Docker容器与现有的Penpot堆栈一起运行。你需要将其添加到你的Penpot中 docker-compose.yml.
看 以添加确切的服务定义。关键点:
- 它连接到
penpotDocker网络(与其他Penpot服务相同) - 这取决于
penpot-postgres(进行健康检查)以及penpot-backend - 它暴露了端口
8787仅在本地主机上(127.0.0.1:8787:8787) - 环境变量引用Docker内部主机名
______________________________________________________________________
发展
本地运行(Docker之外)
# Install uv if needed
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync
# Run the server (needs .env configured for local access)
uv run penpot-mcp对于当地发展,点 PENPOT_DB_HOST 和 PENPOT_DB_PORT 到您的主机映射PostgreSQL端口,以及 PENPOT_BASE_URL 到 http://localhost:9001.
运行测试
uv sync --group dev
uv run pytest tests/ -v项目结构
penpot-mcp-server/
├── src/penpot_mcp/
│ ├── server.py # FastMCP entry point, 68 tool registrations, plugin routes
│ ├── config.py # Pydantic Settings configuration
│ ├── gateway.py # Hybrid context gateway (DB + Plugin awareness)
│ ├── ws_controller.py # WebSocket server for browser plugin bridge (:4402)
│ ├── plugin/
│ │ ├── manifest.json # Penpot plugin manifest (served at /plugin/manifest.json)
│ │ ├── plugin.js # Plugin worker — penpot.* API only (no WebSocket in sandbox)
│ │ └── ui.html # Plugin iframe — WebSocket lives here, relays to plugin.js
│ ├── services/
│ │ ├── db.py # asyncpg connection pool
│ │ ├── api.py # httpx RPC API client
│ │ ├── changes.py # Penpot change operations builder
│ │ └── transit.py # Transit+JSON decoder
│ ├── tools/
│ │ ├── projects.py # Team & project queries
│ │ ├── files.py # File CRUD operations
│ │ ├── shapes.py # Shape reading & search
│ │ ├── create.py # Shape creation
│ │ ├── modify.py # Shape modification
│ │ ├── text.py # Text operations
│ │ ├── export.py # PNG/SVG export
│ │ ├── components.py # Components & design tokens
│ │ ├── comments.py # Comments & collaboration
│ │ ├── media.py # Media assets & fonts
│ │ ├── database.py # Raw SQL queries
│ │ └── advanced.py # File raw data & revision comparison
│ └── transformers/
│ ├── css.py # Shape → CSS conversion
│ ├── svg.py # Shape → SVG conversion
│ └── layout.py # Layout → CSS flexbox/grid
├── tests/
│ ├── conftest.py
│ ├── test_projects.py
│ ├── test_files.py
│ ├── test_shapes.py
│ └── test_e2e_login_form.py
├── pyproject.toml
├── Dockerfile
├── .env.example
├── setup.sh
├── docker-compose.penpot.yml
├── TOOLS.md
└── LICENSE______________________________________________________________________
许可证
该项目根据 Apache许可证2.0.
______________________________________________________________________
