Reality Defender MCP Server

Reality Defender MCP Server

Enables LLMs to analyze images, videos, audio, and text files for AI-generated content using the Reality Defender API, with support for user file uploads and direct URL analysis.

Category
访问服务器

README

Reality Defender MCP Server

A Model Context Protocol (MCP) server that provides AI-generated media detection capabilities using the Reality Defender API. This server enables LLMs to analyze images, videos, audio, and text files to determine if they were generated by AI.

Features

  • AI Media Detection: Analyze files for AI generation using Reality Defender's advanced detection models
  • Multiple Input Methods: Support for both direct URL downloads and user file uploads
  • Comprehensive File Support: Images, videos, audio, and text files
  • Web Upload Interface: Built-in FastAPI web server for secure file uploads
  • Error Handling: Robust error handling with user-friendly messages
  • Async Operations: Modern async/await patterns for optimal performance

Getting Started

Prerequisites

  • Python 3.12
  • UV package and project manager
  • Reality Defender API Key

Installation

  1. Clone the repository:
git clone https://github.com/Reality-Defender/eng-mcp-server.git
  1. Install dependencies:
uv sync
  1. Set up environment variables:
export REALITY_DEFENDER_API_KEY="your-api-key-here"

Running the Server

MCP Server Mode

To run the MCP server:

uv run ./src/reality_defender_mcp_server/mcp_server.py

By default, the server also starts a small web server for file uploads. You can disable uploads entirely by setting UPLOADS=false.

To run MCP over Streamable HTTP (cloud-friendly):

FASTMCP_HOST=0.0.0.0 FASTMCP_PORT=8000 uv run ./src/reality_defender_mcp_server/mcp_server.py --transport streamable-http

By default, the Streamable HTTP MCP endpoint is served at /mcp.

Standalone Web Server

To run just the web server component:

uv run ./src/reality_defender_mcp_server/web_server.py [options]

Web server options:

  • --debug: Enable debug logging
  • --host: Server host (default: 127.0.0.1)
  • --port: Server port (default: 8080)
  • --upload-dir: Upload directory (default: ./uploads)

MCP Client Configuration

Configure the server in your MCP client, e.g. for Claude Desktop:

{
  "mcpServers": {
    "realitydefender": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/eng-reality-defender-mcp-server",
        "run",
        "python",
        "mcp_server.py"
      ],
      "env": {
        "REALITY_DEFENDER_API_KEY": "your-api-key-here"
      }
    }
  }
}

Configuration

The application uses environment variables for configuration:

Variable Description Required Default
REALITY_DEFENDER_API_KEY API key for Reality Defender service Yes -
DEBUG Enable debug mode No false
WEB_SERVER_HOST Host for the web server No 127.0.0.1
WEB_SERVER_PORT Port for the web server No 8080
WEB_SERVER_UPLOADS_DIR Directory for file uploads No ./uploads
UPLOADS Enable local file upload workflow; set to false to disable uploads and only allow remote URLs No true

API Key Authentication

  • By default, the server uses REALITY_DEFENDER_API_KEY from environment variables.
  • For cloud deployments, clients can pass a request-scoped Reality Defender key using the X-Api-Key HTTP header.
  • If X-Api-Key is present, it is used for that request and takes precedence over REALITY_DEFENDER_API_KEY.
  • For security, prefer headers over URL query parameters for API keys.

MCP Tools

The server provides the following MCP tools:

reality_defender_generate_upload_url

Generates a unique upload URL for user file uploads.

Returns: GenerateUploadUrlOutput | Error

reality_defender_get_file_info

Retrieves metadata about an uploaded or downloaded file.

Parameters:

  • file_id (string): The file ID to retrieve metadata for

Returns: GetFileInfoOutput | Error

reality_defender_request_file_analysis

Analyzes a file for AI generation using Reality Defender API.

Parameters:

  • request (RealityDefenderAnalysisRequest): Analysis request with file path/URL and expected file type

Returns: RealityDefenderAnalysisResponse | Error

Streamable HTTP Deployment

  • Use --transport streamable-http to expose MCP over HTTP for cloud deployments.
  • Configure bind host/port with FASTMCP_HOST and FASTMCP_PORT.
  • Default MCP path is /mcp (configurable via FastMCP settings environment variables).
  • Continue using X-Api-Key to pass request-scoped Reality Defender credentials.

Container Publishing

  • On pushes to main, GitHub Actions builds the Docker image from Dockerfile.
  • The image is published to GitHub Container Registry as ghcr.io/<owner>/eng-mcp-server.
  • Published tags include latest, main, and sha-<commit>.

Usage Workflows

User Upload Workflow (Recommended)

  1. Generate upload URL using reality_defender_generate_upload_url
  2. Direct user to upload file at the provided URL
  3. Get file info using reality_defender_get_file_info with the UUID
  4. Analyze file using reality_defender_request_file_analysis
  5. Present results to user

Direct URL Workflow

  1. Analyze file directly using reality_defender_request_file_analysis with URL
  2. Get additional file info using reality_defender_get_file_info if needed
  3. Present results to user

File Structure

Uploaded and downloaded files are organized as:

uploads/
└── {uuid}/
    ├── blob.{ext}     # Raw file data with proper extension
    └── metadata.json  # File metadata (filename, size, timestamp, MIME type, source)

Development

Code Standards

  • Type Hints: Always use type hints for all functions and parameters
  • Modern Python: Use Python 3.12 features and syntax (str | None instead of Optional[str])
  • Async First: Prefer async/await patterns where possible
  • Error Handling: Return union types (SuccessType | Error) instead of raising exceptions
  • Pydantic Models: Use Pydantic for all structured data validation

Linting and Type Checking

# Type checking
basedpyright

# Linting and formatting
ruff check .
ruff format .

Running Tests

pytest

API Reference

Web Server Endpoints

  • GET / - Service information
  • GET /health - Health check
  • GET /upload/{uuid} - Upload form for specified UUID
  • POST /upload/{uuid} - File upload endpoint
  • GET /docs - OpenAPI documentation

Note: If UPLOADS=false, the upload web server is not started and only direct URL analysis is supported. The tools and responses will not suggest uploading files when uploads are disabled.

Response Types

RealityDefenderAnalysisResponse

{
    "status": "ARTIFICIAL" | "AUTHENTIC" | "ANALYZING",
    "score": float,  # Confidence score (0-100)
    "models": [      # Individual model results
        {
            "name": str,
            "status": str,
            "score": float | None
        }
    ],
    "file_id": str | None  # For downloaded files
}

Troubleshooting

  • API Key Errors: Verify your REALITY_DEFENDER_API_KEY is valid
  • File Upload Issues: Check upload directory permissions and disk space
  • Network Errors: Verify internet connectivity for URL downloads
  • Port Conflicts: Use --port option to specify different port
  • Large Files: Files are limited to 1MB via web interface

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选