# R2R MCP

> R2R connects your AI agent directly to your private knowledge base. Execute vector searches, run precise Retrieval-Augmented Generation (RAG) queries, and manage documents without leaving your chat interface. It lets your agent ask questions against proprietary data—not just general web knowledge.

## Overview
- **Category:** friends-mcp
- **Price:** Free
- **Tags:** rag, vector-search, document-ingestion, knowledge-management, semantic-retrieval

## Description

This server connects your AI agent directly to your private knowledge base. You can run vector searches and execute precise Retrieval-Augmented Generation (RAG) queries without ever leaving your chat interface. It lets your agent ask questions against proprietary data—not just general web knowledge.

**Checking the System Status**

You start by verifying everything's running right with `get_health`. You call this tool to ping the R2R server, confirming its operational status and making sure it’s ready for vector operations. It gives you a clean confirmation that your connection is good to go.

**Mapping Out Your Data Inventory**

Before querying anything, you gotta know what data you're working with. You use `list_collections` when you need a rundown of all the distinct, organized document groups available in the entire system. This shows you the top-level categories of your knowledge. Next, if you select a specific collection, you run `list_documents`. This tool lists metadata and IDs for every ingested file within that selected grouping, giving you an inventory count and basic details for everything stored.

If you need to pull the full context—the actual content and deep metadata for one specific piece of writing—you use `get_document`, passing in a known document ID. This retrieves all the detailed information attached to that single file record.

**Performing Searches and Generating Answers**

You've checked the inventory; now you need answers. For a foundational understanding, you can run a semantic search using the `search` tool. It performs a deep similarity search across every ingested document, finding contextually relevant chunks of text based on *meaning*, not just matching keywords. This is how your agent figures out what's related to what.

When you need more than just a few snippets, you run advanced RAG queries using `rag_query`. This specialized tool executes the full Retrieval-Augmented Generation process, summarizing answers directly from multiple retrieved vector data chunks. It gives your agent a synthesized answer based on deep knowledge extraction, which is way better than simple search results.

**How You Use It in Practice**

Your AI client calls one of these tools—like `list_collections` to see what's available first, or `search` when you know the topic. The R2R server processes that request against your private vector store and sends back the clean data, context, or summarized answer right into your chat workflow for final use by your agent. It handles the complexity of proprietary data retrieval so you don't have to.

You control the entire process: checking status with `get_health`, scoping down your files using `list_collections` and then `list_documents`, pulling specific texts via `get_document`, finding relevant passages with `search`, or generating a comprehensive answer using `rag_query`. It keeps all this powerful, private data management right inside the chat interface.

## Tools

### get_document
Retrieves full details for a single, specified document using its ID.

### get_health
Pings the R2R server to confirm its operational status and readiness for use.

### list_collections
Returns a list of all distinct, organized document collections available in the system.

### list_documents
Lists metadata and IDs for every ingested file within a specified collection.

### rag_query
Executes a specialized RAG query to summarize knowledge based on vector data retrieval.

### search
Performs a semantic search against the document database, finding contextually relevant chunks of text.

## Prompt Examples

**Prompt:** 
```
Perform a vector search for 'Company Holiday Policy 2026'.
```

**Response:** 
```
Using the R2R server, I found 3 highly relevant snippets. The top hit from document `doc_7712a` states: 'In 2026, employees are granted 21 flexible floating days, bypassing old blackout windows.'
```

**Prompt:** 
```
Query the RAG engine to summarize known advanced RAG chunking strategies.
```

**Response:** 
```
I requested the summary directly from R2R via `rag_query`. The engine replied: 'Advanced strategies focus on semantic segmentation rather than standard character limits, utilizing markdown structure, sentence boundaries, and logical overlaps to retain context.'
```

**Prompt:** 
```
Verify the operational health of the R2R server.
```

**Response:** 
```
I executed the `get_health` probe. The R2R server replied with `status: ok` and is primed to accept vector operations.
```

## Capabilities

### Search Documents by Meaning
Performs semantic similarity searches across all ingested documents using the `search` tool.

### Generate Answers from Context
Runs advanced RAG queries via `rag_query`, summarizing answers based on retrieved vector data chunks.

### View Document Details
Retrieves specific metadata and content details for a known document using the `get_document` tool.

### Enumerate Available Data Sets
Lists all distinct document collections available in your R2R system via the `list_collections` tool.

### List All Indexed Files
Retrieves a list of every ingested document ID and its basic metadata using the `list_documents` tool.

### Check Server Status
Verifies if the R2R server is operational and ready to accept vector operations with `get_health`.

## Use Cases

### Onboarding a New Employee
A new data custodian needs to know all internal policies. Instead of asking three different people for documents, the agent runs `list_collections` first. Then, it uses `rag_query` to summarize the 'Remote Work Policy,' instantly compiling a single answer from multiple sources.

### Debugging an AI Knowledge Gap
An ML engineer suspects the AI is missing policy updates. They run `list_documents` for the 'HR Policies' collection to check the document IDs and metadata. If they don't see a recent file, they know where the data ingestion failed.

### Getting Quick Policy Answers
A user asks, 'What are our holiday float days for 2026?' The agent runs `search` with that query. R2R finds the top three relevant text snippets from the correct policy document and presents them directly.

### Pre-Flight Check on Data Integrity
A backend developer wants to ensure the system is ready for a major update. They first call `get_health` to verify status, then use `list_collections` to map out all current data silos before running any complex queries.

## Benefits

- Bypass manual API calls: You don't need to switch to Postman or write boilerplate Python code just to check a document ID. Use the `get_document` tool and get details instantly.
- Go beyond keywords: Instead of relying on simple keyword matching, use the `search` tool to perform semantic similarity queries. The agent finds answers based on meaning.
- Verify your data sources immediately: Before running complex reports, call `list_collections` or `list_documents`. This lets you verify that the correct documents were ingested and are available.
- Handle complex questions easily: When you need a summary of advanced concepts (like 'chunking strategies'), use `rag_query`. It handles the retrieval-and-summary pipeline for you.
- Immediate operational checks: Start every session by running `get_health`. This confirms the R2R server is up and ready, saving time diagnosing connection issues.

## How It Works

The bottom line is: it makes your private document collection an active source of truth for your AI client, requiring zero external scripting.

1. You enable the R2R integration, providing your specific Base URL and Authorization Key.
2. Your AI client recognizes a user request that requires internal knowledge (e.g., 'What was our policy on X?').
3. The agent calls the appropriate tool (`search` or `rag_query`), which sends the request to the R2R server, returning a summarized, context-grounded answer.

## Frequently Asked Questions

**What URL should I use for the R2R API URL?**
If you are running R2R locally via Docker, it's typically `http://localhost:7272`. If you are using SciPhi Cloud or have it deployed on your own infrastructure, provide the exact public or private endpoint.

**Do I need an R2R API Key?**
It depends on your deployment. Open deployments for local testing may not require a key. Production deployments or SciPhi Cloud environments require you to provide the generated key.

**What is the difference between RAG and Search?**
The `search` tool issues a standard vector similarity match—it returns relevant raw snippets from your database. The `rag_query` tool asks the R2R server to perform the search and compute an intelligent answer wrapping those snippets using an LLM.

**Are document ingestions possible via chat?**
No. This integration is designed for observational toolsets (listing documents, inspecting states, querying the index). Heavy ingestions of PDFs or websites should be handled through scripts or the dashboard.

**How do I verify that the R2R server is operational using the `get_health` tool?**
The `get_health` tool confirms active connectivity. A successful response, like `status: ok`, means your AI client can send vector operations without connection issues.

**What information does running `list_documents` provide about my knowledge base?**
`list_documents` gives you an inventory of every file ingested into the R2R system. It lists document IDs and names, allowing you to know what data is available before querying it.

**What should I do if my `rag_query` request fails or times out?**
If a query fails, check your server logs for specific errors. Large queries might hit rate limits; try breaking the task down into smaller chunks to prevent timeouts.

**Using `get_document`, what metadata can I retrieve about a single file?**
The `get_document` tool pulls specific details and attributes for one known document ID. You get structured data like creation dates, collection IDs, or author info.