evgenygurin/r2r-mcp-server
If you are the rightful owner of r2r-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.
The R2R MCP Server provides a standardized interface to expose R2R's RAG capabilities to AI assistants.
R2R MCP Server
Model Context Protocol server for R2R - Expose R2R's powerful RAG capabilities to AI assistants through a standardized MCP interface.
Current Status
| Component | Status | Location |
|---|---|---|
| R2R API | 🟢 Running | http://34.134.54.139:7272 |
| FastMCP Cloud | 🟢 Deployed | https://r2r-mcp-server.fastmcp.app/mcp |
| Docker Container | 🟢 Running | r2r-mcp-server (healthy) |
| Local Environment | 🟢 Ready | venv/ configured |
Quick Setup Options:
-
FastMCP Cloud (Recommended) - Connect to hosted server with API key:
# See "Alternative: Connect to FastMCP Cloud" section below # No local setup required! -
Local Setup - Run server locally:
./setup-cursor.sh # Run this first, then configure Cursor
Overview
This MCP server provides AI assistants (like Claude) with access to R2R's production-ready RAG system, including:
- Document Management: Upload, list, delete, update documents
- Hybrid Search: Semantic, keyword, and combined search strategies
- RAG & Agents: Question answering with citations and conversational agents
- Collections: Organize documents into logical groups
- Knowledge Graphs: Extract and query entity-relationship graphs
Quick Start
1. Installation
cd mcp_server
# Install dependencies
pip install -r requirements.txt
# OR use uv (recommended)
uv pip install -r requirements.txt
2. Configuration
Create a .env file (or set environment variables):
# R2R Connection
R2R_BASE_URL=https://api.136-119-36-216.nip.io # or http://localhost:7272
R2R_EMAIL=your@email.com
R2R_PASSWORD=your_password
# Optional: MCP Server Settings
MCP_SERVER_NAME=R2R MCP Server
MCP_LOG_LEVEL=INFO
MCP_CACHE_TTL=300
See .env.example for all configuration options.
3. Run the Server
# Run directly
python server.py
# Or make it executable
chmod +x server.py
./server.py
The server runs using stdio transport (standard for MCP).
4. Configure in Claude Desktop (Local Server)
For local server, add to your Claude Desktop MCP configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"r2r-local": {
"command": "python3",
"args": ["/absolute/path/to/r2r_mcp_server/server.py"],
"env": {
"R2R_BASE_URL": "http://34.134.54.139:7272",
"R2R_EMAIL": "your@email.com",
"R2R_PASSWORD": "your_password"
}
}
}
}
For FastMCP Cloud (recommended), see "Alternative: Connect to FastMCP Cloud" section below.
Restart Claude Desktop. The R2R tools should now be available!
Alternative: Connect to FastMCP Cloud ☁️
Instead of running the server locally, you can connect to the hosted R2R MCP Server on FastMCP Cloud at https://r2r-mcp-server.fastmcp.app/mcp.
Benefits:
- ✅ No local setup required
- ✅ Always available (24/7)
- ✅ Automatic updates
- ✅ API key authentication
Getting Your API Key
- Visit FastMCP Cloud
- Sign in with your GitHub account
- Navigate to your deployed
r2r-mcp-serverproject - Go to Settings → API Keys
- Generate a new API key
- Copy and use it in your client configuration
Security Note: Keep your API key secure and never commit it to version control.
For Claude Desktop (Cloud Connection)
Claude Desktop requires a local proxy to connect to FastMCP Cloud. The proxy file r2r_cloud_proxy.py is included in this repository and connects to https://r2r-mcp-server.fastmcp.app/mcp.
Add to your Claude Desktop MCP configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"r2r-cloud": {
"command": "python3",
"args": ["/Users/laptop/dev/r2r_mcp_server/r2r_cloud_proxy.py"],
"env": {
"MCP_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
Note:
- Replace the path in
argswith the absolute path tor2r_cloud_proxy.pyon your system - Replace
YOUR_API_KEY_HEREwith your actual API key from FastMCP Cloud - Restart Claude Desktop completely after saving the configuration
For Cursor IDE
Add to ~/.cursor/mcp.json or your workspace MCP configuration:
{
"mcpServers": {
"r2r-cloud": {
"url": "https://r2r-mcp-server.fastmcp.app/mcp",
"transport": "streamable-http",
"headers": {
"Authorization": "Bearer YOUR_API_KEY_HERE"
}
}
}
}
Note: Replace YOUR_API_KEY_HERE with your actual API key from FastMCP Cloud.
For Cline (VS Code Extension)
Add to VS Code settings or Cline configuration:
{
"mcpServers": {
"r2r-cloud": {
"url": "https://r2r-mcp-server.fastmcp.app/mcp",
"transport": "http",
"headers": {
"Authorization": "Bearer YOUR_API_KEY_HERE"
}
}
}
}
Alternative: Using FastMCP CLI (Easier for Claude Desktop)
If you have fastmcp installed, you can automatically configure Claude Desktop:
# Install fastmcp if needed
pip install fastmcp
# Create .env file with your API key
echo "MCP_API_KEY=your-api-key-here" > .env
# Install the proxy server
fastmcp install claude-desktop r2r_cloud_proxy.py --name "r2r-cloud" --env-file .env
This will automatically configure Claude Desktop with the correct paths and environment variables.
Restart Your Client
After adding the configuration:
- Claude Desktop: Restart the application
- Cursor: Reload the window or restart Cursor
- Cline: Reload VS Code window
The R2R MCP Server tools should now be available in your AI assistant!
Benefits of FastMCP Cloud
- ✅ No local setup required - Connect immediately from any device
- ✅ Always available - 24/7 uptime with automatic scaling
- ✅ Automatic updates - Server updates on every push to
main - ✅ SSL/TLS encryption - Secure HTTPS connections
- ✅ API key authentication - Built-in access control
- ✅ Free tier during beta - No cost for development and testing
Agent Rules & Development Guidelines
This repository includes comprehensive agent rules that are automatically detected by AI coding assistants like Codegen, Claude Code, Cursor, and others.
📋 Available Rule Files
| File | Purpose | Auto-detected by |
|---|---|---|
AGENTS.md | Primary agent rules (preferred default) | Codegen, Claude Code, compatible assistants |
.cursorrules | Cursor IDE-specific rules | Cursor IDE |
CLAUDE.md | Comprehensive development documentation | Claude Code, Codegen |
🎯 What These Rules Cover
- FastMCP Development Standards - Pre-commit workflow, code quality standards
- Critical Architecture Patterns - Singleton client, configuration system, error handling
- Tool Development Workflow - Step-by-step guide for adding new MCP tools
- R2R SDK v3+ API Patterns - Correct usage of R2R SDK
- Testing Best Practices - Async testing, in-memory transport patterns
- Known Issues & Workarounds - Common problems and solutions
🤖 For AI Assistants
The agent rules provide context about:
- Mandatory code patterns (never violate)
- Pre-commit validation workflow
- Tool return format conventions
- Error handling standards
- Testing requirements
👥 For Human Developers
See:
AGENTS.md- Quick reference and core principlesCLAUDE.md- Comprehensive development guide with examples.env.example- Environment configuration options
🔄 Rule Hierarchy (when using Codegen)
When multiple rules exist, preference order is:
- User Rules - Your personal coding preferences
- Repository Rules - This project's standards (AGENTS.md, .cursorrules, CLAUDE.md)
- Organization Rules - Team-wide standards
All rule files are automatically discovered and included in agent context when working on this repository.
Available Tools
🗂️ Document Management
| Tool | Description |
|---|---|
upload_document | Upload files or text to R2R knowledge base |
list_documents | List documents with filtering and pagination |
delete_document | Remove documents from R2R |
update_document_metadata | Modify document metadata |
get_document | Get full document details |
🔍 Search
| Tool | Description |
|---|---|
search | Hybrid/vector/keyword search across documents |
advanced_search | Advanced strategies (HyDE, RAG-Fusion) + graph search |
🤖 RAG & Agents
| Tool | Description |
|---|---|
rag_query | Ask questions with document retrieval and citations |
agent_query | Advanced agent with tools and multi-step reasoning |
conversation_rag | Conversational RAG with memory |
📚 Collections
| Tool | Description |
|---|---|
create_collection | Create document collections |
list_collections | List all collections |
get_collection_info | Get collection details |
add_to_collection | Add documents to collections |
remove_from_collection | Remove documents from collections |
delete_collection | Delete collections (preserves documents) |
🕸️ Knowledge Graphs
| Tool | Description |
|---|---|
extract_knowledge_graph | Extract entities and relationships from documents |
graph_search | Search the knowledge graph |
update_graph_entities | Update or merge graph entities |
get_entity_details | Get detailed entity information |
ℹ️ System
| Tool | Description |
|---|---|
get_system_status | Check R2R connection and server health |
help_getting_started | Get comprehensive usage guide |
Common Workflows
Basic RAG Workflow
1. Check connection:
get_system_status()
2. Upload document:
upload_document(file_path="/path/to/document.pdf")
3. Search for information:
search(query="authentication methods")
4. Ask questions:
rag_query(query="How do I implement OAuth2 authentication?")
Organizing with Collections
1. Create collection:
create_collection(name="api-docs", description="API documentation")
2. Upload to collection:
upload_document(
file_path="/path/to/doc.pdf",
collection_ids=["collection_id"]
)
3. Search within collection:
search(query="...", collection_ids=["collection_id"])
Building Knowledge Graphs
1. Upload documents:
upload_document(file_path="/path/to/doc.pdf")
2. Extract graph:
extract_knowledge_graph(
document_id="doc_id",
entity_types=["Person", "Technology", "Organization"]
)
3. Query graph:
graph_search(query="technologies used for authentication")
Conversational RAG
1. Start conversation:
result1 = agent_query(query="What is OAuth2?")
conv_id = result1["conversation_id"]
2. Follow up (maintains context):
agent_query(
query="How does it differ from API keys?",
conversation_id=conv_id
)
3. Continue conversation:
agent_query(
query="Show me implementation examples",
conversation_id=conv_id
)
Tool Usage Tips
Search Best Practices
- Hybrid search (default): Best for general queries
- Vector search: For conceptual/semantic queries
- Keyword search: For exact matches (IDs, names, specific terms)
- Start with
limit=5-10, increase if needed - Use
collection_idsto narrow search scope
RAG Best Practices
- Use
search_limit=3-5for focused answers - Use
search_limit=10-20for comprehensive answers - Set
temperature=0.0for factual, deterministic responses - Set
temperature=0.7-1.0for creative explanations - Check
sourcesin response for citation verification
Collection Organization
- Create collections BEFORE uploading documents
- Use descriptive names:
api-docs,legal-contracts,research-papers - Add rich metadata during upload for better filtering
- Documents can belong to multiple collections
Knowledge Graph Tips
- Extract graphs from clean, well-structured documents first
- Specify
entity_typesandrelation_typesfor focused extraction - Update/merge entities to improve graph quality over time
- Combine graph search with document search for best results
Response Format
All tools return a dictionary with:
{
"status": "success" | "error",
"formatted": "Human-readable output",
"next_steps": ["Suggested next actions"],
# Tool-specific fields...
}
Success Response Example
{
"status": "success",
"document_id": "abc123",
"message": "Document uploaded successfully...",
"formatted": "Human-readable message with next steps",
"next_steps": [
"search(query='...')",
"rag_query(query='...')",
]
}
Error Response Example
{
"status": "error",
"error": "Error description with context",
"suggestion": "How to fix the issue"
}
Architecture
mcp_server/
├── server.py # Main MCP server (FastMCP)
├── config.py # Configuration management
├── requirements.txt # Python dependencies
├── tools/ # MCP tool implementations
│ ├── documents.py # Document management
│ ├── search.py # Search operations
│ ├── rag.py # RAG and agent queries
│ ├── collections.py # Collection management
│ └── graphs.py # Knowledge graph operations
├── utils/ # Utilities
│ ├── client.py # R2R client singleton
│ └── formatting.py # Response formatting
└── tests/ # Tests (future)
Configuration Reference
Environment Variables
| Variable | Default | Description |
|---|---|---|
R2R_BASE_URL | http://localhost:7272 | R2R API URL |
R2R_EMAIL | None | Authentication email |
R2R_PASSWORD | None | Authentication password |
MCP_SERVER_NAME | R2R MCP Server | Server display name |
MCP_LOG_LEVEL | INFO | Logging level |
MCP_CACHE_TTL | 300 | Cache TTL in seconds |
MAX_CONCURRENT_REQUESTS | 10 | Max concurrent requests |
REQUEST_TIMEOUT | 60 | Request timeout (seconds) |
ENABLE_CACHING | True | Enable response caching |
ENABLE_RATE_LIMITING | True | Enable rate limiting |
Troubleshooting
Connection Issues
# Check R2R server is running
curl $R2R_BASE_URL/v3/health
# Test authentication
# (see R2R docs for auth endpoints)
# Check MCP server configuration
python server.py
# Should show "Connected to R2R at ..." in logs
Tool Call Failures
- Authentication errors: Check
R2R_EMAILandR2R_PASSWORD - Not found errors: Use
list_documents()orlist_collections()first - Timeout errors: Reduce
limitparameter or simplify query - Network errors: Verify
R2R_BASE_URLand network connectivity
Debugging
# Enable debug logging
export MCP_LOG_LEVEL=DEBUG
python server.py
# Check tool registration
python -c "from server import mcp; print([t.name for t in mcp.list_tools()])"
# Test R2R client directly
python -c "from utils.client import get_r2r_client; client = get_r2r_client(); print(client.system.health())"
Development
Adding New Tools
- Create tool function in appropriate
tools/*.pyfile:
async def my_new_tool(param: str) -> dict:
"""
Clear, AI-friendly description of what this tool does.
Args:
param: Parameter description
Returns:
dict: Response format
"""
from utils.client import get_r2r_client
from utils.formatting import format_error_message
try:
client = get_r2r_client()
# Implementation...
return {"status": "success", ...}
except Exception as e:
return {
"status": "error",
"error": format_error_message(e, "context")
}
- Import and register in
server.py:
from tools.module import my_new_tool
mcp.tool(my_new_tool)
- Test the tool:
python server.py
# Check that tool appears in registered tools list
Testing
# Run tests (future)
pytest tests/
# Manual testing
python
>>> from tools.search import search
>>> import asyncio
>>> result = asyncio.run(search(query="test"))
>>> print(result)
Examples
See examples/ directory (future) for:
- Complete workflow examples
- Integration with Claude Desktop
- Advanced use cases
- Custom tool development
Contributing
Contributions welcome! Please:
- Follow existing code style and patterns
- Add comprehensive docstrings (AI-friendly descriptions)
- Include error handling and formatting
- Update documentation
License
This MCP server is part of the R2R project. See R2R license for details.
Resources
- R2R Documentation: https://r2r-docs.sciphi.ai
- FastMCP Documentation: https://github.com/jlowin/fastmcp
- MCP Protocol: https://modelcontextprotocol.io
- R2R GitHub: https://github.com/SciPhi-AI/R2R
- R2R Discord: https://discord.gg/p6KqD2kjtB
Support
- Issues: https://github.com/SciPhi-AI/R2R/issues
- Discord: https://discord.gg/p6KqD2kjtB
- Documentation: https://r2r-docs.sciphi.ai
Built with: