MCP PDF Server

MCP PDF Server

Enables AI assistants to query PDF documents by ingesting them into a vector database and generating answers grounded in the actual documents.

Category
访问服务器

README

📚 MCP PDF Server

An MCP (Model Context Protocol) server that lets AI assistants query your PDF documents. Drop your PDFs, ingest them into a vector database, and ask questions — answers are grounded in your actual documents.


✨ Features

  • 🔌 MCP-Compatible — Works with any MCP client (GitHub Copilot, Antigravity, etc.)
  • 📄 Auto PDF Discovery — Automatically finds, extracts, chunks, and embeds all PDFs in your folder
  • 🔍 Vector Search — Retrieves the most relevant passages before generating answers
  • 🐳 Docker-Ready — Runs as a containerized server with one command
  • 🗄️ Qdrant — Fast, open-source vector database for similarity search

🏗️ How It Works

┌─────────────┐     MCP (stdio)     ┌───────────────────┐     HTTP      ┌──────────┐
│ AI Assistant │◄───────────────────►│  MCP PDF Server   │◄────────────►│  Qdrant  │
│              │                     │                   │              │ Vector DB│
└─────────────┘                     │  1. Embed question │              └──────────┘
                                    │  2. Search vectors │
                                    │  3. Generate answer│   LLM API
                                    │                    │◄────────────►
                                    └───────────────────┘   (Embeddings
                                                            + Generation)
  1. You ask a question via your AI assistant.
  2. The server embeds the question using your choice of embedding model.
  3. It searches Qdrant for the top 5 most relevant text chunks from your PDFs.
  4. It generates an answer using an LLM, grounded in the retrieved context.

🚀 Quick Start

Prerequisites

1. Clone & Configure

git clone https://github.com/your-username/mcp-pdf-server.git
cd mcp-pdf-server

cp .env.example .env

Edit .env and set your API key:

API_KEY=nvapi-your_key_here

2. Start Qdrant

docker-compose up -d

3. Add Your PDFs & Ingest

Place your PDF documents in the pdfs/ folder, then:

npm install        # first time only
npm run ingest

All PDFs in the folder are automatically discovered and ingested.

4. Build the Server Image

docker build -t mcp-pdf-server .

5. Connect to Your AI Assistant

Add to your AI assistant's MCP config (e.g., mcp_config.json):

{
  "mcpServers": {
    "pdf-docs": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--network",
        "mcp-network",
        "-e",
        "API_KEY",
        "-e",
        "QDRANT_URL=http://mcp-qdrant:6333",
        "-e",
        "COLLECTION_NAME=documents",
        "-e",
        "EMBED_MODEL=nvidia/nv-embedqa-e5-v5",
        "-e",
        "GEN_MODEL=qwen/qwen2.5-coder-32b-instruct",
        "mcp-pdf-server"
      ],
      "env": {
        "API_KEY": "your_nvapi_key_here"
      }
    }
  }
}

Done! Ask your AI assistant any question about your documents.


🔧 Available Tools

Tool Description
ask_documents Ask any question. The server retrieves relevant context from your ingested PDFs and generates an answer.

⚙️ Environment Variables

Variable Description Default
API_KEY LLM API key (required)
EMBED_MODEL Embedding model nvidia/nv-embedqa-e5-v5
GEN_MODEL Generation model qwen/qwen2.5-coder-32b-instruct
COLLECTION_NAME Qdrant collection name documents
QDRANT_URL Qdrant connection URL http://localhost:6333
EMBED_BATCH_SIZE Chunks per embedding batch 15
EMBED_MAX_RETRIES Max retries on API failure 3
EMBED_COOLOFF_MS Cooldown between batches (ms) 500

Note: The .env file is used for local ingestion. The mcp_config.json passes env vars via Docker -e flags for the server.


📁 Project Structure

mcp-pdf-server/
├── pdfs/                     # Place your PDF documents here
├── src/
│   ├── server.ts             # MCP server entry point
│   ├── llm/
│   │   └── provider.ts       # LLM API client (embed + generate)
│   ├── vector/
│   │   └── qdrant.ts         # Qdrant client config
│   └── ingest/
│       ├── main.ts           # Ingestion orchestrator (auto-discovers PDFs)
│       ├── extract.ts        # PDF text extraction
│       ├── chunk.ts          # Text chunking
│       └── embed.ts          # Batch embedding & Qdrant insertion
├── docker-compose.yml        # Qdrant service
├── Dockerfile                # Server image
├── .env.example              # Env var template (safe to commit)
├── .gitignore                # Keeps secrets & binaries out of git
└── package.json

🛠️ Development

For local development with hot-reloading:

npm install
docker-compose up -d    # Start Qdrant
npm run dev             # Server with hot-reload

To use the local dev server with your AI assistant, change mcp_config.json to:

{
  "mcpServers": {
    "pdf-docs": {
      "command": "npx",
      "args": ["tsx", "src/server.ts"],
      "cwd": "/path/to/mcp-pdf-server",
      "env": {
        "API_KEY": "your_nvapi_key_here",
        "QDRANT_URL": "http://localhost:6333",
        "COLLECTION_NAME": "documents",
        "EMBED_MODEL": "nvidia/nv-embedqa-e5-v5",
        "GEN_MODEL": "qwen/qwen2.5-coder-32b-instruct"
      }
    }
  }
}

📝 Use Cases

This server works with any PDF knowledge base:

  • 📖 Technical books — Architecture, algorithms, system design
  • 📋 Company docs — Wikis, runbooks, policies
  • 📄 Research papers — Academic papers, whitepapers
  • 📑 Legal documents — Contracts, compliance
  • 🎓 Course material — Textbooks, lecture notes

🐛 Troubleshooting

Problem Solution
Server can't reach Qdrant docker ps — Ensure mcp-qdrant is running on mcp-network
Embeddings mismatch Changed EMBED_MODEL? Delete qdrant_storage/ and re-ingest
Rebuild server image docker build -t mcp-pdf-server . after code changes
Reset all data Delete ./qdrant_storage/ and re-run npm run ingest
Rate limiting Increase EMBED_COOLOFF_MS or decrease EMBED_BATCH_SIZE in .env
No PDFs found Ensure .pdf files are placed in the pdfs/ directory

📄 License

ISC

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选