LightRAG Code Brain MCP
Provides a durable memory layer for coding agents like Claude Code and Codex by indexing codebases and enabling RAG queries, reducing rediscovery tokens and providing senior-engineer orientation.
README
LightRAG Code Brain MCP
LightRAG Code Brain MCP turns a local LightRAG server into a persistent project brain for coding agents such as Claude Code and Codex.
It provides:
- whole-codebase indexing with conservative default excludes and secret redaction
- multi-repo source names with
repo_id:relative/path - RAG query/context/data tools
- durable memory across sessions
- senior-developer project profile sections
- a task gate that encourages agents to load/update memory for non-trivial work
What This Solves
Coding agents often reread the same files, forget prior fixes, and lose setup history between sessions. This MCP gives them a durable memory layer:
- architecture and module boundaries
- conventions, workflows, and hazards
- debugging playbooks and failed attempts
- setup outcomes and provider quirks
- current project profile and handoff notes
It does not replace reading source files for exact edits. It reduces discovery tokens and gives the agent a senior-engineer orientation before it opens files.
Requirements
- Docker with Compose
- Python 3.10+
- A chat/LLM provider compatible with OpenAI chat completions
- An embeddings provider compatible with OpenAI
/v1/embeddings - Claude Code and/or Codex if you want agent integration
Quick Start
git clone https://github.com/YOUR_ORG/lightrag-code-brain-mcp.git
cd lightrag-code-brain-mcp
cp .env.example .env
Edit .env:
LIGHTRAG_AUTH_ACCOUNTS="admin:your-password"
LIGHTRAG_USERNAME="admin"
LIGHTRAG_PASSWORD="your-password"
LIGHTRAG_TOKEN_SECRET="a-long-random-string"
LIGHTRAG_LLM_BINDING_HOST="https://api.openai.com/v1"
LIGHTRAG_LLM_API_KEY="..."
LIGHTRAG_LLM_MODEL="gpt-4o-mini"
LIGHTRAG_EMBEDDING_BINDING_HOST="https://api.openai.com/v1"
LIGHTRAG_EMBEDDING_API_KEY="..."
LIGHTRAG_EMBEDDING_MODEL="text-embedding-3-large"
LIGHTRAG_EMBEDDING_DIM="3072"
Start LightRAG:
docker compose up -d
curl http://127.0.0.1:9621/health
NVIDIA NIM Embeddings
If you use NVIDIA NIM, this model worked with LightRAG's OpenAI-compatible
embedding call because it does not require input_type:
LIGHTRAG_EMBEDDING_BINDING_HOST="https://integrate.api.nvidia.com/v1"
LIGHTRAG_EMBEDDING_API_KEY="nvapi-..."
LIGHTRAG_EMBEDDING_MODEL="nvidia/nv-embed-v1"
LIGHTRAG_EMBEDDING_DIM="4096"
Some NVIDIA embedding models require input_type; those may fail through
LightRAG's default OpenAI embedding request.
Install In Codex
export LIGHTRAG_URL="http://127.0.0.1:9621"
export LIGHTRAG_USERNAME="admin"
export LIGHTRAG_PASSWORD="your-password"
export LIGHTRAG_DEFAULT_REPO_ROOT="/path/to/your/project"
export LIGHTRAG_DEFAULT_REPO_ID="my-project"
./install-codex.sh
codex mcp list
This runs:
codex mcp add lightrag-code-brain \
--env LIGHTRAG_URL=http://127.0.0.1:9621 \
--env LIGHTRAG_USERNAME=admin \
--env LIGHTRAG_PASSWORD=your-password \
--env LIGHTRAG_DEFAULT_REPO_ROOT=/path/to/your/project \
--env LIGHTRAG_DEFAULT_REPO_ID=my-project \
-- python /absolute/path/lightrag_mcp_server.py
Install In Claude Code
export LIGHTRAG_URL="http://127.0.0.1:9621"
export LIGHTRAG_USERNAME="admin"
export LIGHTRAG_PASSWORD="your-password"
export LIGHTRAG_DEFAULT_REPO_ROOT="/path/to/your/project"
export LIGHTRAG_DEFAULT_REPO_ID="my-project"
./install-claude.sh
Copy the generated .mcp.json into your Claude Code project root, or merge the
mcpServers entry into an existing .mcp.json.
Examples are also provided in examples/:
examples/claude-mcp.jsonexamples/codex-install.shexamples/AGENTS-snippet.md
Recommended Agent Instructions
Add this to your project CLAUDE.md, AGENTS.md, or equivalent:
Use the LightRAG MCP server as persistent project memory.
For non-trivial implementation/debugging/setup work:
- call `brain_begin` first
- use `senior_brief` for architecture/conventions/hazards
- use `brain_search` for prior fixes/failures when something is broken
- use `rag_index_repo` for whole-codebase indexing when needed
- after meaningful work, call `brain_remember`
- call `profile_upsert` when architecture/conventions/workflows/hazards change
- call `brain_finish` before final response
Tool Overview
RAG tools:
rag_askrag_get_contextrag_query_datarag_statusrag_clearrag_index_reporag_list_documentsrag_track_statusrag_reprocess_failedrag_cancel_pipelinerag_webui
Memory tools:
brain_rememberbrain_searchbrain_recentbrain_reindexbrain_beginbrain_finishbrain_gate_status
Senior project profile tools:
profile_bootstrapprofile_getprofile_upsertprofile_searchsenior_brief
Whole-Codebase Indexing
Use rag_index_repo:
{
"root": "/path/to/project",
"repo_id": "my-project",
"dry_run": true,
"limit": 1000
}
Then run without dry_run.
Defaults intentionally skip:
.env, MCP config, local memory files.git,.venv, caches, logs, lockfilesnode_modules, build/dist output- LightRAG storage and generated data
- backup/temp/database/log files
- files larger than 256 KiB
Secret-looking values are redacted before indexing.
Multi-Repo Support
Pass a stable repo_id for each repository:
{
"root": "/work/project-a",
"repo_id": "project-a"
}
Documents are indexed as:
project-a:relative/path.py
This keeps references distinguishable across repositories.
Publish Your Own Copy
git init
git add .
git commit -m "Initial LightRAG Code Brain MCP"
gh repo create lightrag-code-brain-mcp --public --source=. --remote=origin --push
Before publishing, confirm .env is not staged:
git status --short
Troubleshooting
Check LightRAG:
docker compose ps
docker compose logs --tail=100 lightrag
curl http://127.0.0.1:9621/health
Common issues:
401: wrongLIGHTRAG_USERNAME/LIGHTRAG_PASSWORD- embedding
404: provider does not expose/v1/embeddings - NVIDIA
input_type required: usenvidia/nv-embed-v1or another compatible model - no context after indexing: wait for pipeline completion, then check
rag_status
Security Notes
- Do not commit
.env. - Keep LightRAG bound to
127.0.0.1unless you know what you are doing. - Rotate credentials if you accidentally indexed secrets before redaction.
- Review
rag_index_repodry-run output before first full indexing.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。