rag-tool-agent
RAG Tool Agent —— MCP 服务器
它将 rag-tool-agent-demo 项目背后的两个工具——针对 FordA 数据集笔记的基于检索的问答,以及一个安全的算术计算器——暴露为一个正式的 Model Context Protocol 服务器。这样,任何兼容 MCP 的客户端——Claude Desktop、支持 MCP 的智能体框架或自定义主机——都可以直接调用它们,而不只是通过该项目自己的 CLI 或通过 rag-tool-api-docker 中的 Flask HTTP 封装器来调用。
构建它的目的是填补一个具体且明确的空白:当前一些 AI 工程师/智能体应用岗位的招聘信息明确要求具备 MCP 的实践经验(以及相关的智能体到智能体/智能体到 UI 协议)。这是一个小巧、真实且经过测试的实现,而不是一份没有证据支撑的协议经验声明。
为什么采用这种结构
原始智能体在内部自行完成路由——通过手写的 if/else 为每个传入问题决定是“计算器”、“检索”还是“直接回答”。MCP 反转了这一点:由客户端(LLM/智能体宿主)负责路由,它读取每个工具的名称、描述和 JSON-schema 参数,并决定调用哪一个。因此,本服务器不会重新实现原始的路由逻辑——而是将两种底层能力暴露为独立的、可单独调用的 MCP 工具,让任何 MCP 客户端自行路由到它们。这才是该协议的意义所在:工具变得与宿主无关,而不是硬编码进单个智能体的调度逻辑中。
search_notes(query: str) -> str—— 对一小段内嵌的、关于 FordA 数据集的笔记语料进行检索式查找,返回时带有与原始智能体相同的[Grounded in N retrieved chunk(s) from ...]溯源后缀,因此客户端可以区分有依据的回答与无依据的回答。它使用一个小型关键词重叠排序器,而不是重新构建原始项目的 FAISS/embeddings 索引——本项目的重点是 MCP 暴露层,而不是重复那部分工作。calculate(expression: str) -> str—— 算术工具,通过基于ast的安全求值器(而非对任意输入直接使用裸eval())限定为仅支持+ - * / ()和数字字面量。经验证,它会拒绝非算术输入以及类似__import__('os').system(...)的注入尝试。使用官方
mcpPython SDK(FastMCP)构建,也就是 Anthropic 为构建 MCP 服务器而发布的同一 SDK。
Related MCP server: rag-mcp
运行
pip install -r requirements.txt
python server.py它通过 stdio 运行——这是 Claude Desktop 等 MCP 客户端以子进程方式启动服务器并与之通信所采用的标准本地传输方式。要让 Claude Desktop 使用它,请在其 MCP 服务器配置中添加:
{
"mcpServers": {
"rag-tool-agent": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
}
}
}运行测试
pytest tests/ -v11 个测试全部通过——直接调用工具函数(对工具逻辑本身进行单元级覆盖时无需 MCP 传输):有依据的检索回答、grounding 计数契约、算术正确性(包括一个与原始智能体自身文档示例一致的除法示例)、对非算术输入和注入输入的拒绝、除零处理,以及带描述的工具自注册。
验证为真正的 MCP 服务器,而不只是函数
除单元测试之外,本项目还使用真正的 mcp 客户端 SDK(ClientSession + stdio_client)进行了端到端验证——将 server.py 作为实际子进程启动,完成 MCP initialize 握手,调用 list_tools(),并通过真实协议调用这两个工具:
TOOLS: ['search_notes', 'calculate']
calculate -> 1320 / (3601 + 1320) = 0.2682381629750051
search_notes -> The FordA dataset is a univariate time-series
classification dataset... [Grounded in 3 retrieved chunk(s) from
forda_dataset_notes.md]
calculate(injection) -> Error: could not evaluate "__import__('os')" ...这证实了该服务器确实支持真正的 MCP(握手、工具发现、工具调用),而不仅仅是底层 Python 函数能够独立工作。
与其他两个项目的关系
rag-tool-agent-demo—— 原始 CLI 智能体:LangChain、FAISS、Ollama、LCEL 检索链、计算器工具、LLM 驱动的路由。rag-tool-api-docker—— 该智能体的 Flask HTTP API 封装版本,已容器化(Docker、多阶段构建、非 root 用户、健康检查),并通过向运行中的容器发送真实 HTTP 请求进行了验证。本项目 —— 将相同的底层能力(检索、计算器)通过 MCP 而非 HTTP 暴露,因此任何 MCP 主机都可以调用它们,而不只是 REST 客户端。
This server cannot be deployed
Maintenance
Related MCP Connectors
Salesforce-grounded retrieval, diagnoses, and a vetted-Force marketplace for MCP clients.
Free OpenAI-compatible inference with signed provenance receipts and 3 focused MCP tools.
Find, vet, and run MCP tools through a secure audited gateway with prompt-injection risk scoring
Agentic search over your Dewey document collections from any MCP-compatible client.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables document search, read-only SQL querying, arithmetic calculation, and corpus introspection through MCP tools, allowing Claude to dynamically discover and chain these tools together to answer multi-step questions.-
- FlicenseNot gradedqualityCmaintenanceEnables querying local documents via retrieval-augmented generation, along with current UTC datetime and safe arithmetic evaluation through MCP tools over HTTP.-
- AlicenseAqualityCmaintenanceProvides a document store, web search, and safe calculator as MCP tools, enabling both offline and LLM-driven clients to discover and call them over the Model Context Protocol.6MIT
- FlicenseNot gradedqualityCmaintenanceEnables an LLM to perform safe arithmetic calculations and web searches through a standardized MCP interface, returning results to generate informed responses.-