MCP Knowledge Librarian
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.
MCP Knowledge Librarian
A Model Context Protocol (MCP) server for indexing and searching PDF libraries with citation support. Built for privacy-first, local-only operation with robust text extraction, duplicate detection, and hallucination-resistant search results.
Features
Core Capabilities
📚 PDF Cataloging: Recursive scanning of directories with metadata extraction
🔍 Duplicate Detection: Hash-based duplicate identification
📝 Text Extraction: Support for both text-based and scanned PDFs
🤖 OCR Support: Optional OCR for scanned documents (requires Tesseract)
💾 Persistent Index: Single SQLite database with fast retrieval
🔎 Full-Text Search: SQLite FTS5 with BM25 ranking (stdlib, no heavy dependencies)
⚡ Incremental Indexing: Stat-only directory scans — file contents are only read for new or changed PDFs (cloud-mount friendly)
📖 Citation Support: Every result includes PDF path, page number, and text snippet
🛡️ Hallucination Prevention: Answers derived only from actual document content
MCP Tools
The server provides the following MCP tools:
list_documents- List indexed documents (paginated)index_documents- Incrementally scan library paths and index new/changed PDFssearch- Full-text search with BM25 rankingget_snippet- Get full text snippet by chunk IDget_document_metadata- Get detailed metadata for a documentget_statistics- Get index statistics and health information
Related MCP server: PDF RAG MCP Server
Installation
Prerequisites
Python 3.10 or higher
(Optional) Tesseract OCR for scanned PDF support
# On macOS
brew install tesseract
# On Ubuntu/Debian
sudo apt-get install tesseract-ocr
# On Windows
# Download from https://github.com/UB-Mannheim/tesseract/wikiSetup
Clone the repository:
git clone <repository-url>
cd mcp-knowledge-librarianCreate and activate virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activateInstall dependencies:
pip install -e .
# With OCR support (pytesseract + pillow)
pip install -e ".[ocr]"
# For development
pip install -e ".[dev]"Configuration
Copy config.example.yaml to config.yaml and edit it to customize settings (config.yaml is git-ignored, so your local paths stay private):
# Directories to scan for PDFs
library_paths:
- "./sample_library"
- "/path/to/your/pdfs"
# Index storage location — keep OUTSIDE cloud-synced folders
index_path: "~/.cache/knowledge-librarian/index"
# Text extraction settings
extraction:
detect_scans: true
enable_ocr: false # Set to true if you have Tesseract installed
ocr_language: "eng"
# Search settings
search:
max_results: 20
min_score: 0.1Usage
Running the MCP Server
python -m mcp_knowledge_librarian.server config.yamlFor use with Claude Desktop or other MCP clients, add to your MCP configuration:
{
"mcpServers": {
"knowledge-librarian": {
"command": "python",
"args": ["-m", "mcp_knowledge_librarian.server", "/path/to/config.yaml"],
"cwd": "/path/to/mcp-knowledge-librarian"
}
}
}Indexing Documents
Use the index_documents tool to scan and index your PDF library:
{
"force_reindex": false
}Example Output:
{
"indexed": 42,
"skipped": 3,
"errors": 0,
"ocr_required": 2,
"details": [
{
"filename": "machine_learning.pdf",
"status": "indexed",
"chunks": 15,
"is_scan": false
},
{
"filename": "scanned_doc.pdf",
"status": "ocr_required",
"chunks": 0,
"is_scan": true
}
]
}Searching
Use the search tool to find documents:
{
"query": "neural networks deep learning",
"max_results": 10,
"min_score": 0.1
}Example Output:
{
"query": "neural networks deep learning",
"total_results": 5,
"results": [
{
"document_id": "a1b2c3d4...",
"document_path": "/library/ml_guide.pdf",
"document_title": "Machine Learning Guide",
"page_number": 42,
"snippet": "...neural networks are computational models inspired by biological neurons. Deep learning extends this...",
"score": 0.8532,
"chunk_id": "a1b2c3d4:page:42"
}
]
}Getting Full Snippet
Use the get_snippet tool with a chunk ID from search results:
{
"chunk_id": "a1b2c3d4:page:42"
}Example Output:
{
"chunk_id": "a1b2c3d4:page:42",
"document_id": "a1b2c3d4...",
"document_path": "/library/ml_guide.pdf",
"document_title": "Machine Learning Guide",
"page_number": 42,
"text": "Full page text content here...",
"char_offset": 0,
"char_length": 2547
}Testing
Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=mcp_knowledge_librarian --cov-report=html
# Run specific test file
pytest tests/test_integration.pyArchitecture
Components
Catalog (
catalog.py): PDF discovery, metadata extraction, duplicate detectionExtractor (
extractor.py): Text extraction with OCR support and scan detectionIndexer (
indexer.py): SQLite/FTS5-based indexing with BM25 rankingServer (
server.py): MCP server implementation with tool handlers
Data Flow
PDF Files → Catalog → Extract Text → Index → Search → Results with Citations
↓ ↓
Metadata PersistenceStorage
Everything:
<index_path>/librarian.db— a single SQLite database (documents, chunks, FTS5 full-text index). No pickles, no in-memory caches.
Legacy pickle/Whoosh indexes can be migrated without re-reading any PDFs:
python scripts/migrate_to_sqlite.py <old_index_dir> <new_index_dir>Development
Code Quality
# Format code
black src/ tests/
# Lint code
ruff check src/ tests/
# Type check (if using mypy)
mypy src/Adding Tests
Follow the existing test structure:
test_catalog.py- Cataloging and metadata teststest_extractor.py- Text extraction teststest_integration.py- End-to-end workflow tests
Limitations and Known Issues
OCR Performance: OCR can be slow for large scanned documents
Image PDFs: Complex image-based PDFs may have limited OCR accuracy
Cloud mounts: The first indexing of files on OneDrive/Google Drive downloads them once; afterwards only stat() calls are needed
Privacy and Security
✅ Privacy-first design:
All processing happens locally
No data sent to external services
No telemetry or tracking
⚠️ Security notes:
Index files are stored unencrypted
Use appropriate file system permissions
Be cautious when indexing sensitive documents
Performance Metrics
Typical performance on modern hardware:
Indexing: ~5-10 PDFs/second (text-based)
OCR: ~1-2 pages/second
Search: <100ms for typical queries
Index size: ~1-2% of original PDF size
Troubleshooting
"OCR required" status but OCR disabled
Enable OCR in config.yaml:
extraction:
enable_ocr: true"Module not found" errors
Ensure all dependencies are installed:
pip install -e .Slow indexing
Disable OCR for text-based PDFs
Keep the index on local disk, never in a cloud-synced folder
Search returns no results
Check index statistics:
get_statisticstoolVerify documents are indexed:
list_documentstoolLower
min_scorethreshold in search query
Contributing
Contributions welcome! Please ensure:
Tests pass:
pytestCode is formatted:
black src/ tests/No linting errors:
ruff check src/ tests/
License
MIT — see LICENSE.
Acknowledgments
Built with:
MCP SDK - Model Context Protocol
PyPDF - PDF processing
SQLite FTS5 - Full-text search (stdlib)
Tesseract - OCR engine (optional)
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Private, multimodal knowledge store for agents: hybrid search with cited, provenance-backed results.
Read and search folders on your own computer with explicit consent. Files are never uploaded.
Ingest, manage, and retrieve documents for RAG-powered AI applications
Convert PDFs, Office docs, websites and audio into AI-ready Markdown, then search and ask your docs.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to search and query PDF documents through a local RAG system with vector embeddings. Provides semantic document search capabilities while keeping all data stored locally without external dependencies.-
- 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
- FlicenseAqualityDmaintenanceEnables indexing local documents (PDF, Markdown, text, code) into a knowledge base and querying them via semantic search using local embeddings, all running privately on your machine.4-
- AlicenseNot gradedqualityBmaintenanceEnables assistants to search a personal library of local documents using hybrid BM25 and embeddings, retrieve exact passages with file and page citations, and manage collections entirely on the user's own machine.MIT