Visual Document Forensics MCP Server

Visual Document Forensics MCP Server

Enables deterministic visual and structural analysis of PDF and DOCX documents, extracting measurable evidence such as blur, OCR confidence, and image anomalies for auditable forensic workflows.

Category
访问服务器

README

Visual Document Forensics MCP Server

A production-ready Python MCP server that performs deterministic visual and structural analysis of PDF and DOCX documents.

It is designed to be called by a UiPath agent. The agent does the reasoning and decision-making; this server does only one thing: extract measurable visual evidence that UiPath Analyze File cannot reliably provide.

The server never determines fraud. It reports metrics and measurable anomalies (blur, OCR confidence, effective DPI, image stretch, font usage, structural inconsistencies) and leaves all interpretation to the agent.

Guarantees

All processing is local and deterministic. The server does not use:

  • LLMs or VLMs
  • External APIs or API keys
  • Embeddings, vector databases, or retrieval systems
  • Any cloud service or network access

The only optional external component is the local Tesseract OCR binary. If it is absent, the server degrades gracefully (OCR metrics are skipped and a warning is emitted) — it never fails because of it.


Architecture

Document
    ↓
MCP Tool Call            src/server/app.py        (FastMCP, stdio transport)
    ↓
Document Loader          src/render/loader.py     (detect PDF/DOCX, open handles)
    ↓
Page Renderer            src/render/pdf_renderer.py (PyMuPDF, configurable DPI)
    ↓
Tile Generator           src/tiling/tiler.py      (overlapping tiles)
    ↓
