使用说明
Unsplash MCP服务器
该项目实现了一个模型上下文协议(MCP)服务器,该服务器提供了与Unsplash API交互的工具,允许用户搜索和下载照片。
(注:更换 @shariqriazz 如果需要,请使用正确的用户名/命名空间)
Git仓库: https://github.com/shariqriazz/upsplash-mcp-server (如果这不是正确的URL,请更新)
特性
- 提供MCP工具与Unsplash API进行交互。
- 根据查询、分页和方向搜索照片。
- 下载指定分辨率的照片(原始、完整、常规、小)。
- 需要通过环境变量配置Unsplash访问密钥。
- 将照片下载到本地
unsplash/工作区内的目录。
提供的工具
-
search_photos:在Unsplash上搜索照片。- 输入架构:
{ "type": "object", "properties": { "query": { "type": "string", "description": "The search term(s)." }, "page": { "type": "number", "description": "Page number (default: 1).", "default": 1 }, "per_page": { "type": "number", "description": "Items per page (default: 10, max: 30).", "default": 10, "maximum": 30 }, "orientation": { "type": "string", "enum": ["landscape", "portrait", "squarish"], "description": "Filter by orientation." } }, "required": ["query"] } - 输出: 返回包含搜索结果和带图像链接的格式化文本摘要的JSON数据。
- 输入架构:
-
download_photo:将Unsplash照片下载到工作区的unsplash/触发下载跟踪事件后的文件夹。- 输入架构:
{ "type": "object", "properties": { "photo_id": { "type": "string", "description": "The ID of the photo to download." }, "resolution": { "type": "string", "enum": ["raw", "full", "regular", "small"], "description": "Desired resolution (default: raw).", "default": "raw" }, "filename": { "type": "string", "description": "Optional filename (e.g., my-image.jpg). Defaults to sanitized description or {photo_id}.jpg." } }, "required": ["photo_id"] } - 输出: 返回一条成功消息,其中包含下载文件的路径。
- 输入架构:
(注意:模式是说明性的。服务器通过MCP公开确切的模式。)
先决条件
- Node.js(建议使用v18+)
- Bun(
npm install -g bun) - Unsplash帐户和API访问密钥(https://unsplash.com/developers)
设置和安装
- 克隆存储库:
git clone https://github.com/shariqriazz/upsplash-mcp-server.git # Update URL if needed cd upsplash-mcp-server - 安装依赖关系:
bun install - 配置环境:
- 创建一个
.env项目根目录中的文件(或副本.env.example如果提供)。 - 添加您的Unsplash访问密钥:
UNSPLASH_ACCESS_KEY="YOUR_UNSPLASH_ACCESS_KEY"
- 创建一个
- 构建服务器:这将TypeScript代码编译为
bun run buildbuild/index.js.
用法(独立/NPX)
独立(本地构建):
您可以直接使用以下命令运行编译后的服务器 bun 或 node.确保 UNSPLASH_ACCESS_KEY 环境变量已在shell中设置,或 .env 文件。
# Ensure UNSPLASH_ACCESS_KEY is set
bun run build/index.js
# OR
node build/index.js
使用NPX(如果发布到npm):
如果此包发布到npm(例如,as unsplash-mcp-server),您可以直接使用以下命令运行它 npx.
# Ensure UNSPLASH_ACCESS_KEY is set in your environment
npx -y unsplash-mcp-server
注意:这需要在npm上以指定的名称发布包。
与Cline一起跑步
-
配置MCP设置: 在Cline MCP设置文件中添加或更新配置(例如。,
.roo/mcp.json或全局设置)。您有两个主要选择:选项A:使用Bun/Node(直接路径-建议用于本地开发)
此方法使用
bun(或node)直接从本地项目目录运行编译后的脚本。{ "mcpServers": { "unsplash-mcp-server": { "command": "bun", // Or "node" "args": [ // Use the absolute path to the compiled index.js in your project "/path/to/your/upsplash-mcp-server/build/index.js" ], "env": { // Required: Ensure this matches your .env or is set here "UNSPLASH_ACCESS_KEY": "YOUR_UNSPLASH_ACCESS_KEY" // Replace with your actual key }, "disabled": false, "alwaysAllow": [ "search_photos", "download_photo" // "trigger_download" // Include if this tool exists and is separate ], "timeout": 3600 // Optional: Timeout in seconds (e.g., 1 hour) } // Add other servers here... } }- 重要提示: 替换
/path/to/your/upsplash-mcp-server/build/index.js在您的系统上使用正确的绝对路径。 - 替换
"YOUR_UNSPLASH_ACCESS_KEY"用你真正的钥匙。从实际JSON文件中删除注释。
选项B:使用NPX(需要将包发布到npm)
此方法使用
npx从npm注册表自动下载并运行服务器包。如果您不想在本地克隆存储库或更喜欢使用已发布的版本,这很方便。{ "mcpServers": { "unsplash-mcp-server": { "command": "npx", "args": [ "-y", // Auto-confirm installation "unsplash-mcp-server" // Assumed npm package name - update if different ], "env": { // Required: Ensure this is set here or in your environment "UNSPLASH_ACCESS_KEY": "YOUR_UNSPLASH_ACCESS_KEY" // Replace with your actual key }, "disabled": false, "alwaysAllow": [ "search_photos", "download_photo" ], "timeout": 3600 // Optional: Timeout in seconds } // Add other servers here... } }- 确保
env块包含必要的UNSPLASH_ACCESS_KEY. - 更新
"unsplash-mcp-server"在……里面args如果发布的npm包名称不同。
- 重要提示: 替换
-
重新启动/重新加载Cline: Cline应该检测到配置更改,并根据您选择的方法启动服务器。
-
使用工具: 您现在可以使用
search_photos和download_photo通过Cline提供的工具。
发展
- 观看模式:
bun run watch(通常启动服务器,并在文件更改时重新启动) - Linting:
bun run lint(检查代码的样式和潜在错误) - 格式:
bun run format(根据项目标准格式化代码)
(注:假设标准 package.json 脚本如 watch, lint, format。如果您的脚本不同,请更新。)
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
