nexacorp-mcp-agent
A Model Context Protocol server that exposes a hybrid RAG pipeline (dense+sparse retrieval with reranking) for querying an enterprise knowledge base, enabling autonomous agents to search and retrieve relevant information.
README
NexaCorp Agentic RAG with MCP & LangSmith
This project demonstrates a production-ready Agentic AI architecture. It features an advanced Hybrid RAG pipeline exposed as a standard Model Context Protocol (MCP) tool, an autonomous agent powered by Google's Gemini model, and full observability using LangSmith.
Built as part of an Agentic AI roadmap, this project moves beyond simple vector search by separating the retrieval engine (MCP Server) from the reasoning engine (Gemini Client) and tracking the entire flow with enterprise-grade tracing.
Architecture Highlights
- Model Context Protocol (MCP): The RAG pipeline is wrapped in an MCP server. This means the knowledge base acts as an independent tool that any MCP-compliant client (like Claude Desktop, Cursor, or custom agents) can securely query.
- Advanced Hybrid RAG:
- Dense Retrieval: FAISS with
all-MiniLM-L6-v2embeddings for semantic similarity. - Sparse Retrieval: BM25 for precise keyword matching.
- Reranking: Cross-Encoder (
ms-marco-TinyBERT-L-2-v2) to re-score and surface the most relevant chunks.
- Dense Retrieval: FAISS with
- Agentic Reasoning Engine: A Python client using LangChain and
gemini-2.5-flashthat autonomously decides when to query the MCP server and synthesizes the retrieved context into a natural language response. - Observability (LangSmith): Integrated LangSmith tracing to monitor LLM latency, token usage, tool-call success rates, and the exact context payloads sent between the agent and the MCP server.
System Components
server.py: The local MCP Tool Server. Initializes the Hybrid RAG pipeline, ingestssample_data.txt, and exposes asearch_knowledge_basetool via stdio.agent_client.py: The agent runtime. Connects to the local MCP server, sets up the Gemini LLM with tool-calling capabilities, and handles the chat loop.rag_pipeline.py: The core Hybrid Search logic.sample_data.txt: The mock enterprise knowledge base (NexaCorp policies, secrets, and IT rules).
Prerequisites
- Python 3.10+
- Google Gemini API Key
- LangSmith API Key (for observability)
Setup & Installation
-
Clone the repository:
git clone <your-repo-url> cd rag_project -
Install dependencies:
pip install langchain-google-genai mcp langchain langchain-community sentence-transformers faiss-cpu rank_bm25 python-dotenv -
Configure Environment Variables: Create a
.envfile in the root directory:GOOGLE_API_KEY=your_gemini_api_key_here # LangSmith Observability LANGCHAIN_TRACING_V2=true LANGCHAIN_PROJECT=nexacorp-rag-agent LANGCHAIN_API_KEY=your_langsmith_key_here LANGCHAIN_ENDPOINT=https://apac.api.smith.langchain.com # Only if using APAC region
Usage
Start the agent client. The client will automatically boot up the MCP server in the background and establish a connection.
python agent_client.py
Wait for the FAISS and SentenceTransformer models to load into memory (~20 seconds). Once the [Agent] Ready! prompt appears, you can ask questions like:
- "What is the guest wifi password?"
- "Who is the lead engineer for Project Crimson Falcon?"
- "Can I deploy code on Friday afternoon?"
Observability & Tracing
<img width="1917" height="767" alt="image" src="https://github.com/user-attachments/assets/c8062628-acb8-4f94-8544-e8986d7bf9f6" />
With LangSmith enabled, every interaction is logged. You can view the traces in your LangSmith dashboard to inspect:
- The raw prompt sent to Gemini.
- The exact JSON-RPC payload of the MCP tool call.
- The text chunks returned by the Hybrid RAG pipeline.
- Latency and token cost per query.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。