8000 GitHub - m2ux/lance-mcp: LanceDB MCP Server for LLMS Β· GitHub
[go: up one dir, main page]

Skip to content

About

LanceDB MCP Server for LLMS

Resources

Stars

0 stars

Watchers

0 watching

Forks

Β 
Β 

Latest commit

Β 

History

37 Commits

Folders and files

Repository files navigation

🧠 LanceDB MCP Server with Conceptual Search

Node.js 18+ License: MIT

A Model Context Protocol (MCP) server that enables LLMs to interact directly with documents through conceptual search powered by LanceDB. Features corpus-driven concept extraction, WordNet semantic enrichment, and multi-signal hybrid ranking for superior search accuracy.

✨ Features

  • 🧠 Conceptual Search: Corpus concepts + WordNet + hybrid signals for intelligent retrieval
  • πŸ” Multi-Signal Ranking: Vector similarity, BM25, title matching, concept matching, synonym expansion
  • πŸ€– LLM-Powered: Claude Sonnet 4.5 for concept extraction, Grok-4-fast for summaries
  • 🌐 WordNet Integration: Synonym expansion and hierarchical concept navigation (161K+ words)
  • ⚑ Lightning Fast: Cloud AI + local embeddings, no timeout issues
  • πŸ›‘οΈ Robust PDF Handling: Gracefully handles corrupted files with OCR fallback
  • πŸ“Š Comprehensive Indexing: Extracts 100+ concepts per document
  • πŸ”’ Security First: Local storage with secure API key management

πŸš€ Quick Start

Requirements:

  • Node.js 18+
  • OpenRouter API key (sign up here)
  • Python 3.9+ with NLTK (for WordNet)
  • MCP Client (Claude Desktop or Cursor)

1. Setup Environment

# Clone and install
git clone https://github.com/m2ux/lance-mcp.git
cd lance-mcp
npm install
npm run build

# Install WordNet
pip3 install nltk
python3 -c "import nltk; nltk.download('wordnet'); nltk.download('omw-1.4')"

# Configure API key
cp .env.example .env
# Edit .env and add your OpenRouter API key

2. Configure MCP Client

Cursor (~/.cursor/mcp.json):

{
  "mcpServers": {
    "lancedb": {
      "command": "node",
      "args": [
        "/path/to/lance-mcp/dist/conceptual_index.js",
        "/home/username/.lance_mcp"
      ]
    }
  }
}

Claude Desktop
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "lancedb": {
      "command": "node",
      "args": [
        "/path/to/lance-mcp/dist/conceptual_index.js",
        "/home/username/.lance_mcp"
      ]
    }
  }
}

🎬 End-to-End Walkthrough

Complete setup from PDFs to working conceptual search in 15 minutes!

Step 1: Setup & Build

# Clone and build
git clone https://github.com/m2ux/lance-mcp.git
cd lance-mcp
npm install
npm run build

Step 2: Install WordNet

# Install Python NLTK
pip3 install nltk

# Download WordNet data
python3 -c "import nltk; nltk.download('wordnet'); nltk.download('omw-1.4')"

# Verify installation
python3 -c "from nltk.corpus import wordnet as wn; print(f'βœ… WordNet ready: {len(list(wn.all_synsets()))} synsets')"

Step 3: Configure OpenRouter API Key

# Copy example environment file
cp .env.example .env

# Edit .env and add your OpenRouter API key
# Get one at: https://openrouter.ai/keys
nano .env  # or use your preferred editor

Step 4: Seed Your Documents

# Set environment
source .env

# Initial seeding (create database from scratch)
npx tsx hybrid_fast_seed.ts \
  --dbpath ~/.lance_mcp \
  --filesdir ~/Documents/my-pdfs \
  --overwrite

# OR: Incremental seeding (add new/changed documents only - much faster!)
npx tsx hybrid_fast_seed.ts \
  --dbpath ~/.lance_mcp \
  --filesdir ~/Documents/my-pdfs
  # Note: Omit --overwrite to skip already-processed files

What happens during seeding:

  • πŸ“„ Loads PDF files (with OCR fallback for scanned documents)
  • πŸ” Smart detection: Skips files already in database (unless --overwrite used)
  • 🧠 Extracts 100+ concepts per document (Claude Sonnet 4.5)
  • πŸ“ Generates summaries (Grok-4-fast)
  • 🌐 Enriches with WordNet synonyms and hierarchies
  • ⚑ Creates fast local embeddings (384-dimensional)
  • πŸ’Ύ Stores in 3 LanceDB tables: catalog, chunks, concepts

Step 5: Configure Cursor

  1. Open Cursor settings and navigate to MCP configuration

  2. Edit your MCP config file:

    Linux/macOS: ~/.cursor/mcp.json Windows: %APPDATA%/Cursor/User/mcp.json

  3. Add the configuration:

    {
      "mcpServers": {
        "lancedb": {
          "command": "node",
          "args": [
            "/path/to/your/lance-mcp/dist/simple_index.js",
            "/home/your-username/.lance_mcp"
          ]
        }
      }
    }

    Replace the paths with your actual paths:

    # Find your full paths
    pwd  # In lance-mcp directory
    echo ~/.lance_mcp  # Database location

Step 5: Restart Cursor

# Reload window in Cursor: Cmd/Ctrl + Shift + P β†’ "Reload Window"
# The conceptual search tools should now be available

Step 6: Test Conceptual Search

Try these example queries:

1. "What documents do we have?"
   β†’ Uses: catalog_search with concept expansion

2. "Find information about strategic thinking"
   β†’ Expands to: strategy, tactics, planning, decision making, etc.
   β†’ Returns: Relevant documents with concept matches

