
CogniRepo
io.github.ashlesh-t由 GitHub 账号 ashlesh-t 发布v1.1.1更新于 Oct 24, 2026
FAISS, call graph, AST, BM25 — 34 MCP tools for AI agents. 50-80% token reduction. Offline.
概览
CogniRepo 是一个本地 MCP 服务器,为代码库建立索引,让 AI 助手获得持久记忆、符号查找、调用图和会话上下文。
- 可以做什么
- 在已索引的代码库中查找符号、调用者、词级匹配和依赖图,并进行代码语义搜索与架构概览。存储和检索记忆、决策、事件与会话历史,支持语义和关键词搜索。读取并记录用户偏好、错误模式和会话简报,让助手跨会话恢复上下文。搜索和遍历跨仓库的组织图、服务端点与符号路径。生成 HTML 仓库历史报告,并将指令与已记录的决策进行对照检查。
- 适用场景
- 适合较大的代码库(约 1.5 万行以上),让助手更快定位代码,并在不同会话和工具之间保留项目记忆。在小型仓库上,工具架构的额外开销可能超过节省的部分。
- 运行要求
- 以 Python 包形式通过 stdio 在本地运行(需要 Python 3.11 及以上),可用 pipx 或虚拟环境安装。使用前必须先初始化并索引仓库,工具才会返回数据。索引、记忆和所有 MCP 工具均可离线使用,无需 API 密钥;ANTHROPIC_API_KEY 或 GEMINI_API_KEY 等密钥是可选的,仅用于单独的 ask 命令。
安装
在 SourceWeft 中
- 打开 控制台中的 CogniRepo,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
CogniRepo
mcp-name: io.github.ashlesh-t/cognirepo
Persistent memory and context for any AI tool. Not a chatbot — infrastructure.
[CI] [Security] [PyPI version] [GitHub Stars] [License: MIT] [Python 3.11+] [Discord]
lookup_symbol returns file:line very quickly — grep takes 2–8 seconds. On Python repos ≥ 15K LOC, CogniRepo cuts AI coding agent token usage by ~30–78% vs. a targeted grep+read baseline (up to 96–99% vs. reading every matching file naively) — benchmarked on Flask, FastAPI, Celery, and Ansible (5,900+ files). Works with Claude Code, Cursor, and Gemini CLI. Fully offline. No API keys required for indexing or any of the 36 MCP tools.
What it does
Every AI conversation starts from zero. Claude, Cursor, Gemini — none of them remember what you fixed yesterday, which files relate to which features, or what decisions were made last sprint. CogniRepo fixes that.
It sits between your codebase and any AI tool, providing:
- Semantic memory — FAISS vector store with sentence-transformer embeddings. Store decisions, docs, architecture notes. Retrieve them with natural language.
- Episodic log — append-only event journal. Know what happened before that error.
- Knowledge graph — NetworkX DiGraph linking functions, classes, files, imports, inheritance chains, call relationships, and concepts. All queryable.
- AST reverse index — O(1) symbol lookup across your entire codebase in any supported language.
- User behavior profiling — tracks how you prompt so Claude adapts its response style without you having to re-explain preferences every session.
- Error tracking — records errors with prevention hints so Claude avoids repeating the same mistake across sessions.
- Session history — persists conversation exchanges so any session can resume where the last one ended.
- Architectural summaries — auto-generated on first init; built entirely from the local AST index (no API key needed). File → directory → repo summary tree, embedded into FAISS for semantic search.
- Multi-model orchestration — classify query complexity → build context → route to the right model. Claude for deep reasoning, Gemini Flash for quick lookups. All automatic.
Every AI tool that connects gets the same accumulated project knowledge. Memory persists across sessions, across tools, across time.
When to use CogniRepo
Most effective on codebases ≥ 15K LOC. On small repos (< 10K LOC), native file reads are fast enough that the MCP tool schema overhead (~3,700 tokens for 36 tools) takes more than you save. Break-even is roughly 4 tool calls on a medium-sized repo.
CogniRepo vs. claude-context / similar tools:
Conclusion: prefer CogniRepo when you value institutional memory across sessions. Use simpler tools when you just need one-shot code retrieval on a small codebase.
Why it helps — measured numbers
Benchmarked across 6 real open-source repos (FastAPI, Flask, Celery, Ansible, Moby/Docker, Kubernetes) using 30 structured prompts tested against Claude, Gemini, and Cursor/Codex.
Honest limits: CogniRepo adds the most value on Python repos with clear static structure. Dynamic dispatch patterns (Celery beat, plugin registries), deep Go codebases, and Ansible's 22-level variable precedence chains reduce retrieval confidence. The tool reports uncertainty rather than hallucinating call chains.
Measured: lookup latency and token reduction (4 external repos)
Indexed 4 real repos, measured with cognirepo index-repo + cognirepo benchmark --json on
v2.4.0+ (2026-09-17). CPU-only, no GPU.
Measured 2026-09-17. Lookup latency < 0.1 ms on all repos. "Targeted" is the realistic baseline (grep + read top-2 matching files, approximating what an agent would actually do); "naive" reads every matching file in full and is an upper bound, not a realistic comparison. moby and kubernetes are indexable (Go support confirmed, COGNIREPO-500) but not yet in this table — hours of indexing, scheduled separately. Full numbers and methodology, including precision@k, symbol hit rate, and memory recall: docs/METRICS.md.
Run cognirepo benchmark on your own codebase to reproduce. See docs/METRICS.md.
How it works
Quick start
Requirements
- Python 3.11+
- API key (optional — only needed for
cognirepo ask):ANTHROPIC_API_KEY,GEMINI_API_KEY,OPENAI_API_KEY, orGROK_API_KEY. Indexing, memory, summarization, and all MCP tools work fully offline.
Install
Recommended — pipx (global, one command, works on all distros)
That's it. cognirepo setup handles the rest — it installs optional extras (languages,
security, providers) via pipx inject automatically when you enable them in the wizard.
Why pipx? It creates an isolated venv for cognirepo automatically so
fastembedand all deps install cleanly. Thecognirepocommand is then globally available in every directory — no per-repo venv needed.Arch Linux / Debian 12+ / Ubuntu 24.04+: Do NOT
pip installinto system Python. These distros enforce PEP 668 and block system-wide pip installs. Use pipx.
Install pipx first (if needed)
Inside a virtual environment (alternative)
Development install (from source)
Note: CPU-only embeddings are the default (fastembed/ONNX, no PyTorch/CUDA required). For GPU:
pipx inject cognirepo 'cognirepo[gpu]'then install torch separately.
Run
First-time setup:
cognirepo init+cognirepo index-repo .must complete before MCP tools (context_pack,lookup_symbol,who_calls, etc.) return data.
Connect your AI tools
Claude Code / Claude Desktop (recommended — project-scoped)
Run cognirepo init inside your project — it asks if you want to configure Claude and
automatically writes .claude/CLAUDE.md and .claude/settings.json with the correct
project-locked connector.
Each project gets its own isolated connector named cognirepo-<project>:
The --project-dir flag locks the MCP server to that project's .cognirepo/ directory.
When Claude has multiple projects open simultaneously, each connector reads only its own
memories — never mixing data across projects or teams.
Cursor / Copilot
Docker
MCP Tools — complete reference
All 36 tools are available to Claude, Cursor, and any MCP-compatible client.
Core retrieval
User & session intelligence
Error tracking & prevention
Session start
Memory & storage
Reporting
Grounded pushback
Cross-repo (organization)
Knowledge graph — what gets indexed
The knowledge graph is significantly richer than a simple call graph.
Node types
Edge types
IMPORTS and INHERITS edges are built automatically during index-repo from Python AST.
Use subgraph("MyClass", depth=2) or dependency_graph("mymodule") to query them.
User behavior profiling
CogniRepo tracks how you interact across sessions and builds a profile that Claude uses to calibrate its responses — without you having to repeat preferences every session.
What gets tracked
- Depth preference — inferred from average query length:
concise/medium/detailed - Question types — distribution across:
why,what,how,fix,explain,where,refactor,add - Domain vocabulary — top terms that appear frequently in your queries
- Code focus — percentage of queries referencing code identifiers (symbols, functions)
- Sample queries — last 3 queries for Claude to infer framing style
Accessing your profile
Example profile output
Claude receives framing_hints at session start and adjusts response length, code density,
and terminology accordingly. The profile accumulates over time — more accurate the more you use it.
Error tracking & prevention
CogniRepo logs every error that occurs during sessions — whether it's a Python exception, a failed build step, or a tool call that went wrong. Errors are stored with:
- Dedup signature — prevents the same error from inflating the count
- Prevention hint — a targeted suggestion to avoid the same error class
- Occurrence context — last 5 occurrences with file path and error message
- Query context — the query or action that triggered the error
Logging errors
Viewing error patterns
Returns:
Built-in prevention hints
Session history
Every cognirepo ask exchange is persisted to .cognirepo/sessions/.
Sessions are indexed by UUID and retrievable via:
Each entry returns: session ID, created timestamp, message count, model used, and the last user/assistant exchange for quick context scan.
Architectural summaries
cognirepo init automatically prompts to run cognirepo summarize after the first index.
This produces a 3-level LLM summary of the entire codebase:
- Level 1 — repo-wide summary (what the project does, key modules, entry points)
- Level 2 — per-directory summaries (what each package is responsible for)
- Level 3 — per-file summaries (what each file contains, key functions/classes)
Summaries are stored in .cognirepo/index/summaries.json and served via the
architecture_overview MCP tool — zero token cost for Claude to understand the big picture.
Repo insights
What CogniRepo can tell you about your repo: generate_insights() (or cognirepo insights)
turns everything CogniRepo has recorded about a project — episodic events, architectural
decisions, open challenges, branch/commit activity, index health — into one self-contained HTML
report. Sourced only from real stored records; nothing fabricated. Screenshots below are from a
real report generated on this repo (cognirepo insights --since 365d), not mockups:
[CogniRepo insights report, light mode] [CogniRepo insights report, dark mode]
Multi-model orchestration
cognirepo ask automatically picks the right model for each query:
Provider fallback chain: Grok → Gemini → Anthropic → OpenAI.
All errors are logged to .cognirepo/errors/<date>.log — no raw tracebacks shown to users.
Language support
Full details and roadmap: docs/LANGUAGES.md
Storage layout
Files the loaders set aside are kept, never silently deleted: graph.pkl.corrupt-<ts> (may well hold an
intact graph — see cognirepo graph restore), vector_db/chroma.corrupt-<ts>/, *.stale.
cognirepo doctor --resources lists them with sizes. Expected sizes and tuning knobs:
docs/RESOURCES.md.
Everything under .cognirepo/ is .gitignored by default — never committed.
Fernet encryption is opt-in at storage.encrypt: true in config.json; it covers the graph, behaviour
model, org graph, episodic log and local FAISS store, but not the AST index or the default Chroma
store — see SECURITY.md for exactly what is and isn't covered.
CLI reference
Every command, flag and exit code: docs/CLI_REFERENCE.md.
Future Plans
Priorities drawn from the v0.3.0 benchmark findings and community feedback. Now at v2.5.0 — some items below have since landed; each is annotated where that's the case.
Near-term
- Go call-graph indexing — done (COGNIREPO-203): Go receiver-qualified method calls
(
recv.Method()) now resolve throughwho_calls/CALLS edges — tree-sitter's Goselector_expressionnames its method fieldfield, notproperty(the JS convention the extractor previously assumed), so method calls were silently dropped; fixed in_ts_collect_calls(intelligence/indexer/ast_indexer.py). A second bug in the same function — a call-collection recursion depth cap of 12, too shallow for a Go method wrapping an if-statement around a composite-literal call argument — was also raised (to 60). Go IMPORTS edges fromgo.mod-resolved local package imports are implemented (_extract_imports_go/_resolve_go_import_to_file). Live-verified againstcognirepo_test_repo/advanced/moby: 4/4 hand-verified callers resolved (100%, vs. the 90% target) after both fixes. cognirepo ask— done: multi-model orchestrator (QUICK/STANDARD/COMPLEX/EXPERT tiers) is implemented and wired as a real CLI command (_cmd_ask_local,interface/cli/main.py). Streaming REPL mode (see Longer-term) is not yet built.- Incremental re-index on save — done: the file-watcher daemon (
cognirepo watch) debounces writes (config.json→indexing.debounce_ms, default 500ms) and batches indexer/graph saves;tests/test_watcher_debounce.pycovers this including flush-on-shutdown. - CLAUDE.md mandatory-call relaxation — benchmark feedback (Moby tests) flagged that forcing
context_packbefore every file read adds latency under memory pressure. A--fastmode that skips the tool-first gate for files under 50 lines is not yet implemented.
Medium-term
- Platform (planned for 3.0) — a single per-user daemon, a local control API (
/api/v1) with acognirepo uicommand, and an SQLite (WAL) graph store to replace the resident in-memory graph. The Engram console that consumes the API lives in its own repository. Local-only by design: no hosted relay, no remote access. Tracked in the "Platform" epic. - Kubernetes / 2M-LOC scale validation — K8-1 through K8-5 test suite not yet completed. Goal: full scheduling-decision trace at < 8 000 tokens with CogniRepo vs. > 50 000 without.
- Plugin-registry pattern detection — done (COGNIREPO-203): a static, annotation-only
heuristic pass tags symbols reachable via dynamic dispatch — celery-style
@task/@shared_taskdecorators,register(...)-style plugin-registration calls, Python__init_subclass__hooks, and packaging entry-points (pyproject.toml[project.entry-points.*]/setup.cfg[options.entry_points]) — withdispatch:"dynamic"plus aRELATES_TOedge to adynamic_dispatchCONCEPT node (_detect_dynamic_dispatch,_apply_entry_points_dispatchinintelligence/indexer/ast_indexer.py). Annotation-only by design — never fabricates a CALLS edge. Live-verified againstcognirepo_test_repo/medium/celery's real@shared_taskfunctions. - BM25 over symbol names — partially done:
core/_bm25.pyis used byintelligence/retrieval/hybrid.pyas the circuit-breaker fallback ranker (and by episodic search) when embeddings are unavailable, but it isn't yet the primary ranking signal for symbol-name partial-match recall (e.g.HttpClientmatchinghttp_client) in the normal (embeddings-available) retrieval path. - Cross-session memory warm-up — Ansible benchmark noted episodic/memory retrieval is low-value on fresh sessions.
cognirepo primeexists but is not run automatically oninit; will make it opt-in default.
Longer-term
cognirepo askstreaming REPL — full interactive session with tier routing, session persistence, and sub-agent delegation.- Similarity edges in knowledge graph — done (COGNIREPO-202): post-index FAISS k-NN pass over already-embedded FUNCTION/CLASS symbol vectors adds a
SIMILAR_TOedge (cosine ≥ 0.80, max 5/node, cross-file only) between near-duplicate symbols, both directions. Gated viaconfig.json→indexing.similarity_edges(default on below 20k candidate symbols). Weighted (discounted) intointelligence/retrieval/hybrid.py::_graph_score. - VS Code / JetBrains extension — surface
lookup_symbol,context_pack, andwho_callsdirectly in the editor sidebar without requiring an MCP-capable host.
Documentation
Community
Questions, feedback, or just want to see what others are building? Join the CogniRepo Discord.
Want to contribute? See CONTRIBUTING.md — issues labeled
good first issue are
scoped for a first PR.
License
CogniRepo is licensed under the MIT License.
- Free to use, study, modify, and distribute
- Use in proprietary products and commercial services — no restrictions
- No requirement to open-source your application
See LICENSE for full details.
来源:README.md,提交 d3147ab
工具
0版本历史
1- v1.1.1最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分