
Rust Local RAG
STDIOLocal RAG system for PDF document search within Claude conversations using MCP.
Local RAG system for PDF document search within Claude conversations using MCP.
A high-performance, local RAG (Retrieval-Augmented Generation) system built in Rust that integrates with Claude Desktop via the Model Context Protocol (MCP). Search and analyze your PDF documents directly within Claude conversations without sending data to external services.
This project demonstrates how to build a production-ready MCP server using Rust that:
The Model Context Protocol (MCP) is a standard that allows AI assistants like Claude to interact with external tools and data sources. Instead of Claude being limited to its training data, MCP enables it to:
This implementation leverages the rmcp
crate - the official Rust SDK for MCP - to create a server that exposes RAG capabilities to Claude Desktop.
┌─────────────────┐ MCP Protocol ┌──────────────────┐
│ │ (stdin/stdout) │ │
│ Claude Desktop │ ◄─────────────────► │ Rust RAG │
│ │ │ MCP Server │
└─────────────────┘ └──────────────────┘
│
▼
┌──────────────────┐
│ Local RAG Stack │
│ │
│ • PDF Parser │
│ • Ollama │
│ • Vector Store │
│ • Search Engine │
└──────────────────┘
#[tool(tool_box)] impl ServerHandler for RagMcpServer { fn get_info(&self) -> ServerInfo { // Provides server metadata to Claude } }
Uses rmcp
macros to expose RAG functionality as MCP tools:
#[tool(description = "Search through uploaded documents using semantic similarity")] async fn search_documents(&self, query: String, top_k: Option<usize>) -> Result<CallToolResult, McpError> #[tool(description = "List all uploaded documents")] async fn list_documents(&self) -> Result<CallToolResult, McpError> #[tool(description = "Get RAG system statistics")] async fn get_stats(&self) -> Result<CallToolResult, McpError>
// Uses stdin/stdout transport for Claude Desktop integration let service = server.serve(stdio()).await?;
# Install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install Ollama brew install ollama # Install Poppler (for PDF parsing) brew install poppler # Start Ollama and install embedding model make setup-ollama
git clone <this-repository> cd rust-local-rag make install
Add to ~/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" } } } }
# Add PDFs to documents directory cp your-files.pdf ~/Documents/rag/ # Restart Claude Desktop # Now ask Claude: "Search my documents for information about X"
Aspect | MCP Approach | HTTP API Approach |
---|---|---|
Integration | Native Claude Desktop support | Requires custom client |
Security | Process isolation, no network | Network exposure required |
Performance | Direct stdin/stdout IPC | Network overhead |
User Experience | Seamless tool integration | Manual API management |
search_documents
list_documents
get_stats
Contributions are welcome! This project demonstrates practical MCP server implementation patterns that can be adapted for other use cases.
# Run in development mode make run # Check formatting cargo fmt --check # Run linter cargo clippy
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ in Rust | Powered by MCP | Privacy-focused RAG