pdf-reader-mcp

repository·main·Indexed 21 days ago

https://github.com/sylphxai/pdf-reader-mcp

Citra (pdf-reader-mcp) is a local-first PDF intelligence engine for AI agents that transforms PDFs into structured, citeable data including markdown, tables, OCR, and geometric evidence. It features a Model Context Protocol (MCP) server compatible with clients like Claude Desktop, Cursor, Windsurf, and VS Code. The system utilizes Semantic Contracts to ensure reliable data extraction and provides specialized agent workflows for smart reading, OCR scanning, and visual verification.

Tokens
81K
Snippets
188
Records
363
Agent score
71%

What's inside pdf-reader-mcp

  1. Overview of PDF Reader MCP capabilities

    main

    PDF Reader MCP is a Model Context Protocol (MCP) server designed to provide AI agents with high-fidelity access to PDF documents. Instead of providing simple text dumps, it provides structured evidence including page numbers, bounding boxes, table cells, and visual provenance to prevent hallucinations.

    Core Capabilities:

    • Structured Extraction: Converts PDFs into structured text, tables (with rows, cells, and geometry), and page-level citations.
    • Visual Evidence: Renders pages and crops specific regions for tables, figures, charts, and citations.
    • Search & Verify: Allows agents to find snippets with page context before performing deep reading or cropping.
    • OCR Support: Routes selected pages through configured OCR providers for scanned documents, keeping OCR text separate from selectable text.
    • Trust & Safety Signals: Surfaces risk signals such as hidden text, prompt injection, and overlapping content.
    • Native Performance: Uses a Rust-based engine across five platforms, launched via a thin Node.js wrapper.
  2. Overview of PDF Reader MCP

    main

    PDF Reader MCP is a local-first, public Model Context Protocol (MCP) package designed for PDF and document intelligence. It provides AI agents with typed tools for various document tasks including:

    • Inspection & Search: PDF inspection, search, and document maps.
    • Visual & Structural Analysis: Rendering, region crops, and accessibility reports.
    • Data Extraction: OCR routing, extraction, and provenance tracking.
    • Verification: Trust signals, benchmarks, and package release evidence.

    The project is designed to be provider-neutral, offering optional OCR/vision interfaces while keeping document processing local-first by default. It emphasizes preserving source, page, and region provenance so that downstream agents can cite and verify evidence.

  3. Overview of PDF Reader MCP tools

    main

    PDF Reader MCP (@sylphx/pdf-reader-mcp@4.1.1) is an evidence-first MCP server designed for AI agents to process PDFs. Instead of returning lossy text dumps, it provides an 'Agent Document Twin' containing markdown, tables, and source evidence.

    The server exposes three primary V3 tools:

    1. read_pdf: The smart default tool. When provided with sources, it profiles the PDF, selects an extraction route, and returns the Agent Document Twin.
    2. search_pdf: Searches extracted text and returns snippets, offsets, bounding-box provenance, and optional OCR-layer matches.
    3. pdf_evidence: Executes focused evidence operations, including inspect, render_page, extract_regions, ocr_pages, and analyze_regions.
  4. Overview of the PDF Reader MCP tool surface

    main

    The pdf-reader-mcp product provides a set of tools designed to give AI agents the ability to process and understand PDF documents. The tool surface is designed around a policy of providing a few, powerful, and obvious tools, prioritizing structured reading.

    Available Tools

    ToolRole
    read_pdfThe primary tool for structured PDF reading. It extracts text, tables, maps, and citations.
    render_pageUsed to provide visual evidence by rendering a specific page.
    ocr_pagesUsed to provide OCR (Optical Character Recognition) evidence for scanned or image-based pages.

    Interfaces

    • CLI: Use the citra or pdf-reader-mcp commands for human or script-based interaction.
    • SDK: Use the @sylphx/pdf-reader-mcp/sdk for programmatic integration into your own applications.
  5. Citra Available Surfaces

    main

    Citra can be consumed through three primary interfaces:

    1. SDK: Programmatic access via import { Citra } from '@sylphx/pdf-reader-mcp/sdk'.
    2. CLI: Command line access using citra or pdf-reader-mcp.
    3. MCP: Model Context Protocol (MCP) via stdio tools, providing page-level evidence to AI agents.
  6. What is the Agent Document Twin?

    main

    The Agent Document Twin is the core data structure returned by the PDF Reader MCP. Instead of a plain-text dump, it provides a high-fidelity, linked map of the document that includes:

    • Text & Structure: Text, tables, and layout diagnostics.
    • Visual Evidence: Crops, OCR, and page rendering metadata.
    • Citations & Provenance: Stable IDs and source references for retrieval workflows.
    • Metadata & Geometry: Page counts, document properties, and page geometry.
    • Signals: Trust reports (risk/redaction), accessibility reports (tag coverage/headings), and safety findings.

    This structure allows AI agents to understand not just what the text says, but how it is visually and structurally organized.

  7. Identify the Public Surfaces of PDF Reader MCP

    main

    The project exposes several surfaces depending on your integration needs:

    • MCP Package and CLI: Delivered via npm (the main package and platform-optional native packages). The runtime entry is located at dist/runtime-entry.js (native only).
    • Rust Core / Server: The authoritative production runtime is built using the crates/pdf-reader-core and crates/pdf-reader-mcp-server crates.
    • Documentation: Comprehensive guides and tool specifications are available in README.md and the docs/ directory (including docs/specs/).
    • Boundary Specifications: Architectural decisions regarding boundaries are documented in docs/adr/0001-2027-sota-document-intelligence-boundary.md.
  8. Requirements for implementing Provider Adapters

    main

    If you are developing or using provider adapters for OCR, vision, or layout analysis within the @sylphx/pdf-reader-mcp ecosystem, they must adhere to the following constraints:

    • Optionality: Must be an optional dependency or an optional runtime adapter.
    • Credential Handling: Must accept credential handles from the caller environment; never hardcode keys.
    • Transparency: Must explicitly declare whether documents leave the local machine.
    • Data Integrity: Must return typed, provenance-preserving results (including page, bounding region, image, table, and source metadata).
    • Metadata: Must expose cost, latency, and error metadata where available.
    • Granular Failure: Must be capable of failing per page or per source.
  9. Understand the current capabilities of read_pdf via the capability matrix

    main
    The read_pdf tool provides a subset of PDF features modeled after pdf.js. Many features are currently marked as PARTIAL. To understand exactly what is supported (e.g., which metadata fields, annotation types, or geometry properties are available), you should consult the capability matrix. The current live product truth is based on the Rust implementation (v4.1.1).
  10. Use `include_document_map` for structured navigation

    main

    The include_document_map option builds a rich, structured response that links pages, elements, metadata, chunks, and layout diagnostics without embedding heavy image bytes. It is the most efficient way for agents to navigate a document without rebuilding references manually.

    If a visual-region provider is configured, you can also use include_visual_enrichments to get cropped and analyzed regions for tables, charts, and formulas. Keep max_visual_enrichments small for interactive workflows.

    {
      "sources": [{ "path": "doc.pdf", "pages": "1-5" }],
      "include_document_map": true,
      "include_visual_enrichments": true,
      "max_visual_enrichments": 8,
      "include_full_text": false
    }
  11. Understand the Table Intelligence contract

    main

    When include_tables is enabled, the PDF reader provides an enriched table contract designed to help agents assess the reliability of extracted data. Instead of just returning rows, the contract provides metadata about grid trustworthiness, cell inference, and multi-page continuity.

    Key Metadata Fields

    Cell-level properties:

    • cells[].rowSpan and cells[].colSpan: Conservative inferred span hints.
    • cells[].isHeader: Boolean indicating if the cell is part of the first detected header row.
    • cells[].inferred: Boolean indicating if the cell exists because the model inferred an empty slot in the grid.

    Quality metrics (quality):

    • completeness: Overall completeness score.
    • nonEmptyCellRatio: Ratio of cells containing data.
    • cellBoundingBoxCoverage: How well the cells cover the detected table area.
    • inferredCellRatio: Ratio of cells that were inferred rather than explicitly detected.
    • rowAlignment and rowSpacingConsistency: Metrics for structural regularity.
    • Counts: cellBoundingBoxCount, inferredCellCount, missingCellCount, and mergedCellCandidateCount.
    • Signals & Warnings: quality.signals and quality.warnings provide context for sparse, merged, irregular, incomplete-geometry, low-confidence, or continuation-candidate tables.

    Provenance & Continuity:

    • provenance.source: Indicates if the data came from selectable_text (PDF text-coordinate) or ocr_text_layer (OCR word-box).
    • continuation: Candidates linking tables on adjacent pages that share repeated headers or compatible page-edge geometry.

    Implementation Boundaries

    This is a deterministic coordinate model based on selectable PDF text and OCR word boxes. It is not a full visual table recognition engine; it provides structural hints that can be enriched by optional visual table providers.

  12. Understand the PDF Reader MCP agent workflow

    main

    PDF Reader MCP is designed as a full-fidelity intelligence layer for AI agents. Instead of simple text extraction, it provides an 'Agent Document Twin'—a combination of a document map, AST, and evidence indexes.

    The recommended agent workflow follows three stages:

    1. Profile and Map: Use read_pdf to profile the document and obtain the Agent Document Twin.
    2. Search: Use search_pdf to find source-backed text matches (including snippets, offsets, and boxes) to minimize context usage.
    3. Verify/Extract Evidence: Use pdf_evidence for focused follow-up operations like inspecting specific regions, rendering pages, or performing OCR when source-level proof is required.

    This approach ensures agents move from broad understanding to specific, cited evidence without wasting context window on irrelevant text.