Integrations
Unsplash API - FastAPI + FastMCP
目录
概述
该项目提供了访问 Unsplash 服务的 API,允许您搜索、列出和获取随机图像。此外,它集成了模型上下文协议 (MCP),使 Claude 等 AI 模型能够直接与 Unsplash API 交互。
先决条件
在使用 Unsplash API 之前,您需要:
- 在 Unsplash 上注册为开发者
- 获取您的访问密钥
- 在
.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
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
一个将 Unsplash 图像搜索、列表和随机照片功能作为 MCP 工具公开的 API,使 Claude 等 AI 模型能够直接与 Unsplash 的服务进行交互。
Related MCP Servers
- AsecurityAlicenseAqualityEnables AI assistants to download images from URLs and perform basic image optimization tasks.Last updated -24JavaScriptApache 2.0
- AsecurityAlicenseAqualityEnables the generation of images using Together AI's models through an MCP server, supporting customizable parameters such as model selection, image dimensions, and output directory.Last updated -14JavaScriptMIT License
- -securityAlicense-qualityA FastMCP server implementation that provides a standardized interface for accessing AI models hosted on Replicate's API, currently supporting image generation with customizable parameters.Last updated -2PythonMIT License
- 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 -1112PythonMIT License