关于 Unsplash MCP Server
Unsplash MCP Server 通过 MCP 工具提供 Unsplash 照片搜索与下载,适用于需要按查询获取照片或将指定分辨率图片保存到本地的 MCP 客户端。
主要功能
- 01按查询搜索照片
- 02分页并按方向筛选
- 03以四种分辨率下载
- 04将文件保存到工作区的 `unsplash/` 目录
- 05需要 Unsplash Access Key
适用场景
- 01查找符合搜索词的照片
- 02按页码或方向筛选结果
- 03以指定分辨率下载选中的照片
MCP 相关
它向 MCP 客户端提供 `search_photos` 和 `download_photo` 工具。照片搜索支持查询、分页和方向筛选,下载文件会保存到工作区。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Unsplash MCP 服务
本项目实现了一个模型上下文协议(MCP)服务,提供与 Unsplash API 交互的工具,允许用户搜索和下载照片。
(注意:如有需要,请将
@shariqriazz 替换为正确的用户名/命名空间。)
Git 仓库: https://github.com/shariqriazz/upsplash-mcp-server (如果此 URL 不正确,请更新。)
功能
- 提供用于与 Unsplash API 交互的 MCP 工具。
- 根据搜索词、分页和方向搜索照片。
- 以指定分辨率(raw、full、regular、small)下载照片。
- 需要通过环境变量配置 Unsplash Access Key。
- 将照片下载到工作区中的本地
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 Access Key(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 Access Key:
UNSPLASH_ACCESS_KEY="YOUR_UNSPLASH_ACCESS_KEY"
- 在项目根目录中创建
- 构建服务:
此操作会将 TypeScript 代码编译到bun run buildbuild/index.js。
用法(独立运行 / NPX)
独立运行(本地构建):
你可以使用 bun 或 node 直接运行编译后的服务。请确保已在 shell 或 .env 文件中设置 UNSPLASH_ACCESS_KEY 环境变量。
# Ensure UNSPLASH_ACCESS_KEY is set
bun run build/index.js
# OR
node build/index.js
使用 NPX(如果已发布到 npm):
如果此软件包已发布到 npm(例如,名为 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。 - 如果已发布的 npm 软件包名称不同,请更新
args中的"unsplash-mcp-server"。
- 重要: 将
-
重启/重新加载 Cline: Cline 应会检测到配置变更,并根据你选择的方法启动服务。
-
使用工具: 现在,你可以通过 Cline 使用
search_photos和download_photo工具。
开发
- 监视模式:
bun run watch(通常会启动服务,并在文件变更时重新启动) - Lint:
bun run lint(检查代码风格和潜在错误) - 格式化:
bun run format(根据项目规范格式化代码)
(注意:此处假设 package.json 中包含 watch、lint、format 等标准脚本。如果你的脚本有所不同,请相应更新。)
许可证
本项目根据 MIT 许可证授权,详情请参阅 LICENSE 文件。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。