3. "Search for leadership principles"
   β†’ Finds: Documents about leadership, management, command, etc.
   β†’ Shows matched concepts and expanded terms

πŸ“š Data Seeding

Seed your documents with concept extraction:

# Set up environment
export OPENROUTER_API_KEY=your_key_here

# Run seeding with conceptual indexing
npx tsx hybrid_fast_seed.ts \
  --dbpath ~/.lance_mcp \
  --filesdir ~/Documents/your-pdfs \
  --overwrite

What's created:

  • Catalog table: Document summaries with embedded concepts
  • Chunks table: Detailed text segments for deep search
  • Concepts table: Extracted concepts with co-occurrence relationships

Features:

  • 🧠 Comprehensive: Extracts 100+ concepts per document (Claude Sonnet 4.5)
  • πŸ“ Fast summaries: Grok-4-fast for quick overviews
  • 🌐 WordNet enriched: Automatic synonym and hierarchy expansion
  • πŸ›‘οΈ Robust: Auto-skips corrupted PDFs, OCR fallback for scanned docs
  • πŸ’° Seeding cost: ~$4.80 per 100 documents (one-time)

πŸ“‹ Seeding Options

Required:

  • --dbpath: Directory to store the LanceDB database
  • --filesdir: Directory containing PDF files to process

Optional:

  • --overwrite: Recreate database from scratch (deletes existing data)
    • Without this flag: Only processes new or changed files (incremental mode)
    • With this flag: Reprocesses everything (useful for testing or upgrades)

Incremental vs Full Seeding:

# Incremental (recommended for updates) - Only new/changed files
npx tsx hybrid_fast_seed.ts --dbpath ~/.lance_mcp --filesdir ~/Documents/pdfs

# Full (initial setup or rebuild) - Process everything
npx tsx hybrid_fast_seed.ts --dbpath ~/.lance_mcp --filesdir ~/Documents/pdfs --overwrite

Time savings with incremental:

  • Initial 100 docs: ~25 minutes + ~$4.80
  • Add 10 new docs: ~3 minutes + ~$0.48 ✨
  • Add 1 new doc: ~15 seconds + ~$0.05 ✨

🎯 Example Queries

Conceptual search finds documents by meaning, not just keywords:

"What documents do we have?"
β†’ Lists catalog with AI summaries and extracted concepts

"Find information about strategic thinking"
β†’ Expands: strategy, tactics, planning, decision making
β†’ Finds: All documents with related concepts

"Search for leadership principles"  
β†’ Expands: leadership, management, command, authority
β†’ Returns: Chunks from ANY document about leadership

"How do threads synchronize?"
β†’ Expands: concurrency, mutex, semaphore, locks
β†’ Finds: Technical docs even without exact wording

πŸ“ Available Tools

The server provides 3 conceptual search tools:

πŸ—‚οΈ catalog_search

Search document summaries to find relevant sources

  • Query expansion with corpus concepts + WordNet
  • Returns: Documents with concept matches and scores

πŸ“„ chunks_search

Find specific information within a chosen document

  • Requires source parameter (document path)
  • Concept-aware search within single document

πŸ” broad_chunks_search

Search across ALL documents for detailed information

  • Returns: Top 10 most relevant chunks from entire corpus
  • Full conceptual expansion and multi-signal ranking

πŸ—οΈ Architecture

Documents 
    ↓
PDF Processing (with OCR fallback)
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚                   β”‚
Concept          Summary            Chunks
Extraction       Generation         Creation
(Sonnet 4.5)     (Grok-4-fast)     (Local)
    ↓                 ↓                 ↓
Concepts          Catalog           Chunks
Table             Table             Table
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
            Conceptual Search Engine
                 (5 signals)
                      β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚             β”‚             β”‚
    Corpus        WordNet       Hybrid
    Concepts      Synonyms      Scoring

πŸ› οΈ Development

File Structure

hybrid_fast_seed.ts              # Seeding with concept extraction
src/
β”œβ”€β”€ conceptual_index.ts          # MCP server entry point
β”œβ”€β”€ concepts/                    # Concept extraction & indexing
β”‚   β”œβ”€β”€ concept_extractor.ts    # LLM-based extraction
β”‚   β”œβ”€β”€ concept_index.ts         # Index builder
β”‚   β”œβ”€β”€ query_expander.ts        # Query expansion
β”‚   └── types.ts                 # Shared types
β”œβ”€β”€ wordnet/                     # WordNet integration
β”‚   └── wordnet_service.ts       # Python NLTK bridge
β”œβ”€β”€ lancedb/                     # Database clients
β”‚   └── conceptual_search_client.ts  # Search engine
└── tools/                       # MCP tools
    └── conceptual_registry.ts   # Tool registry

Testing

# Build project
npm run build

# Test with MCP Inspector
npx @modelcontextprotocol/inspector dist/conceptual_index.js ~/.lance_mcp

# Run concept extraction tests
npx tsx test/conceptual_search_test.ts

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes (ensure no API keys in code!)
  4. Run tests: npm run build and verify no errors
  5. Submit a pull request

πŸ’° Cost Breakdown

Seeding costs (OpenRouter):

  • Concept extraction: ~$0.041/doc (Claude Sonnet 4.5)
  • Summarization: ~$0.007/doc (Grok-4-fast)
  • Total: ~$0.048 per document

For 100 documents: ~$4.80
For 1,000 documents: ~$48

Runtime search: No additional API calls to OpenRouter (vector search is local)
Note: When used with AI agents (Cursor, Claude Desktop), the agent incurs costs for processing search results

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

LanceDB MCP Server for LLMS

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0