RAG MCP Server

RAG MCP Server

Enables Claude Desktop to search custom knowledge bases using retrieval-augmented generation via a simple MCP tool.

Category
访问服务器

README

RAG MCP Server

A simple Model Context Protocol (MCP) server that provides RAG (Retrieval-Augmented Generation) capabilities to Claude Desktop. This allows Claude to search through your custom knowledge base!

🤔 What is MCP?

Model Context Protocol (MCP) is an open standard created by Anthropic that allows AI assistants like Claude to securely connect to external data sources and tools. Think of it as a way to give Claude superpowers by connecting it to your own data and APIs.

🎯 What Does This Server Do?

This MCP server exposes a search_rag tool that Claude Desktop can use to search through a knowledge base. In this example, it returns test data, but you can easily customize it to:

  • Query your own vector database
  • Search through your documents
  • Connect to your RAG API
  • Access any custom data source

🚀 Quick Start

New to this? Check out QUICKSTART.md for a simplified step-by-step guide!

Prerequisites

Step 1: Clone or Download This Repository

git clone https://github.com/torkian/rag-mcp-server.git
cd rag-mcp-server

Step 2: Install Dependencies

pip install -r requirements.txt

Step 3: Test the Server

Make sure the server runs correctly:

python server.py

You should see the server start. Press Ctrl+C to stop it.

Step 4: Configure Claude Desktop

Find your 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

Open the file and add this configuration (replace /path/to/ with your actual path):

{
  "mcpServers": {
    "rag-server": {
      "command": "python3",
      "args": ["/absolute/path/to/rag-mcp-server/server.py"]
    }
  }
}

Important: Use the absolute path to server.py!

Finding Your Python Path

If python3 doesn't work, find your Python path:

# macOS/Linux
which python3

# Windows (Command Prompt)
where python

Use the full path in your config, for example:

{
  "mcpServers": {
    "rag-server": {
      "command": "/usr/local/bin/python3",
      "args": ["/Users/yourname/rag-mcp-server/server.py"]
    }
  }
}

Step 5: Restart Claude Desktop

  1. Completely quit Claude Desktop (don't just close the window)
    • macOS: Press Cmd+Q or go to Claude → Quit
    • Windows: Right-click the system tray icon and select Quit
  2. Reopen Claude Desktop
  3. Look for the 🔌 icon at the bottom of the chat window - this means your MCP server is connected!

Step 6: Test It!

In Claude Desktop, try asking:

Use the search_rag tool to find information about Python

You should see Claude call your tool and return the test message!

📝 How to Customize

Option 1: Add Your Own Hardcoded Data

Edit server.py and modify the KNOWLEDGE_BASE list (lines 11-39):

KNOWLEDGE_BASE = [
    {
        "id": 1,
        "title": "Your Document Title",
        "content": "Your document content here..."
    },
    # Add more documents...
]

Then update the search_knowledge_base() function (line 45) to implement real search logic.

Option 2: Connect to Your API

Modify the search_knowledge_base() function to call your existing RAG API:

import httpx

def search_knowledge_base(query: str) -> list:
    # Call your API
    response = httpx.get(f"https://your-api.com/search?q={query}")
    return response.json()

Option 3: Connect to a Vector Database

Install a vector database client and query it:

# Example with Pinecone
import pinecone

def search_knowledge_base(query: str) -> list:
    # Query your vector database
    results = index.query(query, top_k=5)
    return results

🛠️ Project Structure

rag-mcp-server/
├── server.py                           # Main MCP server implementation
├── requirements.txt                    # Python dependencies
├── README.md                           # Full documentation (you are here!)
├── QUICKSTART.md                       # Simplified quick start guide
├── CONTRIBUTING.md                     # Contribution guidelines
├── LICENSE                             # MIT License
├── claude_desktop_config.example.json  # Example config (copy and modify)
└── .gitignore                          # Git ignore patterns

🔧 Troubleshooting

The 🔌 icon doesn't appear

  1. Check the config file path - make sure you edited the correct file
  2. Verify absolute paths - use full paths, not relative paths like ./server.py
  3. Check Python path - run which python3 (macOS/Linux) or where python (Windows)
  4. View logs - Claude Desktop logs errors to:
    • macOS: ~/Library/Logs/Claude/mcp*.log
    • Windows: %APPDATA%\Claude\Logs\mcp*.log

Server shows as connected but tool doesn't work

  1. Restart Claude Desktop completely after any code changes
  2. Test the server manually:
    python server.py
    
    It should start without errors

Permission errors

Make the server executable:

chmod +x server.py

Import errors

Make sure dependencies are installed:

pip install -r requirements.txt

If using virtual environments, activate it first:

# Create virtual environment
python -m venv venv

# Activate it
# macOS/Linux:
source venv/bin/activate
# Windows:
venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Then update your Claude Desktop config to use the virtual environment's Python:

{
  "mcpServers": {
    "rag-server": {
      "command": "/absolute/path/to/venv/bin/python",
      "args": ["/absolute/path/to/server.py"]
    }
  }
}

📚 Learn More

🤝 Contributing

Contributions are welcome! Feel free to:

  • Open issues for bugs or feature requests
  • Submit pull requests
  • Share your customizations

📄 License

MIT License - feel free to use this in your own projects!

💡 Example Use Cases

  • Personal knowledge base: Search your notes, documents, or research
  • Company documentation: Give Claude access to internal wikis or docs
  • Database queries: Connect to SQL/NoSQL databases
  • API integration: Bridge Claude with your existing APIs
  • Custom tools: Add any functionality you need!

🎓 How It Works

  1. Server starts: The Python server runs and waits for messages via stdin/stdout
  2. Claude connects: Claude Desktop reads the config and connects to your server
  3. Tool registration: The server tells Claude about the search_rag tool
  4. User asks: When you ask Claude to search, it calls the tool
  5. Server responds: Your server processes the request and returns results
  6. Claude uses results: Claude incorporates the results into its response

Built with ❤️ using the Model Context Protocol

Questions? Open an issue or check the MCP documentation!

推荐服务器

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 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

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

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

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

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

官方
精选