# How to Build codebase-memory-mcp from Source: A Complete Guide to Static Compilation

> Learn how to build codebase-memory-mcp from source with our complete guide. Compile a static C binary using a simple script and minimal dependencies like a compiler, zlib, and git.

- Repository: [Martin Vogel/codebase-memory-mcp](https://github.com/DeusData/codebase-memory-mcp)
- Tags: how-to-guide
- Published: 2026-07-17

---

**The build process for codebase-memory-mcp from source uses a single shell script that generates a completely static C binary by running make with vendored tree-sitter grammars, requiring only a compiler, zlib headers, and git.**

The codebase-memory-mcp repository provides a high-performance MCP server implemented in C. Understanding the build process for codebase-memory-mcp from source gives you full control over compilation options, enabling custom version stamps, architecture-specific optimizations, and optional UI integration.

## Prerequisites

Before starting the build process for codebase-memory-mcp from source, ensure your system meets these minimal requirements:

- **C/C++ compiler** (GCC or Clang)
- **zlib** development headers
- **git** for cloning the repository

All language grammars are vendored within the repository, so no additional runtime dependencies or package managers are required for the core compilation.

### Platform-Specific Setup

**Linux:**

```bash
sudo apt-get update
sudo apt-get install -y build-essential zlib1g-dev curl

```

**macOS:**

```bash
xcode-select --install

```

**Windows:** Use WSL or Git Bash with the MSVC toolchain, as the build scripts are written for Unix-like shells.

## Step-by-Step Build Instructions

### 1. Clone the Repository

Clone the official repository and navigate to the project root:

```bash
git clone https://github.com/DeusData/codebase-memory-mcp.git
cd codebase-memory-mcp

```

### 2. Execute the Build Script

The [`scripts/build.sh`](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/build.sh) script serves as the central build driver. It handles environment detection, flag parsing, artifact cleaning, and the final make invocation.

**Standard headless binary:**

```bash
scripts/build.sh

```

**Binary with 3-D graph UI:**

```bash
scripts/build.sh --with-ui

```

**Custom version tag:**

```bash
scripts/build.sh --version v0.8.0

```

**Force specific architecture:**

```bash
scripts/build.sh --arch x86_64

```

The script outputs the compiled binary to `build/c/codebase-memory-mcp`.

### 3. Verify the Build

Confirm successful compilation by checking the CLI help output:

```bash
./build/c/codebase-memory-mcp --help

```

You should see usage information and a list of the 15 available MCP tools.

### 4. (Optional) Install System-Wide

For system installation, use the provided helper script:

```bash
scripts/install.sh

```

This copies the binary to `~/.local/bin`, strips macOS quarantine attributes, and registers the MCP server with supported agents. Alternatively, manually move the binary to any directory in your `$PATH`.

## Build Script Architecture

The [`scripts/build.sh`](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/build.sh) file orchestrates the build process for codebase-memory-mcp from source through three distinct phases:

**Environment Setup (lines 16-35):** The script locates the repository root and loads [`scripts/env.sh`](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/env.sh), which sets `$NPROC` for parallel compilation and validates the compiler toolchain.

**Flag Parsing (lines 36-71):** Command-line arguments such as `--with-ui`, `--version`, `--arch`, and compiler overrides (`CC=gcc-14`) are parsed and converted into make flags.

**Version Injection (lines 74-79):** When a version is supplied, the script injects `-DCBM_VERSION="..."` to ensure the binary reports the correct version string.

**Compilation (lines 90-97):** After cleaning `build/c`, the script invokes `make` using `Makefile.cbm` with the appropriate target (`cbm` for headless or `cbm-with-ui` for UI support).

## Build Configuration Options

The build process for codebase-memory-mcp from source supports several customization flags:

| Flag | Purpose | Example |
|------|---------|---------|
| `--with-ui` | Embed the 3-D graph visualization | `scripts/build.sh --with-ui` |
| `--version` | Stamp binary with specific version | `scripts/build.sh --version v1.2.0` |
| `--arch` | Target specific architecture | `scripts/build.sh --arch aarch64` |
| `CC/CXX` | Override default compiler | `CC=gcc-14 CXX=g++-14 scripts/build.sh` |

The `Makefile.cbm` processes these flags to compile all C sources under `src/`, link the bundled tree-sitter grammars statically, and link against `zlib`.

## Key Source Files

Understanding these files helps debug or extend the build process for codebase-memory-mcp from source:

- **[`scripts/build.sh`](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/build.sh)** — Central build driver that parses flags and invokes make ([source](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/build.sh))
- **[`scripts/env.sh`](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/env.sh)** — Environment detection for CPU count and compiler validation ([source](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/env.sh))
- **`Makefile.cbm`** — Defines `cbm` and `cbm-with-ui` targets; compiles sources under `src/` ([source](https://github.com/DeusData/codebase-memory-mcp/blob/main/Makefile.cbm))
- **[`src/main.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/main.c)** — Entry point for the MCP server and CLI ([source](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/main.c))
- **`src/mcp/`** — Implements the 15 MCP tools for indexing and querying ([source](https://github.com/DeusData/codebase-memory-mcp/tree/main/src/mcp))

## Summary

- The build process for codebase-memory-mcp from source requires only a C compiler, zlib headers, and git.
- Run [`scripts/build.sh`](https://github.com/DeusData/codebase-memory-mcp/blob/main/scripts/build.sh) to generate a static binary at `build/c/codebase-memory-mcp`.
- Add `--with-ui` to include the 3-D graph visualization interface.
- Use `--version` and `--arch` flags to create reproducible, architecture-specific builds.
- All grammar dependencies are vendored; the Makefile statically links tree-sitter grammars and zlib.

## Frequently Asked Questions

### What are the minimum system requirements to build codebase-memory-mcp from source?

You need a C/C++ compiler (GCC or Clang), zlib development headers, and git. The repository vendors all tree-sitter language grammars, so no Node.js, Python, or other language runtimes are required for compilation.

### How do I compile the binary with the interactive 3-D graph UI?

Pass the `--with-ui` flag to the build script: `scripts/build.sh --with-ui`. This sets the make target to `cbm-with-ui` instead of the default headless `cbm` target, embedding the visualization components into the final static binary.

### Can I cross-compile codebase-memory-mcp for different architectures?

Yes. Use the `--arch` flag to specify the target architecture: `scripts/build.sh --arch x86_64` or `scripts/build.sh --arch aarch64`. You can also override the compiler by setting environment variables like `CC=gcc-14 CXX=g++-14` before invoking the script.

### Where does the build script place the compiled binary?

The script outputs the final static binary to `build/c/codebase-memory-mcp` relative to the repository root. This location is created fresh on each build after cleaning previous artifacts to ensure reproducible compilation.