multi-tenant-rag-mcp-server

chiatzenw-cur/multi-tenant-rag-mcp-server

3.1

If you are the rightful owner of multi-tenant-rag-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

A Model Context Protocol (MCP) server that provides Retrieval-Augmented Generation (RAG) capabilities with multi-tenant support.

Tools
4
Resources
0
Prompts
0

Collaborative RAG MCP Server

A Model Context Protocol (MCP) server that provides Retrieval-Augmented Generation (RAG) capabilities with multi-tenant support.

Features

  • Multi-tenant RAG: Support for multiple isolated tenants
  • Document Upload: Upload documents via file path or base64 encoding
  • Vector Search: Uses OpenAI embeddings and FAISS for similarity search
  • Multiple Formats: Supports PDF, DOCX, and plain text files
  • MCP Integration: Works with MCP-compatible clients like Claude Desktop

Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Set up your OpenAI API key in .env:
OPENAI_API_KEY=your_api_key_here

Usage

Integration with Cline

To use this MCP server with Cline:

  1. Clone or download this repository to your local machine
  2. Install dependencies as shown above
  3. Configure Cline to use this MCP server by adding it to your MCP configuration:
Option 1: Using mcp.json (Recommended)

Copy the provided mcp.json file to your Cline configuration directory, or add this server to your existing MCP configuration:

{
  "mcpServers": {
    "collaborative-rag": {
      "command": "python",
      "args": ["server.py"],
      "cwd": "/path/to/collaborative-rag-mcp-server",
      "env": {
        "OPENAI_API_KEY": "your_api_key_here"
      }
    }
  }
}
Option 2: Direct Cline Configuration

In Cline's settings, add this MCP server:

  • Server Name: collaborative-rag
  • Command: python
  • Arguments: ["server.py"]
  • Working Directory: /path/to/collaborative-rag-mcp-server
  • Environment Variables: OPENAI_API_KEY=your_api_key_here
  1. Restart Cline to load the new MCP server
  2. Use the tools in your Cline conversations:
    • create_tenant - Create a new tenant for document isolation
    • upload_document - Upload documents (PDF, DOCX, TXT)
    • query - Ask questions about uploaded documents
    • list_documents - List documents for a tenant

As Standalone MCP Server

Run the server for other MCP clients:

python server.py

Direct Python Usage

See demo.py for a complete example:

from server import create_tenant, upload_document, query
from server import CreateTenantParams, UploadParams, QueryParams
import base64, json

# 1. Create tenant
res = create_tenant(CreateTenantParams(name="my-tenant"))
tenant_name = json.loads(res.content[0].text)["tenant_name"]

# 2. Upload document
with open("document.txt", "rb") as f:
    b64 = base64.b64encode(f.read()).decode()

upload_document(UploadParams(
    tenant_id=tenant_name,
    filename="document.txt",
    mime_type="text/plain",
    base64=b64
))

# 3. Query
result = query(QueryParams(
    tenant_id=tenant_name,
    question="What is this document about?",
    top_k=5
))

answer = json.loads(result.content[0].text)
print(answer["answer"])

Demo

Run the demo to see the system in action:

python demo.py

This will:

  1. Create a tenant
  2. Upload a document with 3 facts
  3. Ask questions about each fact
  4. Display the AI-generated answers

Tools Available

  • create_tenant: Create a new tenant
  • upload_document: Upload and process documents
  • query: Ask questions about uploaded documents
  • list_documents: List documents for a tenant

Resources Available

  • rag://{tenant_id}/documents: List of documents for a tenant
  • rag://{tenant_id}/doc/{document_id}: Chunks of a specific document

Architecture

  • SQLite: Stores tenants, documents, chunks, and vector metadata
  • FAISS: In-memory vector index for fast similarity search
  • OpenAI: Embeddings and chat completion
  • FastMCP: MCP server framework