NervaPack

io.github.ramdhavepreetamPublished by GitHub account ramdhavepreetamv0.5.8Updated Oct 24, 2026

Offline codebase knowledge graph: 91% token reduction vs naive RAG, plus cross-session agent memory.

Overview

AI-generated overview

Offline codebase knowledge graph MCP server that answers code questions with focused, token-efficient context and keeps cross-session agent memory.

What you can do
  • Query the indexed codebase: vector search plus K-Hop graph traversal returns a focused Markdown context block with token-savings figures
  • Inspect the graph: node and edge counts, language breakdown, unsynced-file warnings, and browsing of indexed classes, functions, imports and docs
  • Analyze impact: reverse dependency lookup showing what depends on a given entity
  • Manage agent memory: open and close sessions, store facts, decisions, procedures and preferences, recall them within a token budget, and get entity dossiers, decision rationale and timelines
  • Maintain memory: verify or refute entries, forget or purge nodes, list and clear sessions, switch namespaces, bulk import, and flag memories…
When to use it
Useful when an assistant works repeatedly in a local git repository and you want code questions answered from a compact structural context instead of dumping whole files, or when you want decisions and conventions to persist across chat sessions without pasting context each time.
Requirements
Runs locally over stdio as a Python package (Python 3.10+) launched with uvx; the project must be a git repository. The graph must be built first with the ingest command. Optional semantic doc-to-code binding needs an LLM: local Ollama by default, or the ANTHROPIC_API_KEY or OPENAI_API_KEY variables for cloud providers. First run downloads a roughly 30 MB ONNX embedding model.
Before you install
Cloud LLM providers are only used when explicitly selected, but then code and docs leave the machine; the ANTHROPIC_API_KEY or OPENAI_API_KEY credentials are used for that and cloud calls cost money. Memory tools write, tombstone and purge stored data, and clearing a session deletes its nodes. The clean command wipes graph and vector data (memory is kept). Indexed data is stored in a .nervapack directory in the project.

Installation

In SourceWeft

  1. Open NervaPack in the dashboard and add it to a workspace.
  2. Enable the server for the chats that should use its tools.

Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.

Other MCP clients

Follow the launch instructions in the repository.

README

NervaPack

[PyPI version] [Python Versions] [License: MIT] [Token Reduction] [Verified] [MCP Registry]

NervaPack is a privacy-first, offline knowledge graph for your codebase. It solves two fundamental problems with standard Vector RAG:

  • Token waste — chunk-based RAG retrieves blobs of text that may only tangentially relate to your query, bloating your context window.
  • Privacy risk — sending code to cloud embedding APIs leaks your proprietary logic.

NervaPack runs 100% on your machine. It uses tree-sitter to parse your codebase into a deterministic Abstract Syntax Tree graph, then uses a local Ollama model to draw hard semantic edges between your documentation and your code. Queries traverse this graph with a K-Hop BFS, returning a hyper-targeted, token-efficient context window — no cloud required.


Verified Performance

91.2% Average Token Reduction — independently verified on real-world codebases.

Test TypeTokens (Naive)Tokens (NervaPack)Reduction
Simple Query10,92610199.1%
Medium Query13,09216498.7%
Complex Query3,2901,10266.5%
Average52,0372,45991.2%

Cost Savings: $181–$724 per developer per year (GPT-4o to Claude Sonnet)

📊 View Full Benchmarks · 🧪 Messy Code Performance

Code quality impact: 90–99% reduction on clean code, 50–75% on legacy/messy code. Even poorly structured codebases benefit significantly.


Why NervaPack vs. standard Vector RAG

Standard Vector RAGNervaPack
ParsingArbitrary text chunksDeterministic AST nodes (class, function, import)
RetrievalNearest-neighbour blobK-Hop BFS on a structural graph
Doc ↔ Code linksNoneHard EXPLAINS edges drawn by local LLM
PrivacyCloud embeddings100% local (ChromaDB + ONNX + optional Ollama)
Incremental syncRe-index everythingSurgical per-file update via GitPython diff
Token savingsNo measurementBuilt-in dashboard shows exact reduction per query
Graph visibilityBlack boxInteractive HTML visualization of every node and edge
Duplicate-safeRepeated ingest = duplicate dataupsert — re-ingest is idempotent
Agent memoryNone17-tool MCP server for cross-session memory

Prerequisites

  • Python 3.10+
  • Git — your project must be a git repository (git init if not)

(Optional for semantic code-doc binding) — an LLM provider. Structural graph indexing and basic queries work out-of-the-box with zero configuration and no cloud connection.

ProviderSetupCostPrivacy
Ollama (default)brew install ollama && ollama pull llama3Free100% local
Claude APIpip install "nervapack[claude]" + ANTHROPIC_API_KEY~$0.25/1k callsCloud
OpenAI APIpip install "nervapack[openai]" + OPENAI_API_KEY~$0.15/1k callsCloud
MCP (Claude Code)Zero configIncluded in subscriptionCloud

Installation

bash
# Recommendedpip install nervapack
# With optional featurespip install "nervapack[mcp]"          # MCP server for Claude Code / Cursorpip install "nervapack[memory]"       # agent memory MCP serverpip install "nervapack[metrics]"      # exact token counts (tiktoken)pip install "nervapack[dashboard]"    # web dashboard (streamlit + plotly)pip install "nervapack[claude]"       # Claude API supportpip install "nervapack[openai]"       # OpenAI API supportpip install "nervapack[all]"          # everything

On first run, ChromaDB downloads an ONNX embedding model (~30 MB) to ~/.cache/chroma/. This is a one-time download.


Quick Start

bash
cd your-project/
# 1. Build the knowledge graph (runs locally, no LLM required for basic use)nervapack ingest .
# 2. Query for context — get focused results + token savings dashboardnervapack query "How does authentication work?"
# 3. Add semantic doc-to-code edges (requires an LLM)nervapack enrich .
# 4. Visualize the full graphnervapack visualize --enhanced --communities
# 5. After changing files, sync incrementally (fast — only changed files)nervapack sync .
# 6. If you ingested wrong data or need a fresh startnervapack clean --allnervapack ingest .
# 7. Check system healthnervapack doctor

Command Reference

nervapack ingest [PATH] — Build the graph

Scans PATH (default: .) and builds the full knowledge graph.

What happens:

  1. Walks the directory tree with tree-sitter, skipping dist/, build/, node_modules/, venv/, site/, .tox/, and dozens of other build directories automatically.
  2. Parses source files into exact AST nodes: classes, functions, imports.
  3. Chunks all .md files by header hierarchy.
  4. Embeds every entity into a local ChromaDB vector store (ONNX by default, Ollama optional).
  5. Optionally binds doc chunks to code nodes via an LLM, adding EXPLAINS edges.
  6. Saves the graph once to .nervapack/graph.graphml.

Re-ingesting is safe — upsert is used throughout, so running ingest twice does not duplicate data.

bash
nervapack ingest .                           # auto-detect LLMnervapack ingest . --llm ollama              # force Ollamanervapack ingest . --llm claude              # use Claude APInervapack ingest . --llm openai --model gpt-4o-mininervapack ingest . --embeddings ollama       # use Ollama for embeddings too

Supported languages (bundled): Python, JavaScript, JSX, TypeScript, TSX

Additional languages:

bash
pip install "nervapack[go]"            # Gopip install "nervapack[rust]"          # Rustpip install "nervapack[java]"          # Javapip install "nervapack[c]"             # C / C headerspip install "nervapack[cpp]"           # C++pip install "nervapack[ruby]"          # Rubypip install "nervapack[csharp]"        # C#pip install "nervapack[all-languages]" # all of the above

Exclude directories — create .nervapackignore in your project root (gitignore syntax):

dist/build/site/generated/*.egg-info/

nervapack query PROMPT — Query the graph

Retrieves focused context for a natural-language prompt and prints a token savings dashboard.

What happens:

  1. Intent detection — "what breaks if I change X" routes to impact analysis (reverse BFS); exact symbol names bypass vector search.
  2. ChromaDB returns the top-3 most semantically similar nodes.
  3. Those nodes seed a K-Hop BFS through the NetworkX graph (default: 1 hop, both directions).
  4. Adjacent nodes — including any markdown docs via EXPLAINS edges and memory notes via TOUCHES edges — are collected.
  5. A focused Markdown context block is printed, ready to paste into an LLM prompt.
  6. Token efficiency panel shows savings vs. naive "dump the whole file" RAG.
bash
nervapack query "How does authentication work?"nervapack query "What calls VectorStore?"nervapack query "what breaks if I change GraphBuilder"  # impact analysis

Example output:

Query: "How does authentication work?"
Query Router: Intent: semantic, Direction: bothVector Search: Found 3 seed nodes
Retrieved Context:──────────────────────────────────────────────────────────# NervaPack Context Retrieval## File: `src/auth/middleware.py`### CLASS: AuthMiddleware (L15-L42)...──────────────────────────────────────────────────────────
╭──────────────  NervaPack Token Efficiency  ──────────────╮│  Strategy              Tokens   Reduction                 ││  Naive RAG (3 files)   12,840   100% (base)              ││  NervaPack              1,180     9.2%                    ││ ─────────────────────────────────────────────────────────││  Tokens saved: 11,660   Reduction: 90.8%                 ││  Cost saved (GPT-4o $2.50/1M): $0.0292 per query         │╰───────────────────────────────────────────────────────────╯

nervapack sync [PATH] — Incremental update

Updates only the files that changed since the last ingest. Uses GitPython to diff the working tree.

bash
nervapack sync .

A full ingest on a large project can take minutes. sync turns that into a 2–5 second surgical update per file. Re-parses changed files, batch-upserts new vectors, and saves the graph once at the end.


nervapack clean [OPTIONS] — Remove ingested data

Wipe graph data and start fresh. Use this when you have duplicate vectors, ingested the wrong directory, or need to reduce disk usage.

bash
nervapack clean --vectors          # wipe ChromaDB only (chroma_db/)nervapack clean --graph            # delete graph.graphml onlynervapack clean --history          # clear query + graph history logsnervapack clean --all              # everything above (keeps memory.db)nervapack clean --all --yes        # skip confirmation (CI / scripts)

Never deleted by clean: memory.db — your agent memory is always safe.

Typical workflow after a bad ingest:

bash
nervapack clean --allnervapack ingest .

nervapack enrich [PATH] — Add semantic edges

Runs LLM doc-to-code binding on an already-ingested graph. Use this if you:

  • Ran ingest without an LLM and want to add EXPLAINS edges now.
  • Added new documentation and want to bind it without a full re-ingest.
bash
nervapack enrich .                           # auto-detect LLMnervapack enrich . --llm ollama --model llama3nervapack enrich . --llm claude              # shows cost estimate before proceeding

nervapack status [--detailed] — Graph health

bash
nervapack status            # node/edge counts + unsynced filesnervapack status --detailed # full analytics: health score, language distribution, coverage

Health score (0–100) factors in documentation coverage, node connectivity, graph density, and edge diversity. A structural-only graph typically scores 30–40; after enrich it rises to 70–90.


nervapack visualize [OPTIONS] — Interactive HTML graph

bash
nervapack visualize                           # basic visualizationnervapack visualize --enhanced                # + real-time search + path findernervapack visualize --enhanced --communities  # + community detection (Louvain)nervapack visualize --output ~/my-graph.html  # custom output pathnervapack visualize --no-browser              # generate without opening

Produces a standalone HTML file with no external dependencies — drag, zoom, search, find shortest paths between nodes.


nervapack explore TARGET [--hops N] — Focused subgraph

Extract and visualize the N-hop neighbourhood of a specific file, class, or function.

bash
nervapack explore GraphBuilder --hops 2nervapack explore src/auth/middleware.py --hops 1nervapack explore "function:parse"

nervapack dependencies [FILE] — Import dependency analysis

Analyze file-level import chains, detect circular dependencies, and visualize the dependency graph.

bash
nervapack dependencies                        # full project analysisnervapack dependencies src/graph/builder.py   # single filenervapack dependencies --no-cycles            # skip cycle detection

nervapack hotspots [OPTIONS] — Change frequency analysis

Show which files change most often in git history — prime targets for documentation and review.

bash
nervapack hotspots                            # top 20 by commit countnervapack hotspots --since "6 months ago"    # recent history onlynervapack hotspots --ext .py --churn         # Python files, sort by lines changed

nervapack history [OPTIONS] — Query history

bash
nervapack history              # last 10 queries with token savingsnervapack history --limit 50   # last 50nervapack history --stats      # aggregate: total savings, cost avoided, top topicsnervapack history --clear      # delete history

nervapack serve [--port N] — Web dashboard

bash
nervapack serve                # http://localhost:8501nervapack serve --port 8080    # custom port

Requires nervapack[dashboard]. Shows graph overview, language distribution, analytics, query history trends, and an interactive graph explorer.


nervapack doctor — Environment check

bash
nervapack doctor

Verifies Python version, tree-sitter grammars, embedding backend, Ollama connectivity, and MCP config. Run this after installation or when troubleshooting.


Storage Layout

Everything lives in .nervapack/ inside your project root:

.nervapack/├── graph.graphml          # NetworkX DiGraph (AST + EXPLAINS edges)├── chroma_db/             # ChromaDB vector store (ONNX embeddings)├── memory.db              # Agent memory (SQLite + FTS5, bi-temporal)├── query_history.jsonl    # Per-query token savings log└── graph_history.jsonl    # Ingest/sync event log

Add .nervapack/ to .gitignore to keep it out of version control.

Disk usage guide:

  • chroma_db/ — typically 10–100 MB depending on project size. Run nervapack clean --vectors && nervapack ingest . if it grows unexpectedly.
  • graph.graphml — typically 0.5–5 MB.
  • memory.db — grows with agent usage; rarely exceeds a few MB.

MCP Integration (Claude Code, Cursor, Windsurf)

NervaPack ships two MCP servers in the same package. Drop this .mcp.json in your project root:

json
{  "mcpServers": {    "nervapack": {      "command": "nervapack-mcp",      "description": "NervaPack knowledge graph (v0.6.1) — query, graph_status, explore, impact"    },    "nervapack-memory": {      "command": "nervapack-memory-mcp",      "description": "NervaPack agent memory (v0.6.1) — store, recall, and reason over facts across sessions"    }  }}

Knowledge Graph MCP tools (nervapack-mcp)

ToolWhat it does
queryVector search → K-Hop BFS → focused Markdown context + token savings
graph_statusNode/edge counts, language breakdown, unsynced file warnings
exploreBrowse all indexed classes, functions, imports, markdown docs
impactReverse dependency analysis — find what depends on a given entity

Agent Memory MCP tools (nervapack-memory-mcp) — 17 tools

ToolPurpose
memory_start_sessionOpen a named session
memory_storePersist a fact, decision, outcome, procedure, preference, or action
memory_recallFTS5 search → graph expansion → scored, budget-capped recall
memory_aboutEntity dossier: all facts/decisions linked to one entity
memory_whyExplain a decision: rationale, rejected alternatives, outcomes
memory_timelineChronological trace including superseded versions
memory_end_sessionClose session with an outcome summary
memory_forgetTombstone or hard-purge nodes
memory_verifyConfirm (confidence +0.1) or refute (close + confidence ×0.5)
memory_statsNode counts, DB size, top entities, all namespaces
memory_list_sessionsList all sessions with node counts
memory_clear_sessionDelete a session and all its nodes
memory_for_codeMemories that TOUCH a source file or specific line
memory_to_codeCode locations a memory node TOUCHES
memory_importBulk-seed memory from a JSON array
memory_switch_namespaceSwitch the active namespace
memory_verify_stalenessFlag memories whose source file changed since stored

CLAUDE.md template

Add to your CLAUDE.md to wire NervaPack into every Claude Code session:

markdown
## Always use NervaPack MCP tools
At the start of every session:1. Call `memory_start_session("<task name>")` to open a named session.2. Call `memory_recall("project context", budget_tokens=400)` to load prior decisions.3. Call `query("<topic>")` before answering any question about how the code works.
During the session — call `memory_store` for:- Any decision made (kind="decision" with rationale and alternatives_rejected)- Any fact discovered about system behaviour (kind="fact")- Any procedure or convention established (kind="procedure")
At session end — call `memory_end_session("<one-paragraph summary>")`.

Architecture

nervapack ingest .       │       ├─ ASTParser (tree-sitter)               16 extensions, 10 languages       │    └─ ParsedEntity[]: class, function, import       │       ├─ GraphBuilder (NetworkX DiGraph)       │    ├─ Nodes: file, class, function, import, markdown       │    ├─ Edges: DEFINES (AST, confidence=1.0)       │    ├─ Edges: REFERENCES (heuristic name overlap, confidence=0.7)       │    └─ Edges: EXPLAINS (LLM or keyword binding, confidence=0.5–0.9)       │       ├─ VectorStore (ChromaDB)       │    ├─ Embedding: ONNX (default) or Ollama       │    └─ upsert — re-ingest is idempotent       │       └─ GraphHistory  — snapshot recorded after each ingest/sync
nervapack query "..."       │       ├─ Intent detection (impact / exact / semantic)       ├─ VectorStore.search() → seed node IDs       ├─ GraphRetriever.retrieve_context()       │    └─ deque BFS, direction: forward / reverse / both       ├─ MemoryStore.get_touches_for_file() → memory context injection       └─ TokenMeter → savings vs. naive RAG
nervapack clean --all       └─ Deletes chroma_db/, graph.graphml, history logs          Never touches memory.db

Key source modules:

ModuleResponsibility
nervapack.parser.ast_parsertree-sitter parsing → ParsedEntity; shared singleton parser instance
nervapack.parser.md_chunkerMarkdown → header-delimited chunks; prunes build dirs from os.walk
nervapack.graph.builderNetworkX DiGraph; O(1) file-index for sync; compiled regex for REFERENCES
nervapack.graph.vector_storeChromaDB upsert (idempotent); pluggable embedding function
nervapack.graph.retrievalK-Hop BFS with deque (O(n) not O(n²))
nervapack.graph.token_metertiktoken singleton; token savings panel
nervapack.graph.query_historyTail-read JSONL — O(limit) not O(total)
nervapack.graph.analyticsBulk graph.degree() — single call not per-node loop
nervapack.llm.basebind_docs_to_ast with keyword pre-filter (top-12 candidates)
nervapack.llm.providers.ollamaollama.list() cached 60 s
nervapack.memory.storeSQLite + FTS5; bi-temporal; batch_neighbors for O(1) hop expansion
nervapack.memory.recallBatched hop expansion; audit trail on recall
nervapack.mcp_serverFastMCP — query, graph_status, explore, impact
nervapack.memory.mcp_serverFastMCP — 17 memory tools

nervapack.memory — Agent Memory

Stop re-pasting project context into every new chat.

python
# Store a decisionmemory_store(    "Chose JWT over session cookies for auth_service — stateless horizontal scaling",    kind="decision",    entities=["auth_service"],    confidence=0.9,    rationale="Stateless tokens enable horizontal scaling without shared session store.",    alternatives_rejected=["server-side sessions", "PASETO"],)
# Recall in any future sessionmemory_recall("project context", budget_tokens=400)
## Memory recall: "project context" (6 items · 171/400 tokens)
### Decisions- [d_0019f2] 2026-06-05 · conf 0.90 — Chose JWT for auth_service
### Facts- [f_0019f3] 2026-06-05 · conf 1.00 — auth_service issues 15-min access tokens
### Procedures- [p_0019f5] 2026-06-12 · conf 1.00 — Deploy: GitHub Actions → staging → prod manual

Token efficiency:

ApproachTokens per sessionAfter 20 sessions
Manual paste (architecture doc)~2,400~48,000
memory_recall~171~3,420
Savings93% fewer tokens

CLI:

bash
nervapack-memory init                          # create schemanervapack-memory stats                         # counts + top entitiesnervapack-memory search "JWT auth"             # FTS searchnervapack-memory timeline "auth service"       # chronological tracenervapack-memory audit d_0019f2abc             # access audit trailnervapack-memory rebind old/path.py new/path.py  # update file links after renamenervapack-memory export --out dump.json        # JSON dump

Data model: 8 node kinds, 7 edge kinds, bi-temporal (valid_from/valid_until), never hard-deletes by default.


Privacy

NervaPack is 100% offline by default:

  • Embeddings use ChromaDB's built-in ONNX model (runs on CPU, no cloud).
  • LLM calls (when using Ollama) go to localhost:11434 only.
  • All graph and vector data lives in .nervapack/ inside your project.
  • No telemetry, no analytics, no network calls at runtime.

Only if you explicitly pass --llm claude or --llm openai does any code leave your machine.


Contributing

  1. Fork the repo and create a branch.
  2. Run tests: python3 -m pytest tests/memory/ -q
  3. Run docs check: python3 -m mkdocs build --strict
  4. Open a pull request against master.

Bug reports and feature requests: issue tracker.


License

MIT — see LICENSE.

Source: README.md at commit a3a0548

Tools

0
SourceWeft has not started this package in its sandbox yet, so its tools are not known.

Version history

1
  1. v0.5.8LatestSep 16, 2026

Score

50% of the applicable checks met

How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.

  • Reached in the last 30 days25 pts

    Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.

  • Auth declared10 pts

    Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.

  • Tools listed15 pts

    Answer tools/list without a credential, or ship a package that starts in a sandbox without one.

  • DescriptionRequired15 pts
  • Logo10 pts
  • Documentation15 pts
  • License10 pts