一个高性能的本地RAG(检索增强生成)系统,用Rust构建,通过模型上下文协议(MCP)与Claude Desktop集成。可直接在Claude对话中搜索和分析PDF文档,无需将数据发送到外部服务。
# 安装Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 安装Ollama
brew install ollama
# 安装Poppler(用于PDF解析)
brew install poppler
# 启动Ollama并安装嵌入模型
make setup-ollama
git clone
cd rust-local-rag
make install
将以下内容添加到 ~/Library/Application Support/Claude/claude_desktop_config.json
:
{
"mcpServers": {
"rust-local-rag": {
"command": "/Users/yourusername/.cargo/bin/rust-local-rag",
"env": {
"DATA_DIR": "/Users/yourusername/Documents/data",
"DOCUMENTS_DIR": "/Users/yourusername/Documents/rag",
"LOG_DIR": "/tmp/rust-local-rag",
"LOG_LEVEL": "info",
"LOG_MAX_MB": "10"
}
}
}
}
# 将PDF文件添加到文档目录
cp your-files.pdf ~/Documents/rag/
# 重启Claude Desktop
# 现在可以向Claude提问:“Search my documents for information about X”
# 安装Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 安装Ollama
brew install ollama
# 安装Poppler(用于PDF解析)
brew install poppler
# 启动Ollama并安装嵌入模型
make setup-ollama
git clone
cd rust-local-rag
make install
提供完整的安装和配置说明。
介绍Claude Desktop的集成和使用示例。
模型上下文协议(MCP) 是一种标准,允许像Claude这样的AI助手与外部工具和数据源进行交互。借助MCP,Claude不再局限于其训练数据,而是能够:
本实现利用了 rmcp
包——MCP的官方Rust SDK,创建了一个向Claude Desktop公开RAG功能的服务器。
┌─────────────────┐ MCP协议 ┌──────────────────┐
│ │ (stdin/stdout) │ │
│ Claude Desktop │ ◄─────────────────► │ Rust RAG │
│ │ │ MCP Server │
└─────────────────┘ └──────────────────┘
│
▼
┌──────────────────┐
│ 本地RAG栈 │
│ │
│ • PDF解析器 │
│ • Ollama │
│ • 向量存储 │
│ • 搜索引擎 │
└──────────────────┘
#[tool(tool_box)]
impl ServerHandler for RagMcpServer {
fn get_info(&self) -> ServerInfo {
// 向Claude提供服务器元数据
}
}
使用 rmcp
宏将RAG功能作为MCP工具公开:
#[tool(description = "Search through uploaded documents using semantic similarity")]
async fn search_documents(&self, query: String, top_k: Option<usize>) -> Result
#[tool(description = "List all uploaded documents")]
async fn list_documents(&self) -> Result
#[tool(description = "Get RAG system statistics")]
async fn get_stats(&self) -> Result
// 使用stdin/stdout传输进行Claude Desktop集成
let service = server.serve(stdio()).await?;
方面 | MCP方法 | HTTP API方法 |
---|---|---|
集成 | 原生支持Claude Desktop | 需要自定义客户端 |
安全性 | 进程隔离,无需网络 | 需要网络暴露 |
性能 | 直接的stdin/stdout IPC | 存在网络开销 |
用户体验 | 无缝的工具集成 | 需要手动管理API |
search_documents
list_documents
get_stats
欢迎贡献代码!本项目展示了实用的MCP服务器实现模式,可用于其他用例。
# 在开发模式下运行
make run
# 检查格式
cargo fmt --check
# 运行代码检查器
cargo clippy
本项目采用MIT许可证,请参阅 LICENSE 文件以获取详细信息。
用Rust精心打造 | 由MCP提供支持 | 注重隐私的RAG