Unsplash API - FastAPI + FastMCP
目录
概述
该项目提供了访问 Unsplash 服务的 API,允许您搜索、列出和获取随机图像。此外,它集成了模型上下文协议 (MCP),使 Claude 等 AI 模型能够直接与 Unsplash API 交互。
先决条件
在使用 Unsplash API 之前,您需要:
获取您的访问密钥
在
.env文件中将密钥配置为UNSPLASH_CLIENT_ID
安装
使用 pip
使用 Docker
配置
在项目根目录中创建一个.env文件,其内容如下:
跑步
本地
API 将在http://localhost:8000上可用。
使用 Docker
API 将在http://localhost:8000上可用。
访问http://localhost:8000/docs上的交互式 API 文档。
API 端点
搜索
在 Unsplash 上搜索图像的端点。
端点: /search
方法: GET
参数:
query:搜索词(默认值:“nature”)page:页码(默认值:1)per_page:每页照片数量(默认值:10)order_by:照片排序(默认值:“relevant”,选项:“relevant”、“latest”)
请求示例:
响应示例:
照片
用于列出来自 Unsplash 登录页面的照片的端点。
端点: /photos
方法: GET
参数:
page:页码(默认值:1)per_page:每页照片数量(默认值:10)order_by:照片排序(默认值:“最新”,选项:“最新”、“最旧”、“热门”)
请求示例:
响应示例:
随机的
从 Unsplash 获取随机照片的端点。
端点: /random
方法: GET
参数:
query:用于过滤随机照片的搜索词(默认值:“自然”)count:返回的照片数量(默认值:1,最大值:30)
请求示例:
响应示例:
有关 Unsplash API 的更多信息,请参阅官方文档。
MCP 集成
MCP 概述
模型上下文协议 (MCP) 是一种允许 AI 模型直接与 API 和服务交互的协议。此实现使用FastAPI-MCP将 Unsplash API 端点公开为 MCP 工具。
MCP 端点
MCP 服务器位于/mcp ,并将所有 API 端点公开为 MCP 工具:
搜索:在 Unsplash 上搜索图片
照片:列出着陆页上的照片
random :获取随机照片
与 AI 模型一起使用
支持 MCP 的 AI 模型可以使用以下方式连接到此 API:
对于 Claude,您可以在模型设置中或通过 API 配置连接。
示例客户端
您可以使用简单的 Python 客户端测试 MCP 服务器:
有关使用 MCP 的更多信息,请参阅MCP_USAGE.md文件。
发展
为发展做出贡献:
克隆存储库
安装开发依赖项:
pip install -r requirements.txt使用你的 Unsplash API 密钥创建一个
.env文件以开发模式运行服务器:
python main.py
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。
This server cannot be installed
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityA lightweight server that enables seamless integration with Unsplash's image library, allowing developers to search for high-quality photos with various filters directly from the Cursor editor.Last updated -1187MIT License
- -securityAlicense-qualityAn MCP server that allows Claude and other AI assistants to interact with the YouTube API, providing tools to search videos/channels and retrieve detailed information about them.Last updated -51MIT License
- -securityAlicense-qualityA search service based on multiple image APIs and icon generation capabilities, specifically designed for integration with Cursor MCP service. Supports image search, download, and AI-generated icons.Last updated -13MIT License
- -securityFlicense-qualityAn MCP server that crawls API documentation websites and exposes their content to AI models, enabling them to search, browse, and reference API specifications.Last updated -