Content Server

Content Server

Stores Organizations content

Category
访问服务器

Tools

listContentNames

List all content names from the organization's database optionally filtered by name

searchOrganizationContents

Search through the organization's content database using semantic search

deleteOrganizationContent

Delete specific content from the organization's database

uploadContentFileAboutOrganization

Upload content file about the organization

uploadContentUrlAboutOrganization

Upload content url about the organization

README

RAG MCP Server (Python)

This is a Python implementation of the RAG (Retrieval-Augmented Generation) MCP (Model Context Protocol) server, equivalent to the Java version. It provides tools for managing organizational content through a content service API.

Features

The server provides the following MCP tools:

  1. listContentNames - List all content names from the organization's database, optionally filtered by name
  2. searchOrganizationContents - Search through the organization's content database using semantic search
  3. deleteOrganizationContent - Delete specific content from the organization's database
  4. uploadContentFileAboutOrganization - Upload content files about the organization
  5. uploadContentUrlAboutOrganization - Upload content URLs about the organization

Prerequisites

Install uv for fast Python package management:

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# or
pip install uv

Quick Start

The fastest way to get started:

# Run tests
./test_uv.sh

# Start the server
./run_server_uv.sh

Installation Options

Option 1: Using uv with pyproject.toml (Recommended)

Dependencies are automatically managed from pyproject.toml:

# Run directly (uv reads pyproject.toml automatically)
uv run mcp_server.py

# Or run tests
uv run test_server.py

# Install in development mode
uv sync

# Install with development dependencies
uv sync --dev

Option 2: Using uv with inline dependencies

No configuration files needed - dependencies declared inline:

# Run directly with inline dependencies
uv run \
    --with mcp==1.0.0 \
    --with fastapi==0.115.5 \
    --with uvicorn==0.32.1 \
    --with requests==2.32.3 \
    --with python-multipart==0.0.17 \
    --with pydantic==2.10.3 \
    --with python-dotenv==1.0.1 \
    mcp_server.py

Option 3: Traditional Virtual Environment with uv

# Create and activate virtual environment
uv venv
source .venv/bin/activate

# Install dependencies
uv pip install mcp==1.0.0 fastapi==0.115.5 uvicorn==0.32.1 requests==2.32.3 python-multipart==0.0.17 pydantic==2.10.3 python-dotenv==1.0.1

# Run the server
python mcp_server.py

Configuration

  1. Copy the example environment file:
cp env.example .env
  1. Edit .env file with your configuration:
USER_ID=your_user_id_here
CONTENT_SERVICE_URL=http://localhost:8080

Usage

Running the MCP Server

Option 1: Using the uv startup script (recommended)

./run_server_uv.sh

Script automatically detects pyproject.toml and uses it, falling back to inline dependencies

Option 2: Using the traditional startup script

./run_server.sh

Option 3: Direct execution with uv

# With pyproject.toml
uv run mcp_server.py

# Or with inline dependencies
uv run \
    --with mcp==1.0.0 \
    --with fastapi==0.115.5 \
    --with uvicorn==0.32.1 \
    --with requests==2.32.3 \
    --with python-multipart==0.0.17 \
    --with pydantic==2.10.3 \
    --with python-dotenv==1.0.1 \
    mcp_server.py

The server will start and listen for MCP protocol messages via stdin/stdout.

Environment Variables

  • USER_ID: The user ID to use for API calls (defaults to "invalid")
  • CONTENT_SERVICE_URL: The URL of the content service API (defaults to "http://localhost:8080")

Testing

Using uv (recommended)

./test_uv.sh
# or
uv run test_server.py  # Uses pyproject.toml

Using traditional approach

./run_server.sh  # This will set up venv and install dependencies
source .venv/bin/activate && python test_server.py

Development

Installing Development Dependencies

# Install all dependencies including dev tools
uv sync --dev

# This includes: pytest, black, ruff, mypy, pre-commit

Code Formatting and Linting

# Format code with black
uv run black .

# Lint with ruff
uv run ruff check .

# Type check with mypy
uv run mypy .

Running Tests with pytest

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov

# Run only unit tests
uv run pytest -m unit

Architecture

The Python MCP server consists of three main components:

1. RagService (rag_service.py)

  • Handles all HTTP API calls to the content service
  • Manages file uploads and URL submissions
  • Provides error handling and logging

2. RagTools (rag_tools.py)

  • Defines the MCP tools that are exposed to clients
  • Acts as a bridge between MCP tool calls and the RagService
  • Handles parameter validation and response formatting

