
abvijaykumar/agentic-rag-mcp
API developmentAn intelligent RAG system that combines document search with web search using LLM-based tool calling.
Overview
An intelligent RAG system that combines document search with web search using LLM-based tool calling. The system automatically decides when to search the web based on document context quality and question requirements. This project was built as part of the Blog Hands on — Agentic RAG (3/3) — Agentic Integrated with MCP Server You can read the other 2 parts here * Hands on — Agentic RAG (1/3) * Hands on — Agentic RAG (2/3) — Agentic ReRanking RAG - : LLM evaluates document context and decides when web search is needed - : Web search via Model Context Protocol servers - : Parallel retrieval with LLM-based ranking - : Prioritizes local documents, uses web as intelligent fallback 1. : Retrieves relevant chunks from ingested PDFs 2. : LLM receives document context via system prompt 3. : LLM decides whether to call search_web tool 4. : If needed, searches web via MCP server 5.
README
Agentic RAG with MCP Web Search
An intelligent RAG system that combines document search with web search using LLM-based tool calling. The system automatically decides when to search the web based on document context quality and question requirements.
This project was built as part of the Blog Hands on — Agentic RAG (3/3) — Agentic Integrated with MCP Server
You can read the other 2 parts here
Features
- Smart Decision Making: LLM evaluates document context and decides when web search is needed
- MCP Integration: Web search via Model Context Protocol servers
- Multi-Candidate Retrieval: Parallel retrieval with LLM-based ranking
- Document-First Approach: Prioritizes local documents, uses web as intelligent fallback
Quick Start
-
Install dependencies:
pip install -r requirements.txt -
Set environment variables:
export OPENAI_API_KEY="your-openai-key" export MCP_ENDPOINT="http://localhost:8000" # Optional
How It Works
- Document Search: Retrieves relevant chunks from ingested PDFs
- Context Evaluation: LLM receives document context via system prompt
- Tool Decision: LLM decides whether to call
search_webtool - Web Search: If needed, searches web via MCP server
- Answer Generation: Combines document and web contexts
Architecture
- RAGOrchestrator: Main coordinator
- WebSearchAgent: MCP server communication
- RetrievalAgent: Multi-candidate document search
- RankingAgent: LLM-based answer selection
- Tool Calling: LLM decides when to search web
Read the blog for more details
Requirements
- Python 3.8+
- OpenAI API key
- MCP server (optional, for web search)
License
MIT License
Install
This server does not publish a one-line install command.
Open the repository installation guide New to MCP? Start with the mcpskill.org guide →