GenAIHub
Back to Labs
Advanced

MCP + Claude Desktop

Download Lab Files

Connect a local MCP server to Claude Desktop app. Process PDFs automatically and use semantic search directly from Claude.

What You'll Learn

PDF Processing

Automatically extract text from PDFs and create embeddings

Claude Desktop Integration

Configure MCP servers for Claude Desktop app

Semantic Search

Query your documents using natural language

Source Tracking

Each result includes PDF source metadata

Workflow

graph LR PDF[PDFs] --> GEN[generate_vector_db.py] GEN --> KB[knowledge_base.json] GEN --> FAISS[FAISS Index] CLAUDE[Claude Desktop] -->|MCP| SERVER[mcp_vector_server.py] SERVER --> FAISS SERVER --> RESULTS[Search Results]

Step 1: Environment Setup

# Navigate to the directory
cd Handson/MCP-Claude-Desktop

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Verify installation
python3 -c "import faiss; import mcp; import PyPDF2; print('✅ Ready!')"

Step 2: Add Your PDFs

Place your PDF documents in the data/PDF/ folder:

# Create the folder structure
mkdir -p data/PDF

# Copy your PDFs
cp /path/to/your/documents/*.pdf data/PDF/

# Your structure should look like:
# data/PDF/
# ├── document1.pdf
# ├── document2.pdf
# └── ...

Step 3: Generate Vector Database

python3 generate_vector_db.py

# Expected output:
# ============================================================
# 🚀 FAISS Vector DB Generator from PDFs
# ============================================================
# 📂 Found 2 PDF file(s) in: data/PDF
# 📄 Processing: document1.pdf
#    ✓ Extracted 15 chunks
# 📄 Processing: document2.pdf
#    ✓ Extracted 12 chunks
#
# ✅ FAISS vector DB created successfully!
# 📁 Location: data/faiss_index
# 📦 Entries: 27 | Dimensions: 384

Texts are split into ~1000 char chunks with 200 char overlap for better retrieval.

Edit the Claude Desktop configuration file:

macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%\Claude\claude_desktop_config.json
Linux:
~/.config/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "vector-db": {
      "command": "/ABSOLUTE/PATH/.venv/bin/python3",
      "args": ["/ABSOLUTE/PATH/mcp_vector_server.py"],
      "env": {
        "PYTHONPATH": "/ABSOLUTE/PATH/MCP-Claude-Desktop"
      }
    }
  }
}

Important: Use absolute paths! Restart Claude Desktop (Cmd+Q) after editing.

Step 5: Use in Claude Desktop

In Claude Desktop, ask it to search your documents:

# Example prompt in Claude Desktop:
"Search 'quality principles' using search_vector_db with 
index_dir='/path/to/data/faiss_index' and top_k=3"

# Expected response:
1) score=0.8234
[Source: company-handbook.pdf]
Critical TechWorks Quality (Quality, Reliability, and Resilience):
We ensure delivery of high-quality software...

Learning Checklist

Quick Quiz

What must you do after editing claude_desktop_config.json?

Correct! Claude Desktop must be fully restarted to load the new MCP configuration.
Not quite. You must restart Claude Desktop (Cmd+Q or completely quit) after editing the config.

"Server not found"

Check paths are absolute. Verify Python path with which python3

"faiss.index missing"

Run python3 generate_vector_db.py first

"BrokenPipeError"

Wait a few seconds after opening Claude Desktop before using tools

Check logs at: ~/Library/Logs/Claude/mcp-server-vector-db.log