mcp-context
mcp-context
本地 模型上下文协议 (MCP) 服务器,提供代码仓库的语义搜索 (RAG) 功能。将多个项目的上下文暴露给外部 AI 客户端(如 Claude.ai、Gemini、Claude Code),无需在每次会话时手动重新传递上下文。
技术栈: Python · FastMCP · Qdrant · sentence-transformers · Next.js · Docker · Cloudflare Tunnel
前置要求
在继续之前,请确保已安装以下项目:
工具 | 最低版本 | 检查命令 |
Python | 3.11 |
|
Docker | 24.0 |
|
Docker Compose | 2.20 |
|
Node.js | 18.0 |
|
npm | 9.0 |
|
Git | 任意 |
|
cloudflared | 任意 |
|
远程连接(阶段 3)需要一个拥有活跃域名的 Cloudflare 账户。
Related MCP server: MCP Codebase RAG Server
安装
# 1. Clone the repository
git clone https://github.com/ericlimabr/mcp-context.git
cd mcp-context
# 2. Copy the environment variables file
cp .env.example .env
# 3. Run setup — installs Python dependencies via uv and starts Qdrant
make setup关于
GITHUB_TOKEN的说明:.env文件包含一个用于读取仓库权限的GITHUB_TOKEN变量。要获取此令牌,请前往 GitHub Settings > Developer settings > Personal access tokens。生成一个新令牌并将其粘贴到你的.env文件中。
配置
1. 环境变量
编辑在上一步中创建的 .env 文件:
# Root path where your projects are stored on the machine
PROJECTS_ROOT=/home/your-user/projects
# Access password for the administrative panel
ADMIN_PASSWORD=choose-a-strong-password2. 配置 Cloudflare Tunnel
# Authenticate cloudflared with your Cloudflare account
cloudflared tunnel login
# Create the permanent tunnel
cloudflared tunnel create mcp-context
# Associate with your subdomain (replace yourdomain.com)
cloudflared tunnel route dns mcp-context mcp.yourdomain.com在项目根目录下创建 cloudflared/config.yml(此文件已被 gitignore 忽略)。将 <id> 替换为上述 tunnel create 命令输出的 UUID:
tunnel: mcp-context
credentials-file: /home/your-user/.cloudflared/<id>.json
ingress:
- hostname: mcp.yourdomain.com
service: http://localhost:17800
- service: http_status:4043. 创建前端
此步骤仅需执行一次。它会创建 Next.js 项目并自动移除内部的 .git/:
make frontend-setup4. 索引第一个项目
打开前端,添加项目路径并触发索引:
make frontend
# Access http://localhost:17801或者直接从终端运行索引器:
make index本地运行(开发)
要启动带有自动重载功能的 MCP 服务器(开发时推荐):
make dev这将启动 Qdrant、Cloudflare Tunnel 以及启用了热重载的 MCP 服务器。服务器会在 server/ 中的任何文件发生更改时自动重启。
要在后台启动所有服务(MCP 服务器、前端、隧道、Qdrant):
make server-dev可用服务:
服务 | URL |
MCP 服务器 | |
前端(管理 + 仪表盘) | |
Qdrant (API) |
实时日志可在 logs/ 中查看:
tail -f logs/server.log # MCP server
tail -f logs/frontend.log # frontend
tail -f logs/tunnel.log # Cloudflare Tunnel
make qdrant-logs # Qdrant停止所有服务:
make stop本地部署(所有服务在容器中)
要完全容器化运行项目——适用于模拟生产环境或通过 Docker 一起启动所有服务:
# First time: build the images
make prod-build
# Start all containers
make prod-up
# Stop everything
make prod-down
# Real-time logs
make prod-logs警告: 在运行
prod-up之前,请确保.env中的PROJECTS_ROOT指向正确的目录。MCP 服务器容器会挂载该路径以访问本地文件。
Make 命令
命令 | 描述 |
| 首次运行:通过 uv 安装依赖并启动 Qdrant |
| 在 |
| 启动 Qdrant + 隧道 + 带自动重载的 MCP 服务器 |
| 在后台启动所有服务 |
| 停止所有开发服务 |
| 仅启动 MCP 服务器(端口 17800) |
| 仅启动 Next.js 前端(端口 17801) |
| 仅启动 Cloudflare Tunnel |
| 运行索引工作进程 |
| 通过 Docker Compose 启动 Qdrant |
| 停止 Qdrant |
| 实时查看 Qdrant 日志 |
| 构建所有 Docker 镜像 |
| 启动所有容器 |
| 停止所有容器 |
| 实时查看所有容器的日志 |
仓库结构
mcp-context/
├── server/ # MCP Server (FastMCP/SSE, port 17800)
│ ├── main.py # Entrypoint and MCP configuration
│ ├── tools/ # MCP tool definitions (planned)
│ ├── resources/ # MCP resource definitions (planned)
│ └── embeddings.py # Local embedding model loading (planned)
├── indexer/ # Project indexing worker (planned)
│ ├── worker.py # Orchestrates indexing
│ ├── chunker.py # Function-scope chunking
│ └── qdrant_client.py # Qdrant client abstraction
├── apps/
│ └── frontend/ # Next.js app — admin panel + dashboard (port 17801)
│ # Generated by make frontend-setup
├── cloudflared/ # Cloudflare Tunnel config (gitignored)
│ └── config.yml
├── docs/
│ ├── ARCHITECTURE.md # Detailed system architecture
│ ├── DECISIONS.md # Architecture decisions
│ ├── ENDPOINTS.md # Endpoints documentation
│ └── ROADMAP.md # Implementation phases
├── logs/ # Service logs in dev (gitignored)
├── .pids/ # Process PIDs in dev (gitignored)
├── qdrant_data/ # Persisted Qdrant data (gitignored)
├── config.json # Project configuration (gitignored)
├── .env # Environment variables (gitignored)
├── .env.example # Environment variables template
├── docker-compose.yml # Qdrant for development
├── docker-compose.prod.yml # All services for local deploy
├── Makefile # Command shortcuts
├── pyproject.toml # Python project and dependencies (uv)
├── CONTEXT.md # Project context for LLMs
└── README.md # This file已知限制
服务器依赖于本地机器保持开启,才能通过 Cloudflare Tunnel 进行远程工作
Qdrant 索引反映的是上次索引时的代码状态——请配置
post-commit钩子,以便在每次提交后自动更新索引二进制文件、图像和资源文件不会被索引
嵌入模型 (
jina-embeddings-v2-base-code, ~160 MB) 会在首次运行时通过sentence-transformers自动下载
This server cannot be deployed
Maintenance
Related MCP Connectors
An MCP server that gives your AI access to the source code and docs of all public github repos
Repository knowledge graph MCP server for codebase understanding and debugging.
Personal knowledge base MCP server with semantic search, auto-categorization, metadata extraction
Related MCP Servers
- AlicenseAqualityDmaintenanceLocal-first MCP server for semantic + keyword hybrid code search. Zero external services, no API keys required.2MIT
- FlicenseAqualityDmaintenanceProvides semantic vector search over local codebases via MCP, enabling hybrid search (dense + sparse + RRF) for any MCP client like GitHub Copilot or Claude Desktop.58-
- FlicenseNot gradedqualityBmaintenanceA local MCP server that enables LLM clients like Claude to perform semantic code search and answer questions about a codebase using tree-sitter parsing and sqlite-vec vector storage.-
- FlicenseNot gradedqualityDmaintenanceMCP server for semantic code search and explanation. Allows AI agents to search, ask questions, and manage memory about a codebase with local embeddings and LLM integration.-