图像取证MCP服务器
用于图像元数据提取和取证分析的轻量级MCP服务器。提供用于提取EXIF数据、计算加密和感知哈希以及比较图像以进行重复数据删除的工具。
特性
- 图片事实 -提取基本图像信息(格式、尺寸、颜色模式、文件大小)
- EXIF提取 -解析EXIF元数据,包括相机信息、日期和GPS坐标
- 哈希计算 -生成SHA-256和感知哈希(pHash)用于图像指纹识别
- 图像对比 -使用基于哈希的相似性分析比较两幅图像
工具
image_facts(url: str)
从URL获取基本图像事实。
参数:
url(字符串,必填):要分析的图像的URL
退货:
{
"ok": true,
"data": {
"format": "JPEG",
"width": 1920,
"height": 1080,
"mode": "RGB",
"file_size_bytes": 245678
},
"meta": {
"source": "https://example.com/image.jpg",
"retrieved_at": "2024-01-15T12:00:00Z",
"pagination": {"next_cursor": null},
"warnings": []
}
}extract_exif(url: str)
从图像中提取EXIF元数据。
参数:
url(字符串,必填):要分析的图像的URL
退货:
{
"ok": true,
"data": {
"camera_make": "Canon",
"camera_model": "EOS R5",
"datetime_original": "2024:01:15 10:30:00",
"iso": 100,
"f_number": 2.8,
"exposure_time": 0.004,
"focal_length": 50.0,
"gps": {
"latitude": 37.7749,
"longitude": -122.4194,
"altitude_meters": 10.5
}
},
"meta": {
"source": "https://example.com/photo.jpg",
"retrieved_at": "2024-01-15T12:00:00Z",
"pagination": {"next_cursor": null},
"warnings": []
}
}image_hashes(url: str)
计算图像的加密和感知哈希。
参数:
url(字符串,必填):要分析的图像的URL
退货:
{
"ok": true,
"data": {
"sha256": "a1b2c3d4e5f6...",
"phash": "d4c3b2a19080..."
},
"meta": {
"source": "https://example.com/image.jpg",
"retrieved_at": "2024-01-15T12:00:00Z",
"pagination": {"next_cursor": null},
"warnings": []
}
}compare_images(url_a: str, url_b: str)
使用基于哈希的方法比较两个图像。
参数:
url_a(string,必填):第一张图片的URLurl_b(string,必填):第二张图片的URL
退货:
{
"ok": true,
"data": {
"exact_match": false,
"perceptual_similarity": 87.5,
"hamming_distance": 8,
"sha256_a": "a1b2c3d4...",
"sha256_b": "e5f6g7h8...",
"phash_a": "d4c3b2a1...",
"phash_b": "d4c3b2a9..."
},
"meta": {
"source": "https://example.com/a.jpg vs https://example.com/b.jpg",
"retrieved_at": "2024-01-15T12:00:00Z",
"pagination": {"next_cursor": null},
"warnings": []
}
}安装
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .用法
启动服务器
# Run with uv
uv run python src/main.py
# Or directly with Python
python src/main.py默认情况下,服务器将在端口8080上启动。
配置
配置是通过环境变量完成的。复制 .env.example 到 .env 并自定义:
# Server port (default: 8080)
PORT=8080
# Maximum image size in bytes (default: 10MB)
MAX_IMAGE_BYTES=10485760
# Request timeout in seconds (default: 30)
REQUEST_TIMEOUT=30错误处理
所有工具在失败时都会返回一个标准化的错误信封:
{
"ok": false,
"error": {
"code": "INVALID_INPUT",
"message": "URL must start with http:// or https://",
"details": {
"field": "url",
"value": "invalid-url"
}
},
"meta": {
"retrieved_at": "2024-01-15T12:00:00Z"
}
}错误代码:
INVALID_INPUT-参数无效或图像格式不受支持UPSTREAM_ERROR-获取图像时发生HTTP错误RATE_LIMITED-速率受映像主机限制TIMEOUT-请求超时PARSE_ERROR-解析图像数据失败INTERNAL_ERROR-意外的服务器错误
局限性
- 最大文件大小:默认10MB(可配置)
- 请求超时:默认为30秒(可配置)
- 支持的格式:Pillow支持的所有格式(JPEG、PNG、GIF、WebP、BMP、TIFF等)
- EXIF支持:通常只有JPEG和TIFF图像包含EXIF数据
- 没有OpenCV:仅在轻量化操作中使用枕头
- 感知哈希:使用具有64位输出的pHash算法
测试
# Run all tests
uv run pytest
# Run with verbose output
uv run pytest -v
# Run specific test file
uv run pytest tests/test_tools.py发展
项目结构
image-forensics/
├── src/
│ ├── __init__.py
│ ├── main.py # Entry point
│ ├── server.py # MCP server configuration
│ ├── tools/
│ │ ├── __init__.py
│ │ ├── facts.py # image_facts tool
│ │ ├── exif.py # extract_exif tool
│ │ ├── hashes.py # image_hashes tool
│ │ └── compare.py # compare_images tool
│ └── utils.py # Shared utilities
├── tests/
│ ├── __init__.py
│ ├── test_tools.py # Unit tests
│ └── test_server.py # E2E tests
├── pyproject.toml
├── .env.example
├── .gitignore
├── .python-version
└── README.md许可证
麻省理工学院
