Skip to main content

r2r-mcp

Model Context Protocol (MCP) server for R2R (RAG to Riches) retrieval system

This package provides a FastMCP server that connects to R2R for advanced retrieval-augmented generation (RAG) capabilities. It enables AI assistants like Claude Desktop, Cursor, and other MCP clients to search, retrieve, and manage documents in R2R knowledge bases.

Features

  • 🔍 Semantic Search - Vector-based and full-text search across documents
  • 🤖 RAG Queries - Retrieval-augmented generation with configurable LLM settings
  • 📝 Document Management - Upload, update, and list documents with upsert semantics
  • 🏷️ Metadata Filtering - Advanced filtering by tags, domain, and custom metadata
  • 🌐 Environment-Based Config - Zero configuration, reads from environment variables

Installation

The easiest way to use r2r-mcp is with uvx, which automatically handles installation:

uvx r2r-mcp

Using pip

Install globally or in a virtual environment:

pip install r2r-mcp

Then run:

r2r-mcp

As a Python Module

You can also run it as a module:

python -m r2r_mcp

Configuration

The server automatically reads configuration from environment variables:

Variable Description Default
R2R_API_BASE or R2R_BASE_URL R2R server URL http://localhost:7272
R2R_COLLECTION Collection name for queries Server default
R2R_API_KEY API key for authentication None

Usage with MCP Clients

Cursor IDE

Add to .cursor/mcp.json:

{
  "mcpServers": {
    "KnowledgeBase": {
      "command": "uvx",
      "args": ["r2r-mcp"],
      "env": {
        "R2R_API_BASE": "http://localhost:7272",
        "R2R_COLLECTION": "aia-r1"
      }
    }
  }
}

Claude Desktop

Add to Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "r2r": {
      "command": "uvx",
      "args": ["r2r-mcp"],
      "env": {
        "R2R_API_BASE": "http://localhost:7272",
        "R2R_COLLECTION": "my-collection"
      }
    }
  }
}

Other MCP Clients

Any MCP client can use r2r-mcp by specifying the command and environment variables:

{
  "command": "uvx",
  "args": ["r2r-mcp"],
  "env": {
    "R2R_API_BASE": "http://localhost:7272"
  }
}

Available MCP Tools

Perform semantic and full-text search across documents.

Parameters:

  • query (str): Search query
  • filters (dict, optional): Metadata filters (e.g., {"tags": {"$in": ["agents"]}})
  • limit (int, optional): Maximum results
  • use_semantic_search (bool, optional): Enable vector search
  • use_fulltext_search (bool, optional): Enable full-text search

Example:

search("machine learning", filters={"tags": {"$in": ["research"]}}, limit=5)

2. rag

Retrieval-augmented generation with LLM.

Parameters:

  • query (str): Question to answer
  • filters (dict, optional): Metadata filters
  • limit (int, optional): Max search results to use
  • model (str, optional): LLM model name
  • temperature (float, optional): Response randomness (0-1)
  • max_tokens (int, optional): Max response length

Example:

rag("What is machine learning?", model="gpt-4", temperature=0.7)

3. put_document

Upload or update a document with upsert semantics.

Parameters:

  • content (str): Document text content
  • title (str): Document title
  • metadata (dict, optional): Custom metadata (e.g., {"tags": ["research"], "author": "John"})
  • document_id (str, optional): Explicit document ID

Example:

put_document(
    content="Machine learning is...",
    title="ML Guide",
    metadata={"tags": ["research", "ml"]}
)

4. list_documents

List documents with pagination.

Parameters:

  • offset (int, optional): Documents to skip (default: 0)
  • limit (int, optional): Max documents (default: 100)
  • document_ids (list[str], optional): Specific IDs to retrieve
  • compact_view (bool, optional): Show only ID and title (default: True)

Example:

list_documents(offset=0, limit=10, compact_view=False)

5. get_document

Retrieve a specific document by ID or title.

Parameters:

  • document_id (str, optional): Document ID
  • title (str, optional): Document title

Example:

get_document(title="ML Guide")

Metadata Filtering

All filter operators supported by R2R:

  • $eq: Equal
  • $neq: Not equal
  • $gt, $gte: Greater than (or equal)
  • $lt, $lte: Less than (or equal)
  • $in: In array
  • $nin: Not in array
  • $like, $ilike: Pattern matching (case-sensitive/insensitive)

Examples:

# Filter by tags
filters={"tags": {"$in": ["research", "ml"]}}

# Filter by domain
filters={"domain": {"$eq": "instructions"}}

# Combined filters
filters={"tags": {"$in": ["research"]}, "created_at": {"$gte": "2024-01-01"}}

Development

Local Installation

Install directly from PyPI:

pip install r2r-mcp

Or for the latest development version, install from source if you have the code locally:

pip install -e .

Running Tests

pip install -e ".[dev]"
pytest

Building for Distribution

python -m build

Requirements

  • Python >= 3.10
  • R2R server running and accessible
  • r2r Python SDK >= 3.6.0
  • mcp >= 1.0.0

License

MIT License - see LICENSE file for details

This package integrates with R2R (RAG to Riches) by SciPhi AI, which is also licensed under the MIT License. We gratefully acknowledge the R2R project and its contributors.

Support

For issues and questions, visit the package page: https://pypi.org/project/r2r-mcp/

Metadata

Release files for r2r-mcp 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for r2r-mcp 0.1.3
File Size Uploaded Provenance
r2r_mcp-0.1.3.tar.gz 11.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for r2r-mcp 0.1.3
File Interpreter ABI Platform
r2r_mcp-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.9 kB

Release files / r2r_mcp-0.1.3.tar.gz

Download URL r2r_mcp-0.1.3.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4ee03707bd85bc019fc4f61882064d726d68605ec8ff0a3f907121ea12b008e6
BLAKE2b-256 checksum
How to use checksums
866d8e90f6c905e2873d274bfd2ebe4c06f0e6502fd16039fb9d2ca5a3a63d91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / r2r_mcp-0.1.3-py3-none-any.whl

Download URL r2r_mcp-0.1.3-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff7b7903d0e408eefcf6f193cea88a6c049573410061a64c4d8ab77feff16c44
BLAKE2b-256 checksum
How to use checksums
38f02aa1b0e925b0d658e1eb025fdf1d998602102b166abc86ce577084c6bc51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for r2r-mcp 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page