Skip to main content

AI-powered document perception and analysis MCP server with intelligent provider selection

Project description

๐Ÿ” Docsray MCP Server

PyPI License: Apache 2.0 Python 3.9+ MCP Status Netlify Status

Docsray is a powerful Model Context Protocol (MCP) server that gives AI assistants like Claude advanced document perception capabilities. Extract text, navigate pages, analyze structure, and understand any document with ease.

โœ… Status: Published to PyPI and TestPyPI - Working in Cursor, Claude Desktop, and other MCP clients

โœจ Features

๐ŸŽฏ Five Powerful Tools

  1. docsray_peek - Quick document overview with format detection and provider capabilities
  2. docsray_map - Generate comprehensive document structure maps with caching
  3. docsray_xray - AI-powered deep analysis extracting entities, relationships, and insights
  4. docsray_extract - Extract content in multiple formats (markdown, text, JSON, tables)
  5. docsray_seek - Navigate to specific pages, sections, or search for content

๐Ÿ”Œ Multi-Provider Architecture

  • PyMuPDF4LLM - Lightning-fast PDF processing (โœ… Implemented)

    • Fast markdown extraction
    • Basic table detection
    • Multi-page support
    • Always enabled as fallback
  • LlamaParse - Deep document understanding with LLMs (โœ… Implemented)

    • AI-powered entity extraction
    • Custom analysis instructions
    • Comprehensive caching in .docsray directories
    • Rich format preservation (markdown, images, tables)
  • PyTesseract - OCR for scanned documents (๐Ÿ”„ Planned)

  • Mistral OCR - AI-powered OCR and analysis (๐Ÿ”„ Planned)

๐Ÿš€ Key Benefits

  • Universal Input Support - Local files (./path, ../path, /absolute) and URLs (https://)
  • Intelligent Provider Selection - Automatically chooses the best tool for each task
  • Smart Caching - LlamaParse results cached in .docsray directories for instant access
  • Dynamic Discovery - Tools report actual capabilities based on what's enabled
  • Production Ready - Comprehensive error handling, logging, and 56 tests
  • Self-Documenting - Built-in resources for discovery by MCP clients

๐Ÿ“ฆ Installation

Quick Start with uvx (Recommended)

# Run directly without installation
uvx docsray-mcp

# Or install globally
uv tool install docsray-mcp
# Then run with either:
docsray
# or
docsray-mcp

Alternative: Install with pip

# Basic installation (PyMuPDF4LLM only)
pip install docsray-mcp

# With LlamaParse for AI analysis
pip install "docsray-mcp[ai]"

# Development installation
pip install -e ".[dev]"

๐Ÿš€ Quick Start

1. Set up API Keys (Optional but Recommended)

Create a .env file in your project:

# For AI-powered analysis with LlamaParse
LLAMAPARSE_API_KEY=llx-your-key-here

# Or use environment variables
export LLAMAPARSE_API_KEY=llx-your-key-here

Get your free LlamaParse API key at cloud.llamaindex.ai

2. Configure with Your MCP Client

For Cursor

Add to your Cursor settings:

{
  "mcpServers": {
    "docsray": {
      "command": "uvx",
      "args": ["docsray-mcp"],
      "env": {
        "LLAMAPARSE_API_KEY": "llx-your-key-here"
      }
    }
  }
}

For Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "docsray": {
      "command": "uvx",
      "args": ["docsray-mcp"],
      "env": {
        "LLAMAPARSE_API_KEY": "llx-your-key-here"
      }
    }
  }
}

๐Ÿ“š Usage Examples

Basic Document Overview

Peek at ./document.pdf to see its structure and available formats

Extract Entities from Contracts

Xray ./contract.pdf and extract all parties, dates, payment terms, and obligations

Navigate Documents

Map the complete structure of ./manual.pdf including all sections and subsections

Extract Specific Content

Extract pages 10-20 from ./report.pdf as markdown

Analyze Web Documents

Analyze https://arxiv.org/pdf/2301.00234.pdf for methodology and key findings

Compare Providers

Extract text from document.pdf with provider pymupdf4llm (fast)
Xray document.pdf with provider llama-parse (AI analysis)

๐Ÿ› ๏ธ Advanced Configuration

Environment Variables

# Provider Configuration
DOCSRAY_PYMUPDF4LLM_ENABLED=true  # Always true by default
DOCSRAY_LLAMAPARSE_ENABLED=true
LLAMAPARSE_API_KEY=llx-your-key

# Performance Tuning
DOCSRAY_CACHE_ENABLED=true
DOCSRAY_CACHE_TTL=3600
DOCSRAY_MAX_CONCURRENT_REQUESTS=5
DOCSRAY_TIMEOUT_SECONDS=30

# Logging
DOCSRAY_LOG_LEVEL=INFO

Provider Capabilities

PyMuPDF4LLM (Always Available)

  • โœ… Fast text extraction
  • โœ… Markdown formatting
  • โœ… Basic table detection
  • โœ… Multi-page support
  • โŒ No AI analysis
  • โŒ No OCR

