Model Context Protocol (MCP) 服务器用于在 macOS 和 Windows 上远程控制 Photoshop 的项目。
该项目使用 FastAPI 实现 MCP 服务器,并通过以下方式控制 Photoshop:
pip install photoshop-mcp-server
或者从源码安装:
git clone https://github.com/StarBoze/photoshop-mcp-server.git
cd photoshop-mcp-server
pip install -e .
详细的安装步骤请参阅安装指南。
使用 Python 的虚拟环境可以避免依赖关系冲突:
# 创建虚拟环境
python -m venv venv
# 激活虚拟环境(macOS/Linux)
source venv/bin/activate
# 激活虚拟环境(Windows)
venv\Scripts\activate
# 安装依赖包
pip install -e .
主要依赖包:
服务器可以以下列模式运行:
普通模式: photoshop-mcp-server start
前台模式: photoshop-mcp-server start --foreground
调试模式: photoshop-mcp-server start --debug
UXP 模式: photoshop-mcp-server start --bridge-mode uxp
# 启动服务器(根据平台默认后端)
photoshop-mcp-server start
# 显示帮助
photoshop-mcp-server --help
# macOS 使用 AppleScript 后端
photoshop-mcp-server start --bridge-mode applescript
# Windows 使用 PowerShell 后端
photoshop-mcp-server start --bridge-mode powershell
# 使用 UXP 后端(跨平台)
photoshop-mcp-server start --bridge-mode uxp
详细的使用方法请参阅文档。
使用 UXP 后端需要以下步骤:
photoshop-mcp-server package_plugin
photoshop-mcp-server install_plugin
根据显示的步骤安装插件
启动服务器并启用 UXP 后端
photoshop-mcp-server start --bridge-mode uxp
bridge_mode 参数为 uxpPOST /openFile
{
"path": "/path/to/file.psd",
"bridge_mode": "uxp"
}
使用 UXP 插件需要 Adobe UXP 开发工具。
打包插件
photoshop-mcp-server package_plugin
这将创建一个位于 dist/photoshop-mcp.zip 的插件包。
在 UXP 开发工具中添加插件
dist/photoshop-mcp.zip在 Photoshop 中启用插件
启动 MCP 服务器(UXP 模式)
photoshop-mcp-server start --bridge-mode uxp
确认连接
使用 UXP 后端时,也可以使用 WebSocket 端点:
ws://localhost:5001/ws
可以通过 WebSocket 直接发送和接收 JSON 消息。
从 v0.2.0 开始,Photoshop MCP Server 完全支持跨平台。新增的功能包括:
platform_utils.py 模块提供了以下功能:
get_platform(), is_windows(), is_macos())get_platform_config())get_temp_file())platform_specific 装饰器)# 示例:根据平台处理
from photoshop_mcp_server.bridge.platform_utils import platform_specific
@platform_specific(
windows_func=windows_specific_function,
macos_func=macos_specific_function,
default_func=default_function
)
def process_file(path):
# 根据平台自动调用相应的函数
pass
POST /generateThumbnail
{
"path": "/path/to/file.psd",
"width": 256,
"height": 256,
"format": "jpeg",
"quality": 80,
"bridge_mode": "uxp"
}
WebSocket 端点: ws://localhost:5001/generateThumbnail/stream
请求:
{
"path": "/path/to/file.psd",
"width": 256,
"height": 256,
"format": "jpeg",
"quality": 80,
"bridge_mode": "uxp"
}
响应(流式传输):
{
"type": "start",
"data": { ... }
}
{
"type": "progress",
"data": { "step": "opening_file", "progress": 10, "message": "正在打开文件..." }
}
{
"type": "progress",
"data": { "step": "generating_thumbnail", "progress": 30, "message": "正在生成缩略图..." }
}
...
{
"type": "complete",
"data": { "width": 256, "height": 256, "format": "jpeg" }
}
集群模式是一种管理多个 Photoshop 实例并分散处理任务的功能。 设计用于高效处理大量图像处理任务。
# 启动调度器
photoshop-mcp-server start_cluster --host 127.0.0.1 --port 8001
# 启动节点 1
photoshop-mcp-server start_node --host 127.0.0.1 --port 8002 --dispatcher 127.0.0.1:8001
# 启动节点 2
photoshop-mcp-server start_node --host 127.0.0.1 --port 8003 --dispatcher 127.0.0.1:8001
POST http://127.0.0.1:8001/submit_job
{
"job_type": "open_file",
"payload": {
"path": "/path/to/file.psd"
},
"priority": 1
}
# 调度器配置
dispatcher_config = {
"host": "127.0.0.1",
"port": 8001,
"routing_strategy": "least_busy", # least_busy, round_robin, random, lowest_latency, capability_based
"node_timeout": 60.0,
"job_timeout": 300.0,
"health_check_interval": 30.0
}
# 节点配置
node_config = {
"host": "127.0.0.1",
"port": 8002,
"dispatcher": "127.0.0.1:8001",
"capabilities": ["open_file", "save_file", "export_layer", "run_action"],
"max_concurrent_jobs": 5
}
LLM 自动修图功能使用 LiteLLM 分析图像并自动生成修图参数。 使用 GPT-4 Vision 等多模态模型分析图像并生成最佳修图参数。
POST /autoRetouch
{
"path": "/path/to/image.jpg",
"instructions": "使皮肤更光滑,并增加对比度",
"bridge_mode": "uxp"
}
响应:
{
"analysis": {
"basic_info": {
"image_type": "肖像",
"main_subject": "女性",
"overall_impression": "在自然光下拍摄的室外肖像"
},
"technical_characteristics": {
"brightness": {
"status": "稍暗",
"value": -15
},
"contrast": {
"status": "较弱",
"value": -20
},
...
},
...
},
"retouch_actions": [
{
"type": "brightness_contrast",
"params": {
"brightness": 15,
"contrast": 20
}
},
{
"type": "skin_smoothing",
"params": {
"strength": 30,
"detail": 50
}
},
...
],
"execution_result": {
"status": "成功",
"actions_applied": 5,
"execution_time": 3.5
}
}
这张照片是在户外拍摄的肖像。请注意以下几点进行修图:
1. 使皮肤更光滑(强度:中等)
2. 提高眼睛的亮度和对比度
3. 稍微模糊背景
4. 调整整体色调,使其具有温暖的感觉
为了将 Photoshop MCP Server 与 MCP 客户端(如 AI 助手)集成,需要配置文件。
配置文件通常位于 mcp-config/photoshop-mcp-server.json,其结构如下:
{
"server_info": {
"name": "photoshop-mcp-server",
"description": "适用于 macOS 和 Windows 的 Photoshop MCP Server",
"version": "0.2.0",
"endpoint": "http://localhost:5001"
},
"tools": [
{
"name": "open_file",
"description": "在 Photoshop 中打开文件",
"input_schema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "文件路径"
},
"bridge_mode": {
"type": "string",
"description": "使用的桥接模式(applescript, powershell, uxp)",
"default": "default"
}
},
"required": ["path"]
}
},
{
"name": "save_file",
"description": "保存当前文件",
"input_schema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "保存文件的路径"
},
"format": {
"type": "string",
"description": "文件格式(psd, jpg, png, tiff)",
"default": "psd"
},
"bridge_mode": {
"type": "string",
"description": "使用的桥接模式",
"default": "default"
}
},
"required": ["path"]
}
},
{
"name": "run_action",
"description": "运行 Photoshop 动作",
"input_schema": {
"type": "object",
"properties": {
"action_set": {
"type": "string",
"description": "动作集名称"
},
"action_name": {
"type": "string",
"description": "动作名称"
},
"bridge_mode": {
"type": "string",
"description": "使用的桥接模式",
"default": "default"
}
},
"required": ["action_set", "action_name"]
}
},
{
"name": "generate_thumbnail",
"description": "从 PSD 文件生成缩略图",
"input_schema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "PSD 文件路径"
},
"width": {
"type": "integer",
"description": "缩略图宽度",
"default": 256
},
"height": {
"type": "integer",
"description": "缩略图高度",
"default": 256
},
"format": {
"type": "string",
"description": "图像格式(jpeg, png)",
"default": "jpeg"
},
"quality": {
"type": "integer",
"description": "图像质量(1-100)",
"default": 80
},
"bridge_mode": {
"type": "string",
"description": "使用的桥接模式",
"default": "default"
}
},
"required": ["path"]
}
},
{
"name": "auto_retouch",
"description": "使用 LLM 对图像进行自动修图",
"input_schema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "图像路径"
},
"instructions": {
"type": "string",
"description": "修图指令"
},
"bridge_mode": {
"type": "string",
"description": "使用的桥接模式",
"default": "default"
}
},
"required": ["path", "instructions"]
}
}
],
"resources": [
{
"uri": "photoshop://status",
"description": "获取服务器状态"
},
{
"uri": "photoshop://version",
"description": "获取服务器版本"
},
{
"uri": "photoshop://plugin/status",
"description": "获取 UXP 插件状态"
}
]
}
mcp-config 目录(如果不存在)