Skip to main content
Glama
ericlimabr

mcp-context

by ericlimabr

mcp-context

本地 模型上下文协议 (MCP) 服务器,提供代码仓库的语义搜索 (RAG) 功能。将多个项目的上下文暴露给外部 AI 客户端(如 Claude.ai、Gemini、Claude Code),无需在每次会话时手动重新传递上下文。

技术栈: Python · FastMCP · Qdrant · sentence-transformers · Next.js · Docker · Cloudflare Tunnel


前置要求

在继续之前,请确保已安装以下项目:

工具

最低版本

检查命令

Python

3.11

python3 --version

Docker

24.0

docker --version

Docker Compose

2.20

docker compose version

Node.js

18.0

node --version

npm

9.0

npm --version

Git

任意

git --version

cloudflared

任意

cloudflared --version

远程连接(阶段 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-password

2. 配置 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:404

3. 创建前端

此步骤仅需执行一次。它会创建 Next.js 项目并自动移除内部的 .git/:

make frontend-setup

4. 索引第一个项目

打开前端,添加项目路径并触发索引:

make frontend
# Access http://localhost:17801

或者直接从终端运行索引器:

make index

本地运行(开发)

要启动带有自动重载功能的 MCP 服务器(开发时推荐):

make dev

这将启动 Qdrant、Cloudflare Tunnel 以及启用了热重载的 MCP 服务器。服务器会在 server/ 中的任何文件发生更改时自动重启。

要在后台启动所有服务(MCP 服务器、前端、隧道、Qdrant):

make server-dev

可用服务:

服务

URL

MCP 服务器

http://localhost:17800

前端(管理 + 仪表盘)

http://localhost:17801

Qdrant (API)

http://localhost:17810

实时日志可在 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 命令

命令

描述

make setup

首次运行:通过 uv 安装依赖并启动 Qdrant

make frontend-setup

在 apps/frontend/ 中创建 Next.js 项目(仅一次)

make dev

启动 Qdrant + 隧道 + 带自动重载的 MCP 服务器

make server-dev

在后台启动所有服务

make stop

停止所有开发服务

make server

仅启动 MCP 服务器(端口 17800)

make frontend

仅启动 Next.js 前端(端口 17801)

make tunnel

仅启动 Cloudflare Tunnel

make index

运行索引工作进程

make qdrant-up

通过 Docker Compose 启动 Qdrant

make qdrant-down

停止 Qdrant

make qdrant-logs

实时查看 Qdrant 日志

make prod-build

构建所有 Docker 镜像

make prod-up

启动所有容器

make prod-down

停止所有容器

make prod-logs

实时查看所有容器的日志


仓库结构

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 自动下载

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    B
    maintenance
    A 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.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    MCP 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.
    -