Manages environment configuration for the MCP server, specifically handling USER_ID and CONTENT_SERVICE_URL variables.
Used as the web framework for potential future REST API functionality within the MCP server.
Used for development workflows to enforce code quality standards through Git hooks.
Provides data validation for the MCP server's request and response structures.
Powers the testing framework for the MCP server, including unit tests and coverage reporting.
Provides fast Python linting capabilities for the codebase.
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:
- 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 files about the organization
- uploadContentUrlAboutOrganization - Upload content URLs about the organization
Prerequisites
Install uv
for fast Python package management:
Quick Start
The fastest way to get started:
Installation Options
Option 1: Using uv with pyproject.toml (Recommended)
Dependencies are automatically managed from pyproject.toml
:
Option 2: Using uv with inline dependencies
No configuration files needed - dependencies declared inline:
Option 3: Traditional Virtual Environment with uv
Configuration
- Copy the example environment file:
- Edit
.env
file with your configuration:
Usage
Running the MCP Server
Option 1: Using the uv startup script (recommended)
Script automatically detects pyproject.toml and uses it, falling back to inline dependencies
Option 2: Using the traditional startup script
Option 3: Direct execution with uv
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)
Using traditional approach
Development
Installing Development Dependencies
Code Formatting and Linting
Running Tests with pytest
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
searchOrganizationContents
deleteOrganizationContent
uploadContentFileAboutOrganization
uploadContentUrlAboutOrganization
Dependencies
mcp==1.0.0
- MCP Python SDKfastapi==0.115.5
- Web framework (for potential future REST API)uvicorn==0.32.1
- ASGI serverrequests==2.32.3
- HTTP client librarypython-multipart==0.0.17
- Multipart form data handlingpydantic==2.10.3
- Data validationpython-dotenv==1.0.1
- Environment variable management
Development Dependencies
pytest>=7.0.0
- Testing frameworkpytest-asyncio>=0.21.0
- Async testing supportpytest-cov>=4.0.0
- Coverage reportingblack>=23.0.0
- Code formattingruff>=0.1.0
- Fast Python lintermypy>=1.0.0
- Type checkingpre-commit>=3.0.0
- Git hooks
Dependencies are managed via pyproject.toml with uv for modern Python packaging
File Structure
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
Permission denied on scripts
Server won't start
- Check if the content service is running on the configured URL
- Verify environment variables in
.env
- Check Python version (requires Python 3.10+)
Missing dependencies
Dependencies are automatically managed by uv from pyproject.toml or inline declarations!
Related MCP Servers
- GoMIT License
- TypeScript
- PythonMIT License
- TypeScriptApache 2.0