图片获取服务器

一个从Unsplash获取和下载图片的模型上下文协议(MCP)服务器,集成到OpenCode中,提供搜索、检索和保存Unsplash照片的工具。

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

使用说明

Unsplash MCP服务器

一种模型上下文协议(MCP)服务器,能够从Unsplash获取和下载图像。此服务器与OpenCode集成,提供搜索、检索和保存Unsplash照片的工具。

特性

  • 🔍 搜索照片:使用方向、颜色和顺序过滤器通过查询搜索Unsplash
  • 🔗 获取照片URL:从照片ID获取直接图像URL(建议下载)
  • 📥 下载照片:将图像下载到指定目录,并可选择调整大小
  • 🎲 随机照片:使用可选滤镜从Unsplash获取随机照片
  • 📐 列出照片尺寸:获取任何照片的可用图像大小和URL

设置

安装依赖项

cd unsplash-mcp
pip install -r requirements.txt

设置Unsplash API密钥

  1. 首选 Unsplash开发者
  2. 注册或登录
  3. 创建新应用程序
  4. 复制您的 访问密钥

添加到OpenCode配置(opencode.json)

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "unsplash-mcp": {
      "type": "local",
      "command": ["python", "/absolute/path/to/server.py"],
      "enabled": true,
      "environment": {
        "UNSPLASH_ACCESS_KEY": "your_key_here"
      }
    }
  }
}

用法

搜索照片

搜索照片。每个结果包括 image_url (直接图像URL)。

Search for "nature" photos, per_page=10, orientation="landscape"

退货:

{
  "results": [
    {
      "id": "photo_123",
      "description": "A beautiful mountain",
      "image_url": "https://images.unsplash.com/photo-xxx...",
      "photographer": {"name": "John Doe"}
    }
  ]
}

download_photo

将图像下载到 directory.使用 image_url 从搜索结果中。

Download image to ./`directory` with width=1920, quality=90

工作流示例

简单 (推荐):

  1. search_photos(query="cats") → Get image_url 根据结果
  2. download_photo(photo_url="...", directory="./images")

高级 (自定义尺寸):

  1. search_photos(query="sunset")
  2. get_photo_download_url(photo_id="xxx", size="raw") → Get recommended_url
  3. download_photo(photo_url="...", directory="./images", width=1920, height=1080)

链接