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)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。