使用说明
Unsplash MCP服务器
一种模型上下文协议(MCP)服务器,能够从Unsplash获取和下载图像。此服务器与OpenCode集成,提供搜索、检索和保存Unsplash照片的工具。
特性
- 🔍 搜索照片:使用方向、颜色和顺序过滤器通过查询搜索Unsplash
- 🔗 获取照片URL:从照片ID获取直接图像URL(建议下载)
- 📥 下载照片:将图像下载到指定目录,并可选择调整大小
- 🎲 随机照片:使用可选滤镜从Unsplash获取随机照片
- 📐 列出照片尺寸:获取任何照片的可用图像大小和URL
设置
安装依赖项
cd unsplash-mcp
pip install -r requirements.txt
设置Unsplash API密钥
- 首选 Unsplash开发者
- 注册或登录
- 创建新应用程序
- 复制您的 访问密钥
添加到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
工作流示例
简单 (推荐):
search_photos(query="cats")→ Getimage_url根据结果download_photo(photo_url="...", directory="./images")
高级 (自定义尺寸):
search_photos(query="sunset")get_photo_download_url(photo_id="xxx", size="raw")→ Getrecommended_urldownload_photo(photo_url="...", directory="./images", width=1920, height=1080)