Visual Analysis Engine   src/analyzers/*          (blur, sharpness, contrast,
    ↓                                              entropy, edge density, noise,
    ↓                                              OCR confidence, text density)
PDF Structure Engine     src/analyzers/pdf_structure.py (images, scaling, DPI,
    ↓                                              fonts, objects; pikepdf check)
Evidence Aggregator      src/tools/analyze.py     (detectors + rollup)
    ↓
JSON Response            src/schemas/models.py    (pydantic-validated contract)
    ↓
UiPath Agent

Project layout

visual-forensics-mcp/
├── src/
│   ├── server/      # FastMCP server (analyze_document tool)
│   ├── tools/       # analysis orchestrator (the pipeline)
│   ├── render/      # document loader + PDF/DOCX rendering
│   ├── tiling/      # overlapping tile generation
│   ├── analyzers/   # deterministic metric computation
│   ├── detectors/   # anomaly detection from metrics
│   ├── schemas/     # pydantic output contract
│   └── utils/       # config, logging, geometry, image ops
├── tests/           # pytest suite (unit + end-to-end)
├── configs/         # default.yaml (all thresholds live here)
├── examples/        # sample docs + example request/response
├── requirements.txt
├── pyproject.toml
└── README.md

Analyzer & detector modules

Analyzers (src/analyzers/) Detectors (src/detectors/)
blur.py — Laplacian variance blur_detector.py — blur anomaly
sharpness.py — Tenengrad / gradient dpi_detector.py — resolution anomaly
contrast.py — RMS / Michelson font_detector.py — font mismatch
entropy.py — Shannon entropy stretch_detector.py — non-uniform scaling
edge_density.py — Canny edge ratio ocr_confidence_detector.py — low OCR confidence
noise.py — Immerkaer sigma / residual compression_detector.py — compression artifact
ocr.py — Tesseract confidence structure_detector.py — raster-in-vector / overlap
font_analysis.py — font families/sizes
image_scaling.py — scale/effective DPI
pdf_structure.py — images/objects/fonts

Installation

Requires Python 3.11+.

# 1. Create and activate a virtual environment (recommended)
python -m venv .venv
# Windows (PowerShell)
.venv\Scripts\Activate.ps1
# macOS / Linux
source .venv/bin/activate

# 2. Install dependencies
pip install -r requirements.txt

Tesseract OCR (optional but recommended)

OCR-based metrics (ocr_confidence) and the OCR-confidence detector require the Tesseract binary. The Python wheel (pytesseract) only wraps it.

  • Windows: install the UB Mannheim build, then either add it to PATH or set ocr.tesseract_cmd in configs/default.yaml (or via request options) to e.g. C:\\Program Files\\Tesseract-OCR\\tesseract.exe.
  • macOS: brew install tesseract
  • Debian/Ubuntu: sudo apt-get install tesseract-ocr

Without Tesseract, everything else still runs; the response simply includes a warning and summary.ocr_available = false.


Configuration

All tunables — including every threshold — live in configs/default.yaml. There are no hardcoded thresholds anywhere in the analysis or detection code.

Key settings:

render:
  dpi: 400                 # default render resolution
tiling:
  tile_size: 512
  tile_overlap: 0.20
features:
  enable_ocr: true
  enable_pdf_analysis: true

Three ways to configure, in increasing precedence:

  1. Edit configs/default.yaml.
  2. Point the server at another file via the VISUAL_FORENSICS_CONFIG environment variable.
  3. Pass an options dict per request (deep-merged over the file), e.g. {"render": {"dpi": 300}, "features": {"enable_ocr": false}}.

Running the MCP server

python -m src.server.app

This starts a FastMCP server on the stdio transport — the standard way MCP clients (including UiPath) launch and communicate with a local server.

A console script is also installed:

visual-forensics-mcp

MCP usage

The server exposes a single primary tool:

analyze_document(document_path: str, options: dict | None = None)

It returns a JSON object with this exact top-level shape:

{
  "document_id": "...",
  "document_type": "...",
  "summary": {},
  "page_results": [],
  "document_findings": [],
  "warnings": [],
  "errors": []
}

Every finding (in page_results[].findings and document_findings) has the required schema:

{
  "type": "...",
  "page": 0,
  "bbox": [0, 0, 0, 0],
  "metrics": {},
  "confidence": 0.0,
  "explanation": "..."
}

bbox values are in rendered pixel coordinates at the page's render DPI. Document-level findings (e.g. font_mismatch) use page: 0 and a zero bbox.

Finding types produced

Type Trigger (configurable)
blur_anomaly Tile sharpness far below the page distribution
ocr_confidence_anomaly Tile OCR confidence far below page average
resolution_anomaly Embedded image effective DPI far below render DPI
image_stretch Embedded image scaled non-uniformly (scale_x ≠ scale_y)
compression_artifact_anomaly Tile noise signature unlike its neighbours
font_mismatch Rare fonts / too many font families
raster_in_vector_anomaly Raster region inside an otherwise vector page
object_overlap_anomaly Strongly overlapping / stacked images

UiPath integration

UiPath agents can call MCP tools directly. Configure this server as a local stdio MCP server in your UiPath agent / MCP client configuration:

{
  "mcpServers": {
    "visual-forensics": {
      "command": "C:/path/to/visual-forensics-mcp/.venv/Scripts/python.exe",
      "args": ["-m", "src.server.app"],
      "cwd": "C:/path/to/visual-forensics-mcp",
      "env": {
        // optional: point at a custom config
        "VISUAL_FORENSICS_CONFIG": "C:/path/to/custom.yaml"
      }
    }
  }
}

Typical agent flow:

  1. UiPath downloads / locates the document and resolves a local file path.
  2. The agent calls analyze_document with that path (and optional options).
  3. The agent reads summary, page_results[].findings, and document_findings, and applies its own business rules / human-in-the-loop logic to decide what to do next.

Because the server is deterministic and offline, the same document always yields the same evidence — ideal for auditable, repeatable RPA workflows.

Example request

{
  "tool": "analyze_document",
  "arguments": {
    "document_path": "C:/docs/invoice.pdf",
    "options": { "render": { "dpi": 200 }, "features": { "enable_ocr": true } }
  }
}

Example response (abridged)

For the bundled examples/sample.pdf (a text page with a stretched, low-resolution raster insert and one rare-font line):

{
  "document_id": "5f34550e05450828",
  "document_type": "pdf",
  "summary": {
    "page_count": 1,
    "tile_count": 20,
    "finding_count": 4,
    "findings_by_type": {
      "resolution_anomaly": 1,
      "image_stretch": 1,
      "raster_in_vector_anomaly": 1,
      "font_mismatch": 1
    },
    "ocr_available": false,
    "pdf_structure_available": true
  },
  "page_results": [
    {
      "page": 1,
      "width": 1700,
      "height": 2200,
      "dpi": 200.0,
      "is_vector": true,
      "findings": [
        {
          "type": "image_stretch",
          "page": 1,
          "bbox": [888.89, 833.33, 1444.44, 1166.67],
          "metrics": { "scale_x": 5.0, "scale_y": 3.0, "stretch_ratio": 0.4, "xref": 32 },
          "confidence": 0.4,
          "explanation": "Embedded image is scaled non-uniformly (horizontal and vertical scale factors differ), distorting the image."
        }
      ]
    }
  ],
  "document_findings": [
    {
      "type": "font_mismatch",
      "page": 0,
      "bbox": [0, 0, 0, 0],
      "metrics": { "font": "Times-Roman", "span_count": 1, "share": 0.04 },
      "confidence": 0.6,
      "explanation": "A font family is used on only a small fraction of text spans, an unusual change versus the dominant fonts."
    }
  ],
  "warnings": ["Tesseract OCR binary not available; OCR metrics and the OCR-confidence detector are disabled for this run."],
  "errors": []
}

Regenerate the full sample with:

python -m examples.generate_examples

Testing

pytest -q

The suite covers PDF rendering, DOCX loading, tile generation, blur computation, OCR confidence extraction (graceful path), image-scaling detection, font extraction, schema validation, MCP invocation, and a complete end-to-end run for PDF, DOCX, and scanned/image-only PDF.


How metrics are computed (deterministic definitions)

  • Blur — variance of the Laplacian (lower ⇒ blurrier).
  • Sharpness — Tenengrad (mean squared Sobel gradient) and mean gradient.
  • Contrast — RMS (intensity std) and Michelson (max−min)/(max+min).
  • Entropy — Shannon entropy (bits) of the 256-bin intensity histogram.
  • Edge density — fraction of Canny edge pixels.
  • Noise — Immerkaer fast σ estimate and median-residual std.
  • OCR confidence — mean Tesseract word confidence, normalised to 0–1.
  • Text density — foreground fraction after adaptive binarisation.
  • Effective DPI — original_px × 72 / displayed_points per axis.
  • Scale / stretch — displayed_points / original_px per axis; stretch is |scale_x − scale_y| / max(scale_x, scale_y).

Anomalies are flagged using per-page z-scores and/or absolute floors, all read from configs/default.yaml. Confidence is a monotonic function of the measured deviation, not a probability of fraud.

推荐服务器

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

官方
精选