Unsplash API MCP Server

Unsplash API MCP Server

An API that exposes Unsplash image search, listing, and random photo capabilities as MCP tools, enabling AI models like Claude to directly interact with Unsplash's services.

Category
访问服务器

README

Unsplash API - FastAPI + FastMCP

<div align="center"> <img src="images/UNSPLASH-MCP.png" alt="Unsplash MCP"> </div>

Forked from unsplash-api by @aliosmankaya

Table of Contents

Overview

This project provides an API to access the Unsplash service, allowing you to search, list, and get random images. Additionally, it integrates the Model Context Protocol (MCP), enabling AI models like Claude to interact directly with the Unsplash API.

FastAPI-MCP FastAPI

Prerequisites

Before using the Unsplash API, you need to:

  1. Register as a developer on Unsplash
  2. Obtain your Access Key
  3. Configure the key as UNSPLASH_CLIENT_ID in the .env file

Installation

Using pip

# Clone the repository
git clone https://github.com/your-username/unsplash-api-mcp.git
cd unsplash-api-mcp

# Install dependencies
pip install -r requirements.txt

# Configure environment variables
cp .env.example .env
# Edit the .env file and add your UNSPLASH_CLIENT_ID

Using Docker

# Clone the repository
git clone https://github.com/your-username/unsplash-api-mcp.git
cd unsplash-api-mcp

# Configure environment variables
cp .env.example .env
# Edit the .env file and add your UNSPLASH_CLIENT_ID

# Build and start the container
docker compose up -d

Configuration

Create a .env file in the project root with the following content:

UNSPLASH_CLIENT_ID=your_access_key_here

Running

Locally

python main.py

The API will be available at http://localhost:8000.

With Docker

docker compose up -d

The API will be available at http://localhost:8000.

Access the interactive API documentation at http://localhost:8000/docs.

API Endpoints

<img src="images/main-page.png" alt="API Swagger UI">

Search

Endpoint to search for images on Unsplash.

Endpoint: /search

Method: GET

Parameters:

  • query: Search term (Default: "nature")
  • page: Page number (Default: 1)
  • per_page: Number of photos per page (Default: 10)
  • order_by: Photo ordering (Default: "relevant", Options: "relevant", "latest")

Request Example:

GET /search?query=mountains&page=1&per_page=5&order_by=latest

Response Example:

[
  {
    "alt_description": "mountain range under cloudy sky",
    "created_at": "2023-05-15T12:34:56Z",
    "username": "Photographer Name",
    "image_link": "https://images.unsplash.com/photo-...",
    "download_link": "https://unsplash.com/photos/...",
    "likes": 123
  },
  ...
]

Photos

Endpoint to list photos from the Unsplash landing page.

Endpoint: /photos

Method: GET

Parameters:

  • page: Page number (Default: 1)
  • per_page: Number of photos per page (Default: 10)
  • order_by: Photo ordering (Default: "latest", Options: "latest", "oldest", "popular")

Request Example:

GET /photos?page=1&per_page=5&order_by=popular

Response Example:

[
  {
    "alt_description": "scenic view of mountains during daytime",
    "created_at": "2023-06-20T10:15:30Z",
    "username": "Photographer Name",
    "image_link": "https://images.unsplash.com/photo-...",
    "download_link": "https://unsplash.com/photos/...",
    "likes": 456
  },
  ...
]

Random

Endpoint to get random photos from Unsplash.

Endpoint: /random

Method: GET

Parameters:

  • query: Search term to filter random photos (Default: "nature")
  • count: Number of photos to return (Default: 1, Maximum: 30)

Request Example:

GET /random?query=ocean&count=3

Response Example:

[
  {
    "alt_description": "blue ocean waves crashing on shore",
    "created_at": "2023-04-10T08:45:22Z",
    "username": "Photographer Name",
    "image_link": "https://images.unsplash.com/photo-...",
    "download_link": "https://unsplash.com/photos/...",
    "likes": 789
  },
  ...
]

For more information about the Unsplash API, see the official documentation.

MCP Integration

MCP Overview

The Model Context Protocol (MCP) is a protocol that allows AI models to interact directly with APIs and services. This implementation uses FastAPI-MCP to expose the Unsplash API endpoints as MCP tools.

MCP Endpoints

The MCP server is available at /mcp and exposes all API endpoints as MCP tools:

  • search: Search for images on Unsplash
  • photos: List photos from the landing page
  • random: Get random photos

Using with AI Models

AI models that support MCP can connect to this API using:

http://your-server:8000/mcp

For Claude, you can configure the connection in the model settings or via API.

Example Client

You can test the MCP server with a simple Python client:

import requests

def test_mcp_metadata():
    """Test if the MCP server is working correctly."""
    response = requests.get("http://localhost:8000/mcp/.well-known/mcp-metadata")
    if response.status_code == 200:
        print("MCP server working correctly!")
        print(f"Response: {response.json()}")
    else:
        print(f"Error: {response.text}")

def list_mcp_tools():
    """List the available tools in the MCP server."""
    response = requests.post(
        "http://localhost:8000/mcp/jsonrpc",
        json={
            "jsonrpc": "2.0",
            "id": 1,
            "method": "mcp/list_tools"
        }
    )
    if response.status_code == 200:
        print("Available MCP tools:")
        for tool in response.json()["result"]["tools"]:
            print(f"- {tool['name']}: {tool['description']}")
    else:
        print(f"Error: {response.text}")

if __name__ == "__main__":
    test_mcp_metadata()
    list_mcp_tools()

For more information about using MCP, see the MCP_USAGE.md file.

Development

To contribute to development:

  1. Clone the repository
  2. Install development dependencies: pip install -r requirements.txt
  3. Create a .env file with your Unsplash API key
  4. Run the server in development mode: python main.py

License

This project is licensed under the MIT License - see the LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选