LlamaParse (When API Key Configured)

  • โœ… AI-powered analysis
  • โœ… Entity extraction
  • โœ… Custom instructions
  • โœ… Table extraction
  • โœ… Image extraction
  • โœ… Layout preservation
  • โœ… Relationship mapping
  • โœ… Result caching

๐Ÿงช Testing

# Run all tests
pytest tests/

# Run only unit tests (no API calls)
pytest tests/unit/

# Run integration tests
pytest tests/integration/

# Run with coverage
pytest tests/ --cov=src/docsray --cov-report=html

Current test coverage: 52 tests passing with comprehensive coverage across all components

๐Ÿ“– API Reference

Tool: docsray_peek

Get quick document overview and metadata.

{
  "document_url": "path/to/document.pdf",
  "depth": "structure",  # metadata | structure | preview
  "provider": "auto"     # auto | pymupdf4llm | llama-parse
}

Tool: docsray_map

Generate comprehensive document structure map.

{
  "document_url": "path/to/document.pdf",
  "include_content": false,
  "analysis_depth": "deep",  # basic | deep | comprehensive
  "provider": "auto"
}

Tool: docsray_xray

Deep AI-powered document analysis.

{
  "document_url": "path/to/document.pdf",
  "analysis_type": ["entities", "key-points"],
  "custom_instructions": "Extract all dates and amounts",
  "provider": "llama-parse"
}

Tool: docsray_extract

Extract content in various formats.

{
  "document_url": "path/to/document.pdf",
  "extraction_targets": ["text", "tables"],
  "output_format": "markdown",  # markdown | text | json
  "pages": [1, 2, 3],  # Optional: specific pages
  "provider": "auto"
}

Tool: docsray_seek

Navigate to specific document locations.

{
  "document_url": "path/to/document.pdf",
  "target": {"page": 5},  # or {"section": "Introduction"} or {"query": "search text"}
  "extract_content": true,
  "provider": "auto"
}

๐Ÿ—๏ธ Architecture

docsray-mcp/
โ”œโ”€โ”€ src/docsray/
โ”‚   โ”œโ”€โ”€ server.py           # FastMCP server with discovery resources
โ”‚   โ”œโ”€โ”€ providers/          # Provider implementations
โ”‚   โ”‚   โ”œโ”€โ”€ base.py        # Provider interface
โ”‚   โ”‚   โ”œโ”€โ”€ pymupdf4llm.py # Fast PDF extraction
โ”‚   โ”‚   โ””โ”€โ”€ llamaparse.py  # AI-powered analysis
โ”‚   โ”œโ”€โ”€ tools/             # MCP tool implementations
โ”‚   โ”‚   โ”œโ”€โ”€ peek.py        # Document overview
โ”‚   โ”‚   โ”œโ”€โ”€ map.py         # Structure mapping
โ”‚   โ”‚   โ”œโ”€โ”€ xray.py        # Deep analysis
โ”‚   โ”‚   โ”œโ”€โ”€ extract.py     # Content extraction
โ”‚   โ”‚   โ””โ”€โ”€ seek.py        # Navigation
โ”‚   โ””โ”€โ”€ utils/             # Utilities
โ”‚       โ”œโ”€โ”€ cache.py       # Document caching
โ”‚       โ””โ”€โ”€ llamaparse_cache.py  # LlamaParse .docsray cache
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ unit/              # Fast isolated tests
โ”‚   โ”œโ”€โ”€ integration/       # Component interaction tests
โ”‚   โ””โ”€โ”€ manual/            # Debugging scripts
โ””โ”€โ”€ PROMPTS.md            # Example prompts for all use cases

๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Development Setup

# Clone the repository
git clone https://github.com/docsray/docsray-mcp.git
cd docsray-mcp

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest tests/

# Run linting
ruff check src/

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ฌ Support


Made with โค๏ธ for the MCP ecosystem

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docsray_mcp-0.3.1.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docsray_mcp-0.3.1-py3-none-any.whl (50.8 kB view details)

Uploaded Python 3

File details

Details for the file docsray_mcp-0.3.1.tar.gz.

File metadata

  • Download URL: docsray_mcp-0.3.1.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for docsray_mcp-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c5e3f9b01e3df1eacfae6319a8efdda40fb3fa7bb473f5a85683e41adf427839
MD5 31ea03e18d49dc3325258aef7467c1c6
BLAKE2b-256 51b10cfabb30e5bdb18a25e85e2fc807dec5d4f7249cb87a14f35f7b3521b26e

See more details on using hashes here.

File details

Details for the file docsray_mcp-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: docsray_mcp-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 50.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for docsray_mcp-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61c1e3ab5658a81750a9b491a82b3b452e565df2c2e9519374a52852bb6cd231
MD5 63b1423051aa666228b20e9d793f7780
BLAKE2b-256 79a462b4377d5a0b4bd92d4042c206b0ea185e1d0b7168d59a67a976d58c5ccb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page