PDF MCP Server
Uses OpenAI's GPT-4o-mini model to generate answers to questions about PDF documents through AI-powered retrieval-augmented generation (RAG).
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
PDF Retrieval MCP Server
A completely free Model Context Protocol (MCP) server for retrieving relevant chunks from PDF documents using hybrid search (BM25 + Vector Search).
๐ Features
PDF Document Processing: Automatic parsing and indexing of PDF files using Docling
Hybrid Retrieval: Combines BM25 (keyword) and vector search (semantic) for accurate retrieval
Free Embeddings: Uses ChromaDB's default sentence-transformers (no API costs!)
Pure Retrieval Mode: Returns raw document chunks for agent processing (no LLM answer generation)
Fresh Start: Clears vector database on each startup for clean indexing
MCP Integration: Exposes
retrieve_pdf_chunkstool via FastMCP for seamless agent integration
Related MCP server: Antigravity PDF MCP Server
๐ Prerequisites
Python 3.11 or later
PDF documents to index
No API keys required! โจ
๐ ๏ธ Installation
1. Clone the Repository (if not already done)
git clone <repository-url>
cd pdf_mcpserver2. Install Dependencies with uv
uv syncThis will automatically:
Create a virtual environment (
.venv)Install all dependencies from
pyproject.tomlSet up the project
3. Add PDF Documents
Create a documents directory and add your PDF files:
mkdir documents
# Copy your PDF files to the documents/ directoryThat's it! No API keys or additional configuration needed.
๐ฏ Usage
Running the Server
uv run python main.pyOr activate the virtual environment first:
source .venv/bin/activate # On Windows: .venv\Scripts\activate
python main.pyThe server will:
Start immediately (lazy initialization)
Load and index PDFs on first query
Be ready to retrieve document chunks via MCP
Using the retrieve_pdf_chunks Tool
The server exposes a single MCP tool: retrieve_pdf_chunks(query: str, max_chunks: int = 5) -> str
Example Query:
retrieve_pdf_chunks("machine learning algorithms", max_chunks=3)Example Response:
{
"query": "machine learning algorithms",
"chunks": [
{
"content": "Machine learning algorithms can be categorized into supervised, unsupervised, and reinforcement learning...",
"document_name": "ml_guide.pdf",
"page_number": 12,
"metadata": {"source": "ml_guide.pdf"}
},
{
"content": "Common supervised learning algorithms include linear regression, decision trees, and neural networks...",
"document_name": "ml_guide.pdf",
"page_number": 15,
"metadata": {"source": "ml_guide.pdf"}
}
],
"total_chunks": 2
}Response Structure
Field | Type | Description |
| string | The original search query |
| array | List of relevant document chunks |
| string | The text content of the chunk |
| string | Source PDF filename |
| int | Page number (if available) |
| object | Additional metadata |
| int | Number of chunks returned |
How Agents Use This
When an agent (like Claude) calls this tool:
Agent sends a search query
Server returns relevant document chunks
Agent uses chunks in its context to answer questions
Example Agent Flow:
User: "What are the main ML algorithms discussed?"
โ
Agent calls: retrieve_pdf_chunks("machine learning algorithms")
โ
Server returns: 3 relevant chunks from PDFs
โ
Agent reads chunks and generates answer for user๐ Testing with MCP Inspector
The MCP Inspector is a web-based tool for testing and debugging MCP servers interactively.
Running the Inspector
npx @modelcontextprotocol/inspector uv run python main.pyThis command will:
Start the MCP Inspector proxy server
Launch your PDF Retrieval Server
Open a web browser with the Inspector UI
What You'll See
The Inspector provides:
Tool Discovery: View available tools (
retrieve_pdf_chunks)Interactive Testing: Test queries with custom parameters
Real-time Responses: See JSON responses in real-time
Request/Response Logs: Debug the MCP protocol communication
Example Inspector Workflow
Open the Inspector - Browser opens automatically at
http://localhost:6274Wait for Initialization - Server loads and indexes PDFs on first query (~1-2 minutes)
Select Tool - Click on
retrieve_pdf_chunksin the tools listEnter Query - Type your search query (e.g., "machine learning")
Set Parameters - Optionally adjust
max_chunks(default: 5)Execute - Click "Run" to see the results
View Response - Inspect the returned chunks and metadata
Inspector Tips
First query is slow: PDF indexing happens on first query (87 seconds for typical PDFs)
Subsequent queries are fast: Embeddings are cached in ChromaDB
Fresh start: Server clears ChromaDB on each restart for clean indexing
Check logs: Terminal shows detailed logging of the indexing process
๐๏ธ Architecture
pdf_mcpserver/
โโโ src/
โ โโโ config.py # Configuration management
โ โโโ constants.py # Configuration constants
โ โโโ models.py # Pydantic response models
โ โโโ pdf_processor.py # PDF loading and hybrid retrieval
โ โโโ retrieval_handler.py # Document chunk retrieval
โโโ main.py # MCP server entry point
โโโ pyproject.toml # Project metadata
โโโ .env # Environment configurationKey Components
PDFProcessor: Singleton class that loads PDFs, converts to Markdown using Docling, and builds hybrid retriever (BM25 + Vector Search)
RetrievalHandler: Retrieves relevant chunks for queries - no LLM answer## ๐ง Configuration
Configuration is managed through environment variables. Create a .env file in the project root:
# Optional: PDF Documents Directory (defaults to ./documents)
PDF_DOCUMENTS_DIR=./documents
# Optional: ChromaDB Directory (defaults to ./chroma_db)
CHROMA_DB_DIR=./chroma_db
# Optional: Log Level (defaults to INFO)
LOG_LEVEL=INFOConfiguration Options
Variable | Required | Default | Description |
| No |
| Directory containing PDF files to index |
| No |
| Directory for ChromaDB vector storage |
| No |
| Logging level (DEBUG, INFO, WARNING, ERROR) |
Note: No API keys required! ChromaDB uses free local embeddings (sentence-transformers).
๐งช Testing
Run unit tests:
uv run pytest tests/๐ Troubleshooting
No PDF files found
Error: No PDF files found in ./documents
Solution: Add PDF files to the documents/ directory or update PDF_DOCUMENTS_DIR in .env
Import errors
Error: ModuleNotFoundError: No module named 'docling'
Solution: Ensure all dependencies are installed: uv sync
CUDA out of memory
Error: CUDA out of memory
Solution: The server is configured to use CPU-only mode. If you still see this error, check that CUDA_VISIBLE_DEVICES="" is set in src/pdf_processor.py
๐ Dependencies
fastmcp: MCP server framework
docling: Document processing and parsing
chromadb: Vector database with free sentence-transformers embeddings
langchain: RAG framework and retrievers
loguru: Logging
No paid APIs required! All embeddings are generated locally using ChromaDB's default model (all-MiniLM-L6-v2).
๐ค Contributing
This is a Proof of Concept (PoC) implementation. For production use, consider:
Adding caching for processed documents
Implementing multi-agent workflow with fact verification
Supporting additional document formats (DOCX, TXT, etc.)
Adding authentication and rate limiting
๐ License
[Your License Here]
๐ Acknowledgments
Based on the docchat-docling architecture.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
Related MCP Connectors
High-fidelity PDF to structured Markdown conversion and document field extraction.
Query your own PDFs and documents from any MCP client. Every answer cites the page it came from.
Turn any PDF into structured JSON via AI + OCR: invoices, bank statements, contracts.
Extract, ask, compare and parse PDFs/images with source evidence. OAuth sign-in or API keys.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables intelligent search and question-answering over PDF documents using semantic similarity and keyword search. Supports OCR for scanned PDFs, persistent vector storage with ChromaDB, and maintains source tracking with page numbers.6MIT
- FlicenseNot gradedqualityDmaintenanceEnables intelligent ingestion and querying of PDF, Markdown, and text files using hybrid search that combines keyword matching and semantic embeddings with citations.2-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to query PDF documents by ingesting them into a vector database and generating answers grounded in the actual documents.18 npm1MIT
- FlicenseNot gradedqualityDmaintenanceEnables querying a hybrid-retrieval RAG pipeline (dense + BM25) over ingested PDF documents, returning answers generated by Gemini.-