个人知识库MCP服务器

一个用于Claude桌面的个人知识库MCP服务器,支持上传多种文件格式并通过语义搜索查询文档内容,所有嵌入均在本地生成,保证数据隐私。

  • by Kamalesh-Kavin
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Kamalesh-Kavin/rag-mcp

使用说明

rag mcp

Claude Desktop的个人知识库MCP服务器。

插入文件(PDF、Markdown、纯文本、代码),并向Claude提出涵盖整个文档集合的问题。通过本地嵌入提供支持 奥拉玛 和 色度数据库 用于持久矢量存储。

特性

  • 为任何文档建立索引 --PDF, .md, .txt, .py, .js, .ts, .json, .yaml
  • 语义搜索 --按含义查找相关内容,而不仅仅是关键字
  • 本地和私人 --所有通过Ollama本地生成的嵌入(没有数据离开您的机器)
  • 持久 --ChromaDB保存到磁盘;仅在文档更改时重新索引
  • 重新索引安全 --对同一文件进行两次索引会干净地替换旧块

工具暴露给克劳德

工具 说明
index_document 将文件索引到知识库中
search_docs 跨所有索引文档的语义搜索
list_indexed_docs 列出当前索引中的每个文档
delete_document 删除文档及其所有块

资源: doc://{filename} --读取特定文档的所有原始块

需求

  • Python 3.13+
  • 紫外线
  • 奥拉玛 在本地运行 nomic-embed-text 拉:
    ollama pull nomic-embed-text
    

设置

git clone https://github.com/Kamalesh-Kavin/rag-mcp
cd rag-mcp
cp .env.example .env
uv sync

Claude桌面配置

将此添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "rag-assistant": {
      "command": "/path/to/uv",
      "args": [
        "--directory",
        "/path/to/rag-mcp",
        "run",
        "rag-mcp"
      ]
    }
  }
}

Claude中的用法

Index a document:
  "Index the file /Users/me/notes/architecture.md"

Ask a question:
  "What does my architecture doc say about the database layer?"

List what's indexed:
  "What documents are in my knowledge base?"

Delete a document:
  "Remove architecture.md from the knowledge base"

建筑

File on disk
    │
    ▼
read_file()          ← pypdf (PDF) or open() (text/code)
    │
    ▼
chunk_pages()        ← sliding window: 1000 chars, 200 overlap
    │
    ▼
embed_chunks()       ← POST http://localhost:11434/api/embeddings
    │                   nomic-embed-text → 768-dim vector
    ▼
VectorStore.add()    ← ChromaDB PersistentClient, cosine similarity
    │
    ▼
search_docs()        ← embed query → cosine nearest-neighbour lookup

项目结构

src/rag_mcp/
├── __init__.py
├── ollama_client.py   # async httpx wrapper for Ollama embeddings API
├── ingestion.py       # file readers, chunker, ingest pipeline
├── vector_store.py    # ChromaDB wrapper (add, search, list, delete)
└── server.py          # MCP server — 4 tools + 1 resource
data/documents/        # drop files here to index them

许可证

麻省理工学院