3. MCP Server (mcp_server.py)

  • Implements the MCP protocol using the Python MCP SDK
  • Handles tool registration and execution
  • Manages the server lifecycle and communication

Tool Schemas

listContentNames

{
  "name": "listContentNames",
  "description": "List all content names from the organization's database optionally filtered by name",
  "inputSchema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "description": "Optional name filter to search for specific content"
      }
    }
  }
}

searchOrganizationContents

{
  "name": "searchOrganizationContents",
  "description": "Search through the organization's content database using semantic search",
  "inputSchema": {
    "type": "object",
    "properties": {
      "query": {
        "type": "string",
        "description": "The search query"
      }
    },
    "required": ["query"]
  }
}

deleteOrganizationContent

{
  "name": "deleteOrganizationContent",
  "description": "Delete specific content from the organization's database",
  "inputSchema": {
    "type": "object",
    "properties": {
      "contentId": {
        "type": "string",
        "description": "The ID of the content to delete"
      }
    },
    "required": ["contentId"]
  }
}

uploadContentFileAboutOrganization

{
  "name": "uploadContentFileAboutOrganization",
  "description": "Upload content file about the organization",
  "inputSchema": {
    "type": "object",
    "properties": {
      "file": {
        "type": "string",
        "description": "The file content to upload"
      },
      "fileName": {
        "type": "string",
        "description": "The file name"
      },
      "role": {
        "type": "string",
        "description": "The roles of the user"
      }
    },
    "required": ["file", "fileName"]
  }
}

uploadContentUrlAboutOrganization

{
  "name": "uploadContentUrlAboutOrganization",
  "description": "Upload content url about the organization",
  "inputSchema": {
    "type": "object",
    "properties": {
      "url": {
        "type": "string",
        "description": "The URL to upload"
      },
      "role": {
        "type": "string",
        "description": "The roles of the user"
      }
    },
    "required": ["url"]
  }
}

Dependencies

  • mcp==1.0.0 - MCP Python SDK
  • fastapi==0.115.5 - Web framework (for potential future REST API)
  • uvicorn==0.32.1 - ASGI server
  • requests==2.32.3 - HTTP client library
  • python-multipart==0.0.17 - Multipart form data handling
  • pydantic==2.10.3 - Data validation
  • python-dotenv==1.0.1 - Environment variable management

Development Dependencies

  • pytest>=7.0.0 - Testing framework
  • pytest-asyncio>=0.21.0 - Async testing support
  • pytest-cov>=4.0.0 - Coverage reporting
  • black>=23.0.0 - Code formatting
  • ruff>=0.1.0 - Fast Python linter
  • mypy>=1.0.0 - Type checking
  • pre-commit>=3.0.0 - Git hooks

Dependencies are managed via pyproject.toml with uv for modern Python packaging

File Structure

rag-mcp-py/
├── README.md              # This documentation
├── pyproject.toml         # Project configuration and dependencies
├── env.example           # Environment configuration template
├── .env                  # Environment configuration (create from template)
├── .gitignore           # Git ignore patterns
├── mcp_server.py        # Main MCP server implementation
├── rag_service.py       # HTTP service layer
├── rag_tools.py         # MCP tools definitions
├── test_server.py       # Test suite
├── run_server.sh        # Traditional startup script (creates .venv)
├── run_server_uv.sh     # uv-based startup script (recommended)
└── test_uv.sh          # uv-based test script

Comparison with Java Version

This Python implementation mirrors the functionality of the Java MCP server:

Java Component Python Equivalent Description
RagMcp.java mcp_server.py Main server application
RagTools.java rag_tools.py Tool definitions and handlers
RagService.java rag_service.py Business logic and API calls

The Python version maintains the same API contracts and tool schemas as the Java version, ensuring compatibility with existing MCP clients.

Why uv?

We use uv for package management because it's:

  • Fast: 10-100x faster than pip (installed 23 packages in 28ms!)
  • Reliable: Better dependency resolution
  • Modern: Built with Rust, designed for modern Python workflows
  • Flexible: Works with pyproject.toml, inline dependencies, or traditional approaches
  • Standards Compliant: Full support for PEP 621 and modern Python packaging

Troubleshooting

uv not found

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Restart your shell or source the path

Permission denied on scripts

chmod +x *.sh

Server won't start

  1. Check if the content service is running on the configured URL
  2. Verify environment variables in .env
  3. Check Python version (requires Python 3.10+)

Missing dependencies

Dependencies are automatically managed by uv from pyproject.toml or inline declarations!

推荐服务器

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

官方
精选