LangChain Agent RAG MCP
An MCP server integrating LangChain, RAG, and Agent to provide knowledge retrieval and tool invocation through natural language.
README
<<<<<<< HEAD
LangChain Agent Project
这是一个从零逐步成长的 LangChain 项目,当前先完成最小 RAG 示例。
目录
agent.md:项目主说明src/minimal_rag.py:第二阶段 RAG 入口src/rag_stage2.py:第二阶段核心实现models/m3e-base/:本地 embedding 模型目录data/sample_docs/:示例文档
环境
固定使用名为 agents 的 Python 虚拟环境。
python -m venv agents
agents\Scripts\Activate.ps1
=======
# LangChain Agent RAG MCP
这是一个逐步演进的 LangChain + RAG + Agent + MCP 项目,当前已完成到 Phase 4。
## 项目结构
- `src/minimal_rag.py`:Phase 2 RAG 入口
- `src/agent_stage3.py`:Phase 3 工具调用入口
- `src/mcp_stage4.py`:Phase 4 MCP 服务入口
- `src/test_stage2.py`:Phase 2 smoke test
- `src/test_agent_stage3.py`:Phase 3 smoke test
- `src/test_mcp_stage4.py`:Phase 4 smoke test
- `agent.md`:阶段规划与最新进展
## 环境准备
统一使用 conda 的 `agents` 环境,路径为 `D:\Pyenvs\py310\agents`。
```powershell
conda activate agents
>>>>>>> 9c9be64 (已完成第三步的工具接入)
python -m pip install -r requirements.txt
配置
<<<<<<< HEAD
复制 .env.example 为 .env,然后填写 OpenAI 兼容中转站配置。
如果你使用的是中转站接口,记得把 OPENAI_BASE_URL 改成你的代理地址。
embedding 只从项目内 models/m3e-base 读取,不再访问 Hugging Face。
运行
=======
复制 .env.example 为 .env,填写 OpenAI 兼容接口配置。
如果使用中转站或代理,请把 OPENAI_BASE_URL 改成实际地址。
使用方式
Phase 2:
9c9be64 (已完成第三步的工具接入)
python -m src.minimal_rag --question "这个项目现在支持什么?"
<<<<<<< HEAD
测试
先跑结构测试:
python -m src.test_stage2
再跑完整问答:
python -m src.minimal_rag --question "这个项目现在支持什么?"
当前能力
- 读取示例文档
- 切分文本
- 使用本地
m3e-base建立向量检索 - 基于检索结果生成回答
- 返回来源引用
- 检索不到时会明确兜底
第三阶段
已完成工具调用骨架,入口位于 src/agent_stage3.py。
运行方式:
python -m src.agent_stage3 --question "这个项目现在支持什么?"
环境说明
当前项目统一使用 conda 创建的 agents 环境,实际位置为 D:\Pyenvs\py310\agents。
后续运行前请先执行:
conda activate agents
最新进展
- 已确认并记录
agentsconda 虚拟环境位置:D:\Pyenvs\py310\agents - 已完成第三阶段的工具调用骨架,
src.agent_stage3可正常运行 - 后续开发统一以
conda activate agents后的环境为准
第一批工具
knowledge_base_search:基于本地 RAG 资料检索回答project_summary:输出项目当前阶段、环境和进展摘要sample_docs_index:列出示例文档并展示简短预览
测试方法
在 agents 环境中执行:
conda activate agents
python -m src.test_agent_stage3
如果你想单独验证 agent 入口,也可以运行:
python -m src.agent_stage3 --question "这个项目现在支持什么?"
更新说明
- 第一批工具已补充输入输出约束和异常兜底
src.test_agent_stage3已加入真实 agent 路由测试,可验证模型按问题自动选不同工具 ======= Phase 3:
python -m src.agent_stage3 --question "这个项目现在支持什么?"
Phase 4:
python -m src.mcp_stage4
如果要在终端里看到常驻服务:
python -m src.mcp_stage4 --transport streamable-http --host 127.0.0.1 --port 8000
测试方法
conda activate agents
python -m src.test_stage2
python -m src.test_agent_stage3
python -m src.test_mcp_stage4
使用注意事项
stdio模式是给 MCP 客户端连接的,不要在终端里手动输入内容。http://127.0.0.1:8000/返回 404 是正常的,真正入口是/mcp。- 新对话里如果无法调用 MCP,优先检查 Codex 是否真的配置到了当前项目里的
src.mcp_stage4。 - 运行前一定先激活
agents环境。 - 现在项目知识已经收口到
README.md和agent.md,不再依赖额外 Markdown 资料。
当前能力
- 基础问答
- RAG 检索增强
- Agent 工具调用
- MCP 接入
测试文档
当前 RAG 测试资料放在 data/laser_tracker_docs/,用于激光跟踪仪前沿研究的示例检索。
如果要新增测试资料,直接在这个目录里添加新的 .md 文件即可。
9c9be64 (已完成第三步的工具接入)
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.