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.
- 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
- Python 3.12
- UV package and project manager
- Reality Defender API Key
- Clone the repository:
git clone https://github.com/Reality-Defender/eng-mcp-server.git- Install dependencies:
uv sync- Set up environment variables:
export REALITY_DEFENDER_API_KEY="your-api-key-here"To run the MCP server:
uv run ./src/realitydefender_mcp_server/mcp_server.pyThe server will start with the web server component for file uploads on localhost:8080.
To run just the web server component:
uv run ./src/realitydefender_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)
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"
}
}
}
}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 |
The server provides the following MCP tools:
Generates a unique upload URL for user file uploads.
Returns: GenerateUploadUrlOutput | Error
Retrieves metadata about an uploaded or downloaded file.
Parameters:
file_id(string): The file ID to retrieve metadata for
Returns: GetFileInfoOutput | Error
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
- Generate upload URL using
reality_defender_generate_upload_url - Direct user to upload file at the provided URL
- Get file info using
reality_defender_get_file_infowith the UUID - Analyze file using
reality_defender_request_file_analysis - Present results to user
- Analyze file directly using
reality_defender_request_file_analysiswith URL - Get additional file info using
reality_defender_get_file_infoif needed - Present results to user
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)
- Type Hints: Always use type hints for all functions and parameters
- Modern Python: Use Python 3.12 features and syntax (
str | Noneinstead ofOptional[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
# Type checking
basedpyright
# Linting and formatting
ruff check .
ruff format .pytestGET /- Service informationGET /health- Health checkGET /upload/{uuid}- Upload form for specified UUIDPOST /upload/{uuid}- File upload endpointGET /docs- OpenAPI documentation
{
"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
}- API Key Errors: Verify your
REALITY_DEFENDER_API_KEYis valid - File Upload Issues: Check upload directory permissions and disk space
- Network Errors: Verify internet connectivity for URL downloads
- Port Conflicts: Use
--portoption to specify different port - Large Files: Files are limited to 1MB via web interface