Labsco
lhstorm logo

QuantConnect PDF MCP Server

β˜… 5

from lhstorm

Converts QuantConnect PDF documentation into searchable markdown, enabling fast, context-aware search.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

MCP Server Knowledge Engine

A powerful Model Context Protocol (MCP) server that transforms any PDF document collection into an intelligent, searchable knowledge base accessible through Claude Desktop. This server features advanced search capabilities using TF-IDF scoring, proximity matching, and domain-specific optimization.

🌟 Key Features

  • πŸ” Advanced Search Engine: TF-IDF-based inverted index with proximity matching for highly relevant results
  • πŸ“„ Universal PDF Support: Process any PDF collection - technical docs, legal papers, research, and more
  • ⚑ High Performance: Cached search index, incremental processing, and background initialization
  • 🎯 Domain Optimization: Configure domain-specific keywords for enhanced search accuracy
  • βš™οΈ Fully Configurable: JSON-based configuration with environment variable support
  • πŸ› οΈ Comprehensive CLI: Complete server management through intuitive commands
  • πŸ”— Seamless MCP Integration: Ready-to-use with Claude Desktop, VS Code, and other MCP clients
  • πŸ“Š Smart Caching: MD5 hash-based change detection for efficient updates

πŸ’¬ Using with Claude Desktop

Once configured, you can interact with your PDFs naturally:

Example prompts:

  • "Search for information about [topic] in the documentation"
  • "What does the documentation say about [specific feature]?"
  • "Find all references to [keyword] across all PDFs"
  • "Show me the content of [document name]"
  • "List all available documents"

Advanced usage:

  • "Search for [term1] near [term2]" - Leverages proximity matching
  • "Get page 15 of [document]" - Retrieves specific pages
  • "Find the top 10 results for [query]" - Adjusts result count

πŸ“ Project Structure

mcp_server_knowledge_engine/
β”œβ”€β”€ server.py              # Main MCP server with search engine
β”œβ”€β”€ config.py              # Configuration management & validation
β”œβ”€β”€ manage_server.py       # CLI for server management
β”œβ”€β”€ generate_mcp_config.py # MCP configuration generator
β”œβ”€β”€ convert_pdfs.py        # Standalone PDF conversion utility
β”œβ”€β”€ server_config.json     # Active server configuration
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ examples/              # Example configurations
β”‚   β”œβ”€β”€ legal_docs_config.json
β”‚   β”œβ”€β”€ medical_docs_config.json
β”‚   β”œβ”€β”€ research_papers_config.json
β”‚   └── tech_docs_config.json
└── your-pdfs/             # Your PDF folder (configurable)
    β”œβ”€β”€ document1.pdf
    β”œβ”€β”€ document2.pdf
    └── markdown/          # Auto-generated cache
        β”œβ”€β”€ .pdf_cache.json      # Processing metadata
        β”œβ”€β”€ .search_index.pkl    # Cached search index
        β”œβ”€β”€ document1.md         # Converted documents
        └── document2.md

πŸ› οΈ Management Commands

Server Management

# Create new configuration
python manage_server.py create-config

# Test configuration
python manage_server.py test

# Generate MCP config
python manage_server.py generate-mcp-config

PDF Management

# List all PDFs
python manage_server.py list-pdfs

# Add PDF
python manage_server.py add-pdf document.pdf

# Remove PDF  
python manage_server.py remove-pdf document.pdf

# Process all PDFs
python manage_server.py process-pdfs

MCP Configuration

# Print MCP config
python generate_mcp_config.py

# Automatically merge with Claude Desktop config
python generate_mcp_config.py --merge

# Save to file
python generate_mcp_config.py --output my_mcp_config.json

πŸ”§ Available MCP Tools

Each server provides three configurable tools:

  1. Search Tool (default: search_docs)

    • Intelligent search through all documents
    • TF-IDF scoring with proximity matching
    • Returns relevant excerpts with context
  2. List Tool (default: list_docs)

    • Lists all available documents
    • Shows document metadata and page counts
  3. Content Tool (default: get_document_content)

    • Retrieves full document content
    • Can fetch specific pages
    • Includes complete markdown formatting

🎯 Domain Customization

The server adapts to your domain through:

  • Domain Keywords: Configure terms important to your field
  • Tool Names: Customize tool names (e.g., search_legal_docs)
  • Descriptions: Tailor descriptions for your use case
  • Context Size: Adjust how much context to return in search results

πŸ” How the Search Engine Works

Inverted Index Architecture

The server uses an advanced inverted index for lightning-fast searches:

  1. Document Processing: PDFs are converted to markdown and tokenized
  2. Index Building: Words are mapped to their locations (document, page, position)
  3. TF-IDF Scoring:
    • TF (Term Frequency): How often a word appears in a document
    • IDF (Inverse Document Frequency): How rare a word is across all documents
    • Combined score ensures relevant, unique results rank higher

Search Features

  • Proximity Boosting: Multi-word queries score higher when terms appear close together
  • Context Extraction: Returns relevant snippets with search terms highlighted
  • Domain Keyword Recognition: Configured keywords get special treatment
  • Page-Level Precision: Results include specific page numbers
  • Smart Caching: Search index persists between server restarts

πŸ“Š Performance Optimizations

  • Incremental Processing: MD5 hash-based change detection - only new/modified PDFs are processed
  • Persistent Search Index: Pickled index loads instantly on server restart
  • Background Initialization: Server accepts connections while building index
  • Memory Efficiency: Streaming PDF processing and markdown storage
  • Configurable Limits: Control file size limits and processing parameters

πŸ—οΈ Architecture Overview

Core Components

  1. SearchIndex Class (server.py:27-140)

    • Implements inverted index with TF-IDF scoring
    • Handles word tokenization and document indexing
    • Provides proximity-based ranking for multi-word queries
  2. GenericPDFServer Class (server.py:142-661)

    • Main server implementation with MCP protocol handling
    • Manages PDF processing pipeline
    • Handles async operations and background initialization
  3. Configuration System (config.py)

    • Dataclass-based type-safe configuration
    • JSON schema validation
    • Environment variable support
  4. Management CLI (manage_server.py)

    • Interactive configuration creation
    • PDF management operations
    • Server testing and validation

Data Flow

PDFs β†’ PDF Reader β†’ Markdown Converter β†’ Search Index β†’ MCP Tools β†’ Claude
         ↓                    ↓                ↓
    [.pdf files]      [.md cache files]  [.search_index.pkl]

πŸ“š Example Use Cases

  • Legal Firms: Search through contracts, case files, and legal documents
  • Research Labs: Query scientific papers and technical reports
  • Software Teams: Access API documentation and technical specs
  • Medical Practices: Search patient records and medical literature
  • Educational Institutions: Browse course materials and textbooks

🀝 Contributing

We welcome contributions! Here are some ways to help:

Enhancement Ideas

  1. Document Format Support: Add support for Word, HTML, or other formats
  2. Search Improvements: Implement semantic search, fuzzy matching, or ML-based ranking
  3. Performance: Add database backend, parallel processing, or distributed indexing
  4. Tools: Create specialized MCP tools for specific domains
  5. UI: Build a web interface for configuration management

Development Guidelines

  • Follow existing code style and patterns
  • Add tests for new functionality
  • Update documentation for new features
  • Submit PRs with clear descriptions

πŸ” Security Considerations

  • The server only has read access to specified PDF folders
  • No external network calls are made during operation
  • Sensitive data remains local - nothing is sent to external services
  • Configure appropriate file permissions for your PDF folders

πŸ“„ License

This project is open source. See LICENSE file for details.

πŸ™ Acknowledgments

Built with the Model Context Protocol by Anthropic.


Ready to transform your PDFs into a searchable knowledge base?

Run python manage_server.py create-config to get started! πŸš€

πŸ“¦ Dependencies

  • mcp: Model Context Protocol SDK for building MCP servers
  • PyPDF2: PDF parsing and text extraction
  • asyncio: Asynchronous I/O for concurrent operations
  • jsonschema: JSON validation for configuration files

All dependencies are lightweight and have minimal system requirements.