Unsplash图片搜索服务

Unsplash MCP Server是一个用于搜索Unsplash高质量图片库的工具,支持关键词、颜色、方向和分页过滤。

  • by petems
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 petems/unsplash-mcp-server

使用说明

Unsplash MCP服务器

一个用于搜索Unsplash图像的简单MCP服务器。

叉子 hellokaton/unsplash mcp服务器.

概述

Unsplash MCP Server提供了搜索Unsplash高质量图像库的工具。它支持按关键字、颜色、方向和分页进行过滤。

获取Unsplash访问密钥

  1. 在以下网址创建开发人员帐户 Unsplash
  2. 注册新应用程序
  3. 从应用程序详细信息页面获取访问密钥

有关更多详细信息,请参阅 Unsplash API官方文档.

安装

克劳德代码

将以下内容添加到您的 ~/.claude.json (用户范围)或 .mcp.json 在项目根目录(项目范围)中:

{
  "mcpServers": {
    "unsplash": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/petems/unsplash-mcp-server", "unsplash-mcp-server"],
      "env": {
        "UNSPLASH_ACCESS_KEY": "your_access_key"
      }
    }
  }
}

手动安装

git clone https://github.com/petems/unsplash-mcp-server.git
cd unsplash-mcp-server
uv venv
uv pip install .

可用工具

搜索照片

使用可选滤镜搜索Unsplash的照片库。

{
  "tool": "search_photos",
  "query": "mountain",
  "per_page": 5,
  "orientation": "landscape"
}

download_photo

按ID下载Unsplash照片并将其保存到本地文件。此工具从Unsplash的CDN获取图像并将其直接写入磁盘。

{
  "tool": "download_photo",
  "photo_id": "abc123",
  "save_path": "/absolute/path/to/image.jpg",
  "size": "regular"
}

参数:

  • photo_id (必填):Unsplash带照片的身份证(从 search_photos 结果)
  • save_path (必填):保存图像的绝对文件路径。如果此路径上已存在文件,将引发错误以防止意外覆盖。
  • size (可选):图像大小变量-- raw, full, regular (默认), small,或 thumb
    • raw:原始未处理图像(最大文件大小)
    • full:全尺寸处理图像(高质量)
    • regular:标准网页尺寸(~1080px宽度,建议用于大多数用途)
    • small:较小的预览(~400px宽度)
    • thumb:缩略图(~200px宽)
  • create_directories (可选):如果 true,如果父目录不存在,则自动创建父目录。默认为 false 为了安全。

退货: 一个结构化的结果,包含照片ID、最终保存路径、大小变量、字节数和一个现成的Markdown归因行。

示例响应:

{
  "photo_id": "abc123",
  "path": "/home/user/images/mountain_unsplash-abc123.jpg",
  "size": "regular",
  "byte_count": 245891,
  "attribution": "\"[A mountain landscape](https://unsplash.com/photos/abc123?utm_source=unsplash_mcp&utm_medium=referral)\" by [Jane Smith](https://unsplash.com/@janesmith?utm_source=unsplash_mcp&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=unsplash_mcp&utm_medium=referral)"
}

重要提示:

  • 该工具会根据需要自动触发Unsplash的下载跟踪端点 取消屏蔽API指南
  • 默认情况下,父目录必须存在;集 create_directories=true 自动创建它们
  • 该工具对常规下载使用60秒超时,对 raw 和 full 大小以容纳较大的文件
  • 该工具不会覆盖现有文件。如果指定路径上已存在文件,将引发错误,要求您选择其他路径或先删除现有文件
  • 下载的图像应按照 Unsplash许可证

获取照片分配

根据Unsplash API指南,返回Unsplash照片的正确格式归因。包括结构化数据(JSON)和现成的Markdown字符串。

{
  "tool": "get_photo_attribution",
  "photo_id": "abc123",
  "image_size": "regular"
}

参数:

  • photo_id (必填):Unsplash照片的唯一标识符
  • image_size (可选):要使用的图像URL的大小-- raw, full, regular (默认), small,或 thumb

示例响应:

{
  "photo_id": "abc123",
  "description": "A mountain landscape at sunset",
  "alt_description": "snow-capped mountains under orange sky",
  "photo_url": "https://unsplash.com/photos/abc123?utm_source=unsplash_mcp&utm_medium=referral",
  "image_url": "https://images.unsplash.com/photo-abc123?w=1080",
  "photographer_name": "Jane Smith",
  "photographer_url": "https://unsplash.com/@janesmith?utm_source=unsplash_mcp&utm_medium=referral",
  "attribution_markdown": "\"[A mountain landscape at sunset](https://unsplash.com/photos/abc123?utm_source=unsplash_mcp&utm_medium=referral)\" by [Jane Smith](https://unsplash.com/@janesmith?utm_source=unsplash_mcp&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=unsplash_mcp&utm_medium=referral)"
}

这 attribution_markdown 字段呈现为:

"[A mountain landscape at sunset](https://unsplash.com/photos/abc123?utm_source=unsplash_mcp&utm_medium=referral)" by [Jane Smith](https://unsplash.com/@janesmith?utm_source=unsplash_mcp&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=unsplash_mcp&utm_medium=referral)

相同 attribution 字段作为每个字段的一部分返回 search_photos 结果和 download_photo 回应。

许可证

MIT许可证