Caseware Procurement Document MCP Server
Enables AI agents to search, retrieve, and answer grounded questions over procurement documents (invoices, purchase orders, contracts, etc.) using hybrid SQL and vector retrieval.
README
Caseware Document MCP Server
MCP server over a procurement and inventory knowledge base. Ingests invoices, purchase orders, shipping orders, inventory reports, and contracts, then exposes structured (SQL) and semantic (vector) retrieval via MCP tools for AI agents.
Architecture
Documents Pipeline Storage MCP Server
───────── ──────── ─────── ──────────
invoices/ ──▶ ingest.py ──▶ SQLite search_documents
purchase_orders/ ──▶ extract.py ──▶ ──▶ stdio ──▶ get_related_documents
shipping_orders/ ──▶ embed.py server find_order_evidence
inventory_reports──▶ index.py answer_question
contracts/ ──▶
Hybrid retrieval: structured questions (e.g. "which invoices are missing a PO?") hit SQL; semantic questions (e.g. "summarize contract terms") hit vector search via sentence-transformers, then Ollama (llama3.2) generates grounded answers with citations.
Prerequisites
- Python 3.12+
- Tesseract OCR (for image-based invoice extraction)
- macOS:
brew install tesseract - Ubuntu:
apt install tesseract-ocr
- macOS:
- Ollama with
llama3.2(for LLM-based answer generation)brew install ollama # macOS # or: curl -fsSL https://ollama.com/install.sh | sh ollama pull llama3.2
Quick Start
# Clone and enter the project
cd caseware.mcp-codechallege
# Install with pip (no venv required)
pip install -e .
# Run full pipeline + start MCP server
caseware-mcp
# Or with task (recommended)
task install
task
Dependencies
| Package | Purpose |
|---|---|
pymupdf |
PDF text extraction |
pytesseract + pillow |
OCR for scanned/image documents |
sentence-transformers |
Local embeddings (all-MiniLM-L6-v2) |
pydantic |
Data models and validation |
mcp |
MCP protocol server (stdio transport) |
ollama |
LLM inference for grounded answer generation |
All listed in pyproject.toml — no requirements.txt needed.
Data
Documents live in data/ organized by type:
data/
├── invoices/ 8 PDFs + 5 JPGs
├── purchase_orders/ 8 PDFs
├── shipping_orders/ 16 PDFs
├── inventory_reports/ 7 PDFs
└── contracts/ 1 PDF (71 pages)
The pipeline auto-detects format: PDFs via PyMuPDF, images via Tesseract OCR.
Usage
Taskfile (recommended)
| Command | Description |
|---|---|
task |
Full pipeline + start MCP server |
task pipeline |
Index documents only |
task server |
Start server (skip indexing) |
task install |
Install into .venv |
task test |
Smoke test — list available tools |
task db |
Show document counts |
task clean |
Remove storage + .venv |
Direct
# Full run
caseware-mcp
# Pipeline only (no server)
caseware-mcp --pipeline-only
# Skip indexing (if already indexed)
caseware-mcp --skip-pipeline
MCP Tools
| Tool | Input | What it does |
|---|---|---|
search_documents |
{query, document_type?} |
Hybrid SQL + vector search |
get_related_documents |
{document_id} |
Cross-document lookup via invoice↔PO↔shipment refs |
find_order_evidence |
{order_number} |
Trace an order across all document types with citations |
answer_question |
{question} |
Routes to SQL or vector search → Ollama answer with sources |
Example questions
- "Which invoices are missing a purchase order?"
- "Find all documents related to order 10687"
- "Summarize the contract terms"
- "Show me all invoices for Roland Mendel"
Claude Desktop Integration
See MCPHOWTO.md for detailed setup instructions.
Project Structure
src/caseware_documents_mcp/
├── models.py # Pydantic models
├── main.py # Entry point
├── pipeline/
│ ├── ingest.py # PDF + OCR extraction
│ ├── extract.py # Structured field parsing
│ ├── embed.py # Chunking + embeddings
│ └── index.py # Cross-document reference builder
├── db/
│ ├── schema.py # SQLite DDL
│ └── queries.py # SQL queries
├── retrieval/
│ ├── classifier.py # Question routing
│ ├── structured.py # SQL-based retrieval
│ └── semantic.py # Vector search
└── server/
└── mcp_server.py # MCP stdio server
Design Decisions
- SQLite as the single store — procurement data is fundamentally relational; vector search alone misses invoice↔PO↔shipment links. Embeddings are stored alongside structured data in the same SQLite database.
- Regex extraction over LLM-based parsing — the documents follow predictable templates (Northwind-style); regex is faster, cheaper, and more reliable
- sentence-transformers for local embeddings — no API calls needed;
all-MiniLM-L6-v2is 80MB and runs on CPU - Ollama for answer generation — keeps everything local;
llama3.2provides good results for summarization and reasoning - Keyword classifier over LLM router — pattern matching on the question is sufficient to distinguish "which invoices are missing a PO?" (SQL) from "summarize the contract" (vector)
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.