PDF RAG MCP Server

PDF RAG MCP Server

A document knowledge base system that enables users to upload PDFs and query them semantically through a web interface or via the Model Context Protocol, allowing integration with AI tools like Cursor.

Category
访问服务器

README

PDF RAG MCP Server

<img width="600" alt="image" src="https://github.com/user-attachments/assets/3aeb102a-6d7f-4d58-a15b-129e640b2e35" />

<img width="1614" alt="image" src="https://github.com/user-attachments/assets/2b6e12c0-48f1-49f8-8d50-db03da2d1ee8" />

A powerful document knowledge base system that leverages PDF processing, vector storage, and MCP (Model Context Protocol) to provide semantic search capabilities for PDF documents. This system allows you to upload, process, and query PDF documents through a modern web interface or via the MCP protocol for integration with AI tools like Cursor.

Features

  • PDF Document Upload & Processing: Upload PDFs and automatically extract, chunk, and vectorize content
  • Real-time Processing Status: WebSocket-based real-time status updates during document processing
  • Semantic Search: Vector-based semantic search across all processed documents
  • MCP Protocol Support: Integrate with AI tools like Cursor using the Model Context Protocol
  • Modern Web Interface: React/Chakra UI frontend for document management and querying
  • Fast Dependency Management: Uses uv for efficient Python dependency management

System Architecture

The system consists of:

  • FastAPI Backend: Handles API requests, PDF processing, and vector storage
  • React Frontend: Provides a user-friendly interface for managing documents
  • Vector Database: Stores embeddings for semantic search
  • WebSocket Server: Provides real-time updates on document processing
  • MCP Server: Exposes knowledge base to MCP-compatible clients

Quick Start

Prerequisites

  • Python 3.8 or later
  • uv - Fast Python package installer and resolver
  • Git
  • Cursor (optional, for MCP integration)

Quick Installation and Startup with uv and run.py

  1. Clone the repository:

    git clone https://github.com/yourusername/PdfRagMcpServer.git
    cd PdfRagMcpServer
    
  2. Install uv if you don't have it already:

    curl -sS https://astral.sh/uv/install.sh | bash
    
  3. Install dependencies using uv:

    uv init .
    uv venv
    source .venv/bin/activate
    uv pip install -r backend/requirements.txt
    
  4. Start the application with the convenient script:

    uv run run.py
    
  5. Access the web interface at http://localhost:8000

  6. Using with Cursor

Go Settings -> Cursor Settings -> MCP -> Add new global MCP server, paste below into your Cursor ~/.cursor/mcp.json file. See Cursor MCP docs for more info.

{
  "mcpServers": {
    "pdf-rag": {
      "url": "http://localhost:7800/mcp"
    }
  }
}

You could also change localhost into the host ip you deployed the service. After this confige added to the mcp json, you will see the mcp server showes at the Cursor mcp config page, switch it on to enable the server:

<img width="742" alt="image" src="https://github.com/user-attachments/assets/d9b2c97c-c535-4d2a-bcf1-2d2c6343aeb3" />

Building the Frontend (For Developers)

If you need to rebuild the frontend, you have two options:

Option 1: Using the provided script (recommended)

# Make the script executable if needed
chmod +x build_frontend.py

# Run the script
./build_frontend.py

This script will automatically:

  • Install frontend dependencies
  • Build the frontend
  • Copy the build output to the backend's static directory

Option 2: Manual build process

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Build the frontend
npm run build

# Create static directory if it doesn't exist
mkdir -p ../backend/static

# Copy build files
cp -r dist/* ../backend/static/

After building the frontend, you can start the application using the run.py script.

Simple Production Setup

For a production environment where the static files have already been built:

  1. Place your pre-built frontend in the backend/static directory
  2. Start the server:
    cd backend
    uv pip install -r requirements.txt
    python -m app.main
    

Development Setup (Separate Services)

If you want to run the services separately for development:

Backend

  1. Navigate to the backend directory:

    cd backend
    
  2. Install the dependencies with uv:

    uv pip install -r requirements.txt
    
  3. Run the backend server:

    python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
    

Frontend

  1. Navigate to the frontend directory:

    cd frontend
    
  2. Install the dependencies:

    npm install
    
  3. Run the development server:

    npm run dev
    

Usage

Uploading Documents

  1. Access the web interface at http://localhost:8000
  2. Click on "Upload New PDF" and select a PDF file
  3. The system will process the file, showing progress in real-time
  4. Once processed, the document will be available for searching

Searching Documents

  1. Use the search functionality in the web interface
  2. Or integrate with Cursor using the MCP protocol

MCP Integration with Cursor

  1. Open Cursor
  2. Go to Settings → AI & MCP
  3. Add Custom MCP Server with URL: http://localhost:8000/mcp/v1
  4. Save the settings
  5. Now you can query your PDF knowledge base directly from Cursor

Troubleshooting

Connection Issues

  • Verify that port 8000 is not in use by other applications
  • Check that the WebSocket connection is working properly
  • Ensure your browser supports WebSockets

Processing Issues

  • Check if your PDF contains extractable text (some scanned PDFs may not)
  • Ensure the system has sufficient resources (memory and CPU)
  • Check the backend logs for detailed error messages

Project Structure

PdfRagMcpServer/
├── backend/               # FastAPI backend
│   ├── app/
│   │   ├── __init__.py
│   │   ├── main.py        # Main FastAPI application
│   │   ├── database.py    # Database models
│   │   ├── pdf_processor.py # PDF processing logic
│   │   ├── vector_store.py # Vector database interface
│   │   └── websocket.py   # WebSocket handling
│   ├── static/            # Static files for the web interface
│   └── requirements.txt   # Backend dependencies
├── frontend/              # React frontend
│   ├── public/
│   ├── src/
│   │   ├── components/    # UI components
│   │   ├── context/       # React context
│   │   ├── pages/         # Page components
│   │   └── App.jsx        # Main application component
│   ├── package.json       # Frontend dependencies
│   └── vite.config.js     # Vite configuration
├── uploads/               # PDF file storage
└── README.md              # This documentation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选