检索增强生成MCP服务器

一款自托管的模型上下文协议(MCP)服务器,具备检索增强生成(RAG)能力,专为Mac用户设计,可通过本地文档扩展Claude的上下文窗口。

  • by abehmiel
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 abehmiel/personal-mcp-server

使用说明

配备RAG的个人MCP服务器

一个具有检索增强生成(RAG)功能的自托管模型上下文协议(MCP)服务器,专为希望使用自己的文档扩展Claude上下文窗口的Mac用户而设计。

这是什么?

该项目提供了 自托管MCP服务器 它允许Claude Desktop使用RAG技术访问和搜索您的个人知识库。无需外部API密钥-一切都在Mac上本地运行。

简单来说: 这就像给克劳德一个可搜索的文档、代码和笔记库,以便在对话中参考。

主要特点

  • 自托管:完全在Mac上运行-无需外部服务
  • RAG供电:使用检索增强生成进行智能文档搜索
  • Claude桌面集成:与Claude Desktop应用程序无缝协作
  • Mac优化:通过MPS自动加速苹果硅(M1/M2/M3)GPU
  • 矢量搜索:ChromaDB用于高效的语义搜索
  • 没有API密钥:所有处理都在本地进行
  • 类型安全:带有mypy验证的完整类型提示
  • 测试良好:综合测试套件,141项测试通过

为什么使用这个?

传统的人工智能对话受到上下文窗口的限制。此MCP服务器通过以下方式解决了这个问题:

  1. 为文档编制索引 进入本地矢量数据库
  2. 语义搜索 -即使没有精确的关键字匹配,也能找到相关内容
  3. 提供上下文 在对话过程中自动与克劳德
  4. 在本地运行 -你的数据永远不会离开你的机器

非常适合开发人员、研究人员、作家或任何有大量文档需要Claude参考的人。

快速开始

通过我们的自动化设置,让您的个人MCP服务器在5分钟内运行!

先决条件

在开始之前,请确保您已经:

  • macOS 11.0或更高版本(英特尔或苹果硅)
  • python 3.10或更高
  • 紫外线 -现代Python包管理器(v0.5.24+)
  • 克劳德桌面 已安装应用程序
  • 10GB+磁盘空间 用于依赖关系和向量数据库

一个命令设置

我们已经实现了整个设置过程的自动化!只需运行:

# Clone the repository
git clone https://github.com/yourusername/personal-mcp-server.git
cd personal-mcp-server

# Complete automated setup (installs dependencies + runs diagnostics)
make setup

# Configure Claude Desktop (interactive wizard)
make config

# That's it! Restart Claude Desktop (Cmd+Q, then reopen)

setup命令将:

  • 安装所有依赖项
  • 创建虚拟环境
  • 运行系统诊断程序
  • 验证一切正常

config命令将:

  • 自动检测项目路径
  • 创建正确的JSON配置
  • 备份现有配置
  • 提供明确的后续步骤

看看它在行动: 整个过程不到5分钟!

手动安装(替代)

如果您更喜欢手动设置或需要更多控制:

1.克隆和安装

# Navigate to where you want to install
cd ~/Projects

# Clone the repository
git clone https://github.com/yourusername/personal-mcp-server.git
cd personal-mcp-server

# Install dependencies (this may take a few minutes)
uv sync

# Verify installation
uv run pytest

您应该看到“141通过”,表示一切正常。

2.配置克劳德桌面

您可以使用自动向导:

make config

或者手动创建配置文件:

# Open the config file in your editor
nano ~/Library/Application\ Support/Claude/claude_desktop_config.json

添加此配置(替换 /path/to/ 根据您的实际路径):

{
  "mcpServers": {
    "rag-server": {
      "command": "/Users/YourUsername/.local/bin/uv",
      "args": [
        "run",
        "python",
        "-m",
        "rag_server.rag_mcp_chroma"
      ],
      "cwd": "/Users/YourUsername/Projects/personal-mcp-server",
      "env": {}
    }
  }
}

重要提示-用实际值替换这些路径:

  1. 项目路径: 替换 /Users/YourUsername/Projects/personal-mcp-server 使用您的实际项目路径

    • 通过运行以下命令找到它: pwd 在您的项目目录中
  2. 紫外线路径: 替换 /Users/YourUsername/.local/bin/uv 使用您的紫外线安装路径

    • 通过运行以下命令找到它: which uv
    • 常见位置:
      • /Users/YourUsername/.local/bin/uv (uv安装程序默认)
      • /opt/homebrew/bin/uv (苹果硅上的自制)
      • /usr/local/bin/uv (英特尔自制)

为什么是完整的路径? Claude Desktop不会继承您的完整系统PATH,因此您必须提供所有可执行文件的绝对路径。

3.重新启动克劳德桌面

完全退出并重新启动Claude Desktop以使更改生效。

验证它是否正常工作

运行系统诊断程序以确保一切配置正确:

make doctor

这将检查:

  • Python版本和位置
  • 紫外线装置
  • 虚拟环境
  • 依赖项
  • ChromaDB设置
  • Claude桌面配置
  • 还有更多!

在Claude Desktop中,查找锤子图标(🔨) 在输入区域。单击它以查看可用工具。您应该看到:

  • 搜索文档
  • add_文档
  • list_collections
  • 删除收集

祝贺您的MCP服务器现在已连接。

故障排除? 如果有什么不起作用, make doctor 会告诉你到底出了什么问题以及如何解决。

基本用法

添加文档

您可以使用自然语言通过Claude Desktop添加文档:

Can you add these documents to a collection called "my-notes":
- Document 1: "Python is a high-level programming language"
- Document 2: "Machine learning is a subset of AI"

或者以编程方式:

from rag_server.rag_mcp_chroma import RAGMCPServer

server = RAGMCPServer()
# Use server methods to add documents

用于添加整个项目的首选API

如果从该目录运行以下makefile命令,它将为整个项目目录建立索引 并尊重该项目的.gitignore,忽略该模式中的文件(对大量存储库有用 磁盘上的数据):

make index REPO=/path/to/repo COLLECTION=repo-name

事实上,您可以创建以下bash函数并将其放入.profile或类似文件中 使命令可用于索引当前项目目录。在主项目层次结构级别执行此操作, 在那里,您将拥有项目的.gitignore、README.md等,并替换“/path/to/personal mcp服务器” 使用此目录的绝对路径:

 # Personal RAG MCP server index
   indexme() {
       local repo_path="$PWD"
       local collection_name=$(basename "$PWD")
       local mcp_server_path="/path/to/personal-mcp-server"

       echo "📚 Indexing current directory..."
       echo "  Repository: $repo_path"
       echo "  Collection: $collection_name"
       echo ""

       # Navigate to the MCP server directory, run make, then return
       (cd "$mcp_server_path" && make index REPO="$repo_path" COLLECTION="$collection_name")

       local exit_code=$?
       if [ $exit_code -eq 0 ]; then
           echo ""
           echo "✅ Successfully indexed $collection_name"
       else
           echo ""
           echo "❌ Indexing failed with exit code $exit_code"
           return $exit_code
       fi
   }

搜索文档

让克劳德搜索您的文件:

Search my "my-notes" collection for information about Python

Claude将使用MCP服务器进行搜索并提供相关结果。

管理收藏

列出您的收藏:

What collections do I have in my knowledge base?

删除集合:

Delete the "old-notes" collection

可用工具

服务器提供以下MCP工具:

1.搜索_文档

使用语义搜索在文档集合中搜索。

参数:

  • query (string,必填):要搜索什么
  • collection (string,必填):要搜索哪个集合
  • n_results (整数,可选):结果数量(默认值:5)

2.添加文档

将新文档添加到集合中。

参数:

  • collection (字符串,必填):集合名称
  • documents (数组,必填):文档文本列表
  • metadatas (数组,可选):元数据对象列表

3.列表_集合

列出所有可用的集合和文档计数。

参数: 无

4.删除收集

从数据库中删除集合。

参数:

  • collection (字符串,必填):要删除的集合名称

项目结构

personal-mcp-server/
├── rag_server/                 # Main package
│   ├── __init__.py            # Package exports
│   ├── errors.py              # Custom exception classes
│   ├── logging_config.py      # Logging utilities
│   ├── rag_mcp_chroma.py      # MCP server implementation
│   ├── utils.py               # Device detection utilities
│   └── py.typed               # Type hint marker
├── tests/                      # Test suite
│   ├── conftest.py            # Pytest fixtures
│   ├── test_errors.py         # Error handling tests
│   ├── test_logging_config.py # Logging tests
│   └── test_utils.py          # Utility tests
├── docs/                       # Documentation
│   ├── CLAUDE.md              # AI assistant guide
│   ├── mcp-concepts.md        # MCP education
│   ├── rag-explained.md       # RAG education
│   ├── claude-desktop-setup.md # Integration guide
│   ├── usage-examples.md      # Practical examples
│   ├── troubleshooting.md     # Problem solving
│   └── development.md         # Contributor guide
├── pyproject.toml             # Project configuration
├── uv.lock                    # Dependency lock file
├── LICENSE                    # MIT License
└── README.md                  # This file

发展

我们使用一个全面的Makefile自动化了所有常见的开发任务。以下是最有用的命令:

快速参考

# Setup and configuration
make setup              # Complete first-time setup
make config             # Configure Claude Desktop
make doctor             # Run system diagnostics

# Testing
make test               # Run all tests
make test-fast          # Quick tests (skip slow ones)
make coverage           # Generate coverage report

# Code quality
make quality            # Run all quality checks
make format             # Auto-format code
make lint               # Check code style
make typecheck          # Type checking with mypy

# Development workflow
make watch-test         # Auto-run tests on file changes
make pre-commit-install # Install git hooks
make all-checks         # All checks before commit

# Utility
make clean              # Clean temporary files
make logs               # View server logs
make benchmark          # Run performance tests
make help               # See all commands

运行测试

# Recommended: Use make commands
make test               # Run all tests (141 tests)
make test-fast          # Skip slow tests (~15 seconds)
make coverage           # Generate HTML coverage report

# Alternative: Direct pytest
uv run pytest
uv run pytest --cov=rag_server --cov-report=html
uv run pytest tests/test_utils.py
uv run pytest -v

代码质量

# Recommended: Use make commands
make quality            # Lint + type check (fast)
make format             # Auto-format with ruff
make lint               # Check code style
make typecheck          # Run mypy

# Run all checks before committing
make all-checks         # Quality + tests

# Alternative: Direct commands
uv run ruff check .
uv run ruff check --fix .
uv run ruff format .
uv run mypy rag_server

日常开发工作流程

# Morning: Verify everything works
make doctor

# During development: Auto-run tests
make watch-test

# Before committing
make quality
make test-fast

# One-time: Install pre-commit hooks
make pre-commit-install
# Now quality checks run automatically on git commit!

独立运行服务器

# Recommended
make run                # Start server

# Alternative methods
uv run personal-mcp-server
uv run python -m rag_server.rag_mcp_chroma
make inspector          # Run queryable server over a webUI 

服务器在stdio模式下运行,通过标准输入/输出(专为MCP协议设计)进行通信。

查看所有命令: 跑 make help 查看40+开发人员命令的完整列表。

文档

提供全面的文档:

入门指南:

设置和集成:

用法和示例:

发展:

学习资源:

故障排除

第一步:运行诊断程序!

make doctor

这种全面的健康检查将自动诊断大多数问题并提供具体的修复。它检查:

  • Python版本和位置
  • 紫外线装置
  • 虚拟环境设置
  • 依赖项
  • ChromaDB配置
  • Claude桌面配置
  • MCP服务器导入
  • 系统资源

常见问题

Claude Desktop不显示工具

# Check configuration
make doctor

# View Claude Desktop logs
make logs

# Reconfigure if needed
make config

导入错误或找不到模块

# Reinstall dependencies
uv sync

# Verify installation
make test

性能问题

# Check performance metrics
make benchmark

# View diagnostics
make doctor

什么东西坏了?

# Clean and start fresh
make clean
make setup

# If still broken, emergency recovery
rm -rf .venv chroma_db
make setup

更多帮助

请参阅 详细的故障排除指南 全面的解决方案。故障排除文档按以下方式组织 make doctor 诊断类别,便于参考。

Mac特定优化

此项目针对Mac进行了优化:

  • 苹果硅技术支持:自动MPS(金属性能着色器)GPU加速
  • 兼容英特尔Mac:也适用于基于Intel的Mac
  • 原生车轮:ARM64滚轮,可更快地安装在M系列芯片上
  • 设备检测:自动选择最佳计算设备

服务器将在启动时记录它正在使用的设备。

系统要求

最低要求:

  • macOS 11.0+
  • Python 3.10+
  • 4GB内存
  • 10GB磁盘空间

推荐:

  • macOS 13.0+
  • Python 3.11+
  • 8GB+RAM(用于大型文档收藏)
  • 20GB+磁盘空间
  • 用于GPU加速的苹果Silicon Mac(M1/M2/M3)

贡献

欢迎投稿!我们通过自动化质量检查使贡献变得容易:

  1. 分叉存储库
  2. 创建要素分支: git checkout -b feature-name
  3. 通过测试进行更改
  4. 运行质量检查: make all-checks
  5. 用明确的消息提交(预提交钩子自动运行)
  6. 推送并创建拉取请求

开发人员体验功能:

  • make pre-commit-install -提交时自动运行质量检查
  • make watch-test -对文件更改自动运行测试
  • make quality -快速梳理和类型检查
  • make all-checks -推送前的全面检查

看 docs/development.md 详细的贡献指南。

路线图

当前状态:第4阶段已完成 (所有自动化和文件最终确定)

已完成的功能

  • ✅ 第一阶段:基础设施(Python、测试、类型安全)
  • ✅ 第二阶段:RAG实施(MCP服务器、ChromaDB、嵌入)
  • ✅ 第3阶段:开发人员体验(Makefile、自动化、诊断)
  • ✅ 第4阶段:文档(综合文档、示例、指南)

即将推出的功能

  • []高级文档分块策略
  • []元数据过滤和搜索细化
  • []多收藏搜索
  • []文档更新和版本控制
  • []用于代码库索引的CLI工具
  • [].mcpinore支持
  • []CI/CD管道(GitHub操作)
  • []Docker容器化
  • []性能优化

看 docs/CHANGELOG.md 查看详细的项目历史。

技术栈

  • 语言:Python 3.10+
  • MCP-SDK:官方Anthropic MCP Python SDK
  • 向量数据库:ChromaDB
  • 嵌入:句子转换器(全MiniLM-L6-v2)
  • 深度学习:支持MPS的PyTorch
  • 验证:Pydantic v2
  • 测试:支持asyncio的pytest
  • 代码质量拉夫,我的孩子
  • 包管理器:uv(防锈,快速)

安全与隐私

您的数据保留在您的计算机上:

  • 没有对嵌入的外部API调用
  • 没有数据发送到云服务
  • 所有处理都在本地进行
  • ChromaDB将数据存储在 ./chroma_db/ 默认情况下

您可以完全控制您的数据。

演出

性能因硬件而异:

苹果硅(M1/M2/M3):

  • 首次运行:2-3分钟(模型下载)
  • 后续运行:即时启动
  • 嵌入速度:~100个文档/秒
  • 搜索延迟:<100ms

英特尔Mac:

  • 首次运行:2-3分钟(模型下载)
  • 后续运行:即时启动
  • 嵌入速度:~30个文档/秒
  • 搜索延迟:<200ms

许可证

MIT许可证-请参阅 许可证 文件以获取详细信息。

版权所有(c)2025亚伯拉罕·哈米尔

致谢

支持

了解更多

MCP或RAG新手?看看这些教育指南:


状态:第4阶段完成✅ | 生产就绪🚀

快速链接:

由以下材料制成❤️ 为克劳德社区