AryanAgarwal27
MCP Server
AryanAgarwal27
public

MultiContext RAG using MCP MCRAG

It is a multi-tool, retrieval-augmented generation (RAG) system that leverages **MCP (Model Context Protocol)** to integrate multiple web search and scraping agents. It uses LangChain to orchestrate OpenAI-powered agents across Tavily, Firecrawl, and Exa APIs, then enriches the responses using FAISS-powered RAG over live web content.

Repository Info

0
Stars
0
Forks
0
Watchers
0
Issues
Python
Language
Apache License 2.0
License

About This Server

It is a multi-tool, retrieval-augmented generation (RAG) system that leverages **MCP (Model Context Protocol)** to integrate multiple web search and scraping agents. It uses LangChain to orchestrate OpenAI-powered agents across Tavily, Firecrawl, and Exa APIs, then enriches the responses using FAISS-powered RAG over live web content.

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

# 🧠 MultiContext-RAG (MCRAG)

**MultiContext-RAG (MCRAG)** is a multi-tool, retrieval-augmented generation (RAG) system that leverages **MCP (Model Context Protocol)** to integrate multiple web search and scraping agents. It uses LangChain to orchestrate OpenAI-powered agents across Tavily, Firecrawl, and Exa APIs, then enriches the responses using FAISS-powered RAG over live web content.

---
### πŸ”Ή Main Streamlit UI

![Main UI](ui.png)

## ✨ Features

- πŸ” **Multi-Engine Web Search**
  - Tavily (general search)
  - Exa (developer/documentation search)
  - Firecrawl (real-time web info)
- 🌐 **Web Scraping & Content Parsing** via Firecrawl
- 🧠 **RAG (Retrieval-Augmented Generation)** using FAISS + LangChain
- πŸ’¬ **Streamlit UI** chat interface
- πŸ€– **Agent Memory** using LangChain’s `ConversationBufferMemory`
- πŸ”§ **@mcp.tool** decorators for modular tool exposure
- πŸ› οΈ **Modular structure** β€” easily extend or replace tools

---

## πŸ“ Project Structure

```
mcrag/
β”œβ”€β”€ app.py                  # Streamlit UI
β”œβ”€β”€ main.py                 # CLI entrypoint for testing RAG
β”œβ”€β”€ config.py               # Environment & API key loader
β”œβ”€β”€ mcp.py                  # Primary MCP agent class with tools
β”œβ”€β”€ mcp_implementation.py   # Alt LangChain agent executor (if needed)
β”œβ”€β”€ search_tools.py         # Tools for Tavily, Firecrawl, Exa (with @mcp.tool)
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ .env                    # Local API key storage (not committed)
β”œβ”€β”€ conversation_history.json # Saved chats (Streamlit)
```


---

## πŸš€ Getting Started

### 1. Clone the Repository
```bash
git clone https://github.com/your-org/mcrag.git
cd mcrag
```

### 2. Install Python Dependencies
```bash
pip install -r requirements.txt
```

If using FAISS and LangChain Community tools:
```bash
pip install faiss-cpu langchain_community
```

---

## πŸ” Environment Setup

Create a `.env` file in the root:

```env
OPENAI_API_KEY=your-key
TAVILY_API_KEY=your-key
FIRECRAWL_API_KEY=your-key
EXA_API_KEY=your-key
MODEL_NAME=gpt-4-turbo-preview
TEMPERATURE=0.7
MAX_SEARCH_RESULTS=5
```

---

## πŸ’¬ Run Streamlit UI

```bash
streamlit run app.py
```

Open your browser at [http://localhost:8501](http://localhost:8501)

---

### πŸ”Ή Response from Web Search + RAG

![Working Response](working_ui.png)


## πŸ§ͺ Run CLI Search + RAG

```bash
python main.py "what is model context protocol"
```

This will:
- Run a search via Exa
- Scrape contents from top links
- Perform RAG search over the scraped data
- Print both search + RAG results to terminal

---

## 🧠 How It Works

1. **User asks a question** in CLI or Streamlit
2. Agent chooses the best tool via `@mcp.tool`
3. Performs:
    - `tavily_search`
    - `exa_search`
    - `firecrawl_search`
4. Scrapes URLs via Firecrawl
5. Splits content with LangChain
6. Embeds using `OllamaEmbeddings` or OpenAI (configurable)
7. Stores & retrieves via FAISS
8. Renders result in UI or terminal

---

## 🧩 Key Components

### πŸ”Ή MCP (Model Context Protocol)
All tools are exposed as modular MCP tools using:

```python
from fastmcp import mcp

@mcp.tool
async def exa_search(query: str): ...
```

### πŸ”Ή LangChain Agent
Orchestrates tool usage with a prompt like:

```
"You are a helpful AI assistant with access to multiple search tools..."
```

### πŸ”Ή Tools
Defined in `search_tools.py`:
- `tavily_search`
- `exa_search`
- `firecrawl_search`

Each returns JSON: `status`, `results`, and `error`.

---

## πŸ“Έ Streamlit Chat Interface

> `app.py` implements a memory-based chat with real-time feedback and session saving.

UI Features:
- Send query
- Visualize response
- Save to `conversation_history.json`
- Clear/reset session

---

## πŸ§ͺ MCP Agent Class

In `mcp.py`, a class called `MCP` is declared as:

```python
@mcp.tool
class MCP:
    ...
```

This class:
- Instantiates the LLM
- Initializes memory
- Loads tools
- Handles message orchestration
- Has `.process_query()` and `.save_conversation()` methods

---

## πŸ“¦ Python Requirements

Minimal `requirements.txt`:

```txt
langchain==0.1.0
langchain-openai==0.0.2
python-dotenv==1.0.0
streamlit==1.29.0
tiktoken==0.5.2
tavily-python==0.2.6
firecrawl==2.1.2
exa-py==1.12.1
faiss-cpu
langchain_community
```

---

## πŸ’Ύ Saved Conversations

Stored in `conversation_history.json` whenever the user clicks "Save Conversation" in Streamlit.

Format:
```json
[
  { "role": "user", "content": "What is MCP?" },
  { "role": "assistant", "content": "MCP stands for Model Context Protocol..." }
]
```

---

## 🧠 Name Breakdown

- **MultiContext**: Inspired by the protocol’s emphasis on message-passing across tools
- **RAG**: Retrieval-augmented generation
- **MCRAG**: Powerful, plug-and-play architecture for agentic info retrieval

---

## πŸ“Œ To-Do / Ideas

- [ ] Add embeddings with Ollama or OpenAI switch
- [ ] Dockerize project
- [ ] Add automatic retry logic for failed tool calls
- [ ] Add PDF/Webpage ingestion from file

---

🧠 Happy building with MultiContext-RAG!

Quick Start

1

Clone the repository

git clone https://github.com/AryanAgarwal27/-MultiContext-RAG-using-MCP-MCRAG-
2

Install dependencies

cd -MultiContext-RAG-using-MCP-MCRAG-
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

OwnerAryanAgarwal27
Repo-MultiContext-RAG-using-MCP-MCRAG-
Language
Python
LicenseApache License 2.0
Last fetched8/8/2025

Recommended MCP Servers

πŸ’¬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
πŸ”—

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
πŸ•·οΈ

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers
⚑

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation