LightRAG Code Brain MCP
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@LightRAG Code Brain MCP brain_search for previous fixes on login timeout"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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/pathRAG 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.
Related MCP server: Hokmah MCP Server
Requirements
Docker with Compose
Python 3.10+
A chat/LLM provider compatible with OpenAI chat completions
An embeddings provider compatible with OpenAI
/v1/embeddingsClaude 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 .envEdit .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/healthNVIDIA 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 listThis 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.pyInstall 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.shCopy 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 responseTool 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 outputLightRAG 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.pyThis 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 --pushBefore publishing, confirm .env is not staged:
git status --shortTroubleshooting
Check LightRAG:
docker compose ps
docker compose logs --tail=100 lightrag
curl http://127.0.0.1:9621/healthCommon issues:
401: wrongLIGHTRAG_USERNAME/LIGHTRAG_PASSWORDembedding
404: provider does not expose/v1/embeddingsNVIDIA
input_type required: usenvidia/nv-embed-v1or another compatible modelno 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.
Available Tools
23 toolsbrain_beginB
Start the mandatory project-brain workflow for a non-trivial task. Creates a local gate file and optionally runs senior_brief immediately.
Inputs: task (required), repo_id, senior_brief_required, brain_search_required, +1 more.
brain_finishC
Finish the mandatory project-brain workflow and record whether memory/profile updates were made before final response.
Inputs: memory_ids, profile_updated, brain_search_done, note.
brain_gate_statusB
Check whether the mandatory project-brain workflow gate is satisfied.
Inputs: no named parameters.
brain_recentC
List recent durable project memories from the local memory log.
Inputs: repo_id, limit.
brain_reindexC
Replay the local durable memory log into LightRAG.
Inputs: repo_id, limit.
brain_rememberB
Persist a durable project memory into the local memory log and LightRAG. Use this after fixes, failed attempts, setup discoveries, architecture decisions, and session handoff notes.
Inputs: title (required), summary (required), kind, details, +4 more.
brain_searchC
Search durable project memories and LightRAG semantic memory for prior fixes, failures, decisions, and setup outcomes.
Inputs: query (required), repo_id, kinds, limit, +3 more.
profile_bootstrapC
Build or refresh the structured senior-developer project profile from repository layout and project instruction files.
Inputs: root, repo_id.
profile_getC
Return the structured senior-developer project profile.
Inputs: sections, markdown.
profile_searchC
Search the structured senior-developer project profile and semantic RAG profile.
Inputs: query (required), limit, mode, top_k, +1 more.
profile_upsertC
Create or update one senior-developer knowledge item in the project profile and index it into LightRAG.
Inputs: section (required), title (required), summary (required), details, +3 more.
rag_askA
Query the local LightRAG knowledge base for repository context. Use this before answering questions about code architecture, historical decisions, indexed docs, or cross-file behavior.
Inputs: query (required), mode, include_references, top_k, +2 more.
rag_cancel_pipelineA
Cancel the active LightRAG document processing pipeline, if any.
Inputs: no named parameters.
rag_clearC
Clear LightRAG documents and/or cache. Destructive.
Inputs: documents, cache.
rag_get_contextA
Retrieve LightRAG context for a query without generating a final answer.
Inputs: query (required), mode, include_references, top_k, +2 more.
rag_index_repoB
Index a repository into LightRAG. Multi-repo support is provided by prefixing every source with repo_id:relative/path.
Inputs: root, repo_id, include_extensions, exclude_dirs, +6 more.
rag_list_documentsC
List indexed documents, optionally filtered by repo_id prefix.
Inputs: page, page_size, status, repo_id.
rag_query_dataC
Return structured LightRAG query data: entities, relations, chunks, and metadata.
Inputs: query (required), mode, include_references, top_k, +2 more.
rag_reprocess_failedB
Ask LightRAG to reprocess failed documents.
Inputs: no named parameters.
rag_statusA
Check LightRAG health, active models, and document pipeline state.
Inputs: no named parameters.
rag_track_statusC
Get processing status for a LightRAG track_id.
Inputs: track_id (required).
rag_webuiA
Return local LightRAG Web UI and API documentation URLs.
Inputs: no named parameters.
senior_briefC
Return a senior-developer brief for a topic: architecture profile, conventions, hazards, workflows, and related durable memories.
Inputs: topic, repo_id, memory_limit, top_k, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 23 tools
Most tools have distinct purposes, especially within groups. However, brain_search, rag_ask, and profile_search all involve searching different stores, which could cause confusion if descriptions are not carefully read.
Tools follow a consistent verb_noun pattern with lowercase underscores, except 'senior_brief' which lacks a verb prefix. The pattern is clear within each prefix group (brain_, profile_, rag_).
23 tools is slightly on the higher side but still reasonable for a comprehensive memory and knowledge server. Each tool serves a specific function, and the count is not excessive.
The tool set covers core workflow, memory, profile, and RAG operations, but lacks delete/update tools for memories and profiles, and document-level deletion. Minor gaps exist but most use cases are addressed.
Maintenance
Related MCP Connectors
Shared memory for coding agents. Stop re-explaining your codebase every session.
Persistent engineering memory designed to follow developers across coding agents.
Give your AI agent a persistent map of your project's structure, dependencies, and bugs.
Shared, scoped, reviewable team memory for AI coding agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides long-term memory for AI coding agents, enabling them to remember, search, and organize information across sessions and platforms like Claude Code, ChatGPT, and Cursor.34 npm8MIT
- AlicenseNot gradedqualityDmaintenanceProvides AI coding agents with persistent architectural memory of codebases, enabling impact analysis, test generation, and code generation with reduced token usage.MIT
- FlicenseNot gradedqualityDmaintenanceProvides persistent codebase memory and semantic context for AI agents via AST-aware chunking and symbol graph indexing.1-
- AlicenseNot gradedqualityBmaintenanceProvides persistent long-term memory (semantic RAG) for AI coding assistants, enabling them to store and semantically search code and documentation across chat sessions without token limits.5MIT