Skip to content

Latest commit

 

History

History
64 lines (51 loc) · 3.17 KB

File metadata and controls

64 lines (51 loc) · 3.17 KB

codebase-memory-zig

A hardened fork of DeusData/codebase-memory-mcp — a local, single-binary code-structure intelligence MCP server (tree-sitter AST + LSP-style symbol/call-graph) that speaks stdio JSON-RPC MCP.

It is a hybrid: Zig owns the process, the stdio JSON-RPC framing, and a hard filesystem-security bound; the vendored C engine (SQLite, ~200 tree-sitter grammars, the C++ preprocessor) executes every tool with full upstream parity via cbm_mcp_server_handle. serverInfo.name stays codebase-memory-mcp, and the 15-tool surface is byte-for-byte extracted from upstream — existing MCP clients need no change. Verified end-to-end on Linux and Windows.

Why this fork

Two defects in the upstream prebuilt binary can't be fixed from outside it, so the engine was forked to fix them at the source:

  1. Bounded scans (CPU-DoS fix). Upstream's dependency resolution can walk the whole filesystem (find / -path */registry/src/*), starving a shared host. This fork installs a WalkRoots bound engine-wide from the sole directory-iteration chokepoint (compat_fs.c's cbm_opendir, interposed by src/cshim/walk_guard.c): any walk outside the declared roots is refused. Roots are declared with repeatable --walk-root flags — a walk that escapes to /, $HOME, or CARGO_HOME is refused (EACCES). Performance is unchanged from upstream (the guard adds one realpath() per directory entered).
  2. One-command cross-compilation (build-pain fix). Zig's build system cross-compiles the vendored C engine, so one zig build targets glibc 2.36/2.35 (Linux) and x86_64-windows (.exe) — removing the 266 MB / glibc-2.38 / bind-mount-SIGSEGV pain the upstream binary caused in containers.

Build

Requires Zig 0.16.0.

zig build hybrid       # Linux MCP server (glibc 2.36 deploy target)
zig build hybrid-test  # Linux MCP server (glibc 2.35, for WSL smoke tests)
zig build hybrid-win   # Windows MCP server (.exe)
zig build engine       # cross-compile the vendored C engine to a static lib
zig build test         # Zig unit tests

The server takes --walk-root=<dir> (repeatable — declare the repo and any other allowed roots), --store-path=<dir> (index/cache location), and --tool-profile=<all|analysis|scout>. With no --walk-root the guard runs in allow-all bootstrap mode and logs a warning.

Layout

build.zig / build.zig.zon   Zig build + manifest
src/main_hybrid.zig         the hybrid MCP server: Zig stdio + delegation to the C engine
src/cshim/walk_guard.c      the WalkRoots CPU-DoS bound (sole cbm_opendir chokepoint)
src/discover/, src/foundation/   pure-Zig safe discovery + WalkRoots types
src/mcp/, src/main.zig      native-Zig MCP surface scaffold (tool table extracted from upstream)
docs/PORTING-PLAN.md        architecture + phased C -> Zig plan
reference/upstream-c/       vendored MIT C source of truth (DeusData @ e678b2b, read-only)

License

MIT — see LICENSE. Original copyright (c) 2025 DeusData is preserved; the vendored snapshot under reference/upstream-c/ keeps its own LICENSE / THIRD_PARTY notices.