Content
# DocuMind MCP Server
An MCP (Model Context Protocol) server that ingests documents and codebases into a local vector store and exposes intelligent RAG retrieval tools to any MCP-compatible AI client(Claude Desktop, Claude Code, VS Code Copilot, Cursor, etc.).
**Zero API cost** — all embeddings run locally on CPU; the server never calls an LLM. MCP clients supply the LLMs (e.g., Claude, Copilot), so there are no third-party LLM API costs for the server itself.
## Features
- **Ingest PDFs, markdown, and entire codebases** into a pgvector store
- **AST-aware code chunking** via tree-sitter (TypeScript, JavaScript, Python, Go, Rust, Java, and more)
- **Semantic search** across all ingested content using cosine similarity
- **Smart question answering** — retrieves and formats relevant context for the LLM client
- **Duplicate detection** — SHA-256 hash prevents re-ingesting the same document
- **Works with any MCP client** — Claude Desktop, Claude Code, Cursor, VS Code Copilot, Windsurf, etc.
Key decisions
-------------
- Language: TypeScript (strict)
- MCP SDK: `@modelcontextprotocol/sdk`
- Embeddings: computed locally on CPU using `@xenova/transformers` (example model: `all-MiniLM-L6-v2`) — no external embedding APIs
- Vector store: `pgvector` on PostgreSQL
- PDF parsing: `pdf-parse` or `unpdf` (local, no API)
- Code parsing: `tree-sitter` (AST-aware chunking)
- LLMs: None on the server — clients provide LLMs (Claude Desktop, Claude Code, Copilot, etc.)
- Package manager: pnpm
- Validation: Zod
Why "Zero API cost"?
--------------------
DocuMind itself performs no paid LLM calls and does not call external embedding services. Embeddings are computed entirely locally on CPU using open-source transformer models (via `@xenova/transformers`), and the server exposes retrieval tools for MCP clients. Any LLM usage and associated costs are incurred by the client (e.g., Claude Desktop or another MCP-capable model provider), not DocuMind.
## Architecture
```
┌─────────────────────┐ ┌──────────────────────────┐
│ MCP Client │ stdio │ DocuMind MCP Server │
│ (Claude Desktop, │◄───────►│ │
│ Claude Code, │ JSON │ Tools: │
│ Cursor, etc.) │ RPC │ - semantic_search │
└─────────────────────┘ │ - ask_question │
│ - ingest_document │
│ - ingest_codebase │
│ - list_sources │
│ - get_summary │
│ │
│ Resources: │
│ - documind://sources │
│ - documind://status │
└──────────┬───────────────┘
│
┌────────────┼────────────┐
│ │ │
┌────────▼──┐ ┌──────▼─────┐ ┌──▼──────────┐
│ Local │ │ PostgreSQL │ │ tree-sitter │
│ Embeddings│ │ + pgvector │ │ (WASM) │
│ (ONNX) │ │ │ │ AST parsing │
└───────────┘ └────────────┘ └─────────────┘
```
## Quick Start
### Prerequisites
- Node.js 18+
- PostgreSQL with pgvector extension
- pnpm
### Setup
```bash
# Clone
git clone https://github.com/YOUR_USERNAME/documind-mcp.git
cd documind-mcp
# Install
pnpm install
# Create database and enable pgvector
psql -c "CREATE DATABASE documind;"
psql -d documind -c "CREATE EXTENSION IF NOT EXISTS vector;"
# Configure
cp .env.example .env
# Edit .env with your DATABASE_URL
# Run migrations
pnpm db:migrate
```
### Connect to Claude Desktop
Add to `%APPDATA%\Claude\claude_desktop_config.json` (Windows) or `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS):
```json
{
"mcpServers": {
"documind": {
"command": "npx",
"args": ["tsx", "/absolute/path/to/documind-mcp/src/index.ts"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/documind"
}
}
}
}
```
### Connect to Claude Code
Add `.mcp.json` to your project root:
```json
{
"mcpServers": {
"documind": {
"command": "npx",
"args": ["tsx", "src/index.ts"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/documind"
}
}
}
}
```
## Tools
| Tool | Description | Parameters |
|------|-------------|------------|
| `semantic_search` | Search by semantic similarity | `query`, `limit?` (1-20, default 5) |
| `ask_question` | RAG Q&A with formatted context | `question`, `limit?` (1-10, default 5) |
| `ingest_document` | Ingest a PDF, markdown, or text file | `filePath` |
| `ingest_codebase` | Ingest a repo with AST-aware chunking | `dirPath` |
| `list_sources` | List all ingested sources with chunk counts | — |
| `get_summary` | Get detailed info about a source | `sourceId` (UUID) |
## Resources
| URI | Description |
|-----|-------------|
| `documind://sources` | All ingested sources with metadata |
| `documind://status` | Server health, model info, statistics |
## How It Works
### Ingestion Pipeline
```
File/Repo → Parse → Chunk → Embed → Store in pgvector
```
1. **Parse**: PDFs via `pdf-parse`, markdown/text via file read, code via `tree-sitter` AST
2. **Chunk**: Text split at 512 chars with overlap at sentence boundaries. Code split by AST nodes (functions, classes, methods)
3. **Embed**: Local `all-MiniLM-L6-v2` model (384 dimensions, runs on CPU via ONNX)
4. **Store**: Chunks + embeddings in PostgreSQL with pgvector HNSW index for fast cosine search
5. **Dedup**: Documents are SHA-256 hashed — re-ingesting the same file is a no-op. Codebases always re-ingest fresh.
### Retrieval Pipeline
```
Query → Embed → Cosine Similarity Search (HNSW) → Return Top-K Chunks
```
The MCP client (Claude, Cursor, etc.) provides the LLM reasoning. DocuMind only does fast, accurate retrieval.
### AST-Aware Code Chunking
Instead of splitting code at arbitrary character boundaries, DocuMind uses tree-sitter to parse code into an AST and extracts meaningful units:
- **Functions/methods** as individual chunks (with name, line numbers in metadata)
- **Classes/interfaces/types** as individual chunks
- **Fallback** to text chunking for files without a tree-sitter grammar
Supported languages: TypeScript, JavaScript, Python, Go, Rust, Java, C, C++, C#, Ruby, Kotlin, Swift, Dart, Lua, PHP, Scala, Bash
## Tech Stack
| Component | Technology |
|-----------|------------|
| Language | TypeScript (ESM, strict mode) |
| MCP SDK | `@modelcontextprotocol/sdk` |
| Embeddings | `@xenova/transformers` + `all-MiniLM-L6-v2` (local, CPU, ONNX) |
| Vector Store | PostgreSQL + pgvector (HNSW index) |
| ORM | Drizzle ORM |
| PDF Parsing | `pdf-parse` |
| Code Parsing | `web-tree-sitter` + `tree-sitter-wasms` |
| Transport | stdio (JSON-RPC 2.0) |
## Development
```bash
# Type check
pnpm typecheck
# Dev mode (with hot reload)
pnpm dev
# Build
pnpm build
# Run migrations
pnpm db:migrate
# Generate new migration after schema changes
pnpm db:generate
# Drizzle Studio (DB browser)
pnpm db:studio
# Debug with MCP Inspector
npx @modelcontextprotocol/inspector npx tsx src/index.ts
```
## Project Structure
```
src/
├── index.ts # MCP server — tool & resource registration
├── config.ts # Centralized config (env vars)
├── db/
│ ├── schema.ts # Drizzle schema (sources + chunks tables)
│ └── index.ts # Database connection pool
├── embeddings/
│ └── index.ts # Local embedding model (singleton loader)
├── ingestion/
│ ├── document.ts # PDF/markdown ingestion pipeline
│ └── codebase.ts # AST-aware code ingestion pipeline
├── tools/
│ ├── search.ts # Semantic search (pgvector cosine similarity)
│ └── sources.ts # list_sources / get_summary queries
└── utils/
└── chunker.ts # Text chunking with overlap + sentence boundaries
```
## License
MIT