Skip to main content
Glama
mcp-codebase-server

mcp-codebase-server

by codeyrk

mcp-codebase-server

A security-first MCP (Model Context Protocol) server for C++ monorepos. Gives Claude Desktop and VS Code deep codebase awareness — symbol search, impact analysis, branch diff review, linting, and format checking — without ever sending raw source code to external AI.


Security Guarantees

Guarantee

How

Zero code egress

Raw source code never leaves your machine

Pre-index secret scrubbing

Known secret patterns redacted before SQLite index

Structured metadata only

AI receives symbol graphs, signatures, dependency maps — never file contents

Output validation

Every tool response is scanned before returning — defence in depth

LDAP identity binding

Every tool call stamped with developer identity (or OS username in degraded mode)

stdio transport

Zero inbound network ports


Related MCP server: claude-context-local

Prerequisites

Requirement

Notes

Node.js 20+

Required for --env-file support

C++ monorepo on disk

Set REPO_PATH in .env

Docker (optional)

Required only for run_linter (clang-tidy)

clang-format (optional)

Required only for format_check — brew install clang-format


Quick Start

# 1. Install dependencies
npm install

# 2. Copy and edit the environment file
cp .env.example .env
# Edit .env — at minimum set REPO_PATH=/absolute/path/to/your/monorepo

# 3. Build
npm run build

# 4. Index the codebase (first time, and after large changes)
npm run index

# 5. Start the server
npm start
# Should print: [server] mcp-codebase-server v0.1.0 ready

Environment Configuration (.env)

# REQUIRED
REPO_PATH=/absolute/path/to/your/monorepo

# Optional overrides
# INDEX_DB_PATH=$HOME/.mcp-server/index.db
# AUDIT_LOG_DIR=$HOME/.mcp-server/audit
# LOG_LEVEL=info

# Docker — required for run_linter (clang-tidy)
DOCKER_CONTAINER=your-build-container-name
COMPILE_COMMANDS_PATH=/container/path/to/compile_commands.json
CONTAINER_REPO_PATH=/container/path/to/repo
CLANG_TIDY_BIN=/usr/lib/llvm-17/bin/clang-tidy   # full path if not on container PATH

# Host clang-format — required for format_check
CLANG_FORMAT_BIN=/opt/homebrew/bin/clang-format   # brew install clang-format

# LDAP / Active Directory (leave blank for OS-username fallback)
# LDAP_URL=ldap://ldap.yourcompany.com:389
# LDAP_BASE_DN=dc=yourcompany,dc=com
# LDAP_BIND_DN=cn=mcp-service,ou=serviceaccounts,dc=yourcompany,dc=com
# LDAP_BIND_PASSWORD=

Connecting to Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "codebase": {
      "command": "node",
      "args": [
        "--env-file=/absolute/path/to/mcp-codebase-server/.env",
        "/absolute/path/to/mcp-codebase-server/dist/index.js"
      ]
    }
  }
}

Restart Claude Desktop. The 8 codebase tools will appear in the tool list.


Connecting to VS Code (Cline / Continue)

Add to .vscode/mcp.json in your workspace:

{
  "servers": {
    "codebase": {
      "type": "stdio",
      "command": "node",
      "args": [
        "--env-file=/path/to/mcp-codebase-server/.env",
        "/path/to/mcp-codebase-server/dist/index.js"
      ]
    }
  }
}

Available Tools (8 total)

Tool

What it returns

search_code

Ranked list of symbols matching a name, concept, or keyword. Never raw code.

get_symbol

Full structural profile: location, signature, includes, sibling symbols, complexity.

explain_file

Everything a file defines + what it includes + git change history + architectural role.

index_stats

Index health: symbol count, file count, CMake targets, include edges. Call first if results seem incomplete.

Impact Analysis

Tool

What it returns

blast_radius

Given a file or symbol: all files that need recompilation, affected CMake targets, risk level (low/medium/high/critical), test suites to run.

diff_review

Given a branch name: all changed files with their symbols, aggregate blast radius, risk level, and test suites. Essential before code review or merge.

Code Quality

Tool

What it returns

run_linter

Runs clang-tidy inside the build container. Returns structured findings (file, line, severity, rule, message). Never raw code. Requires Docker.

format_check

Runs clang-format --dry-run on host. Returns structured violations (file, line, col). Never raw diffs. Requires clang-format binary.


Typical Workflow

1. diff_review branch=feature/my-branch
      → Lists changed files + symbols + risk level

2. blast_radius file=src/core/MyChangedHeader.hpp
      → Shows full recompilation impact

3. run_linter files=[changed files from step 1]
      → Checks for clang-tidy issues

4. format_check files=[changed files from step 1]
      → Confirms formatting is clean before merge

Indexer

The indexer uses tree-sitter for AST-accurate C++ symbol extraction:

  • Functions, methods (including qualified Foo::bar()), constructors, destructors

  • Operator overloads (operator==, operator[])

  • Template functions and class templates

  • Classes, structs, enums

  • Namespace context preserved

Run the indexer:

npm run index          # indexes REPO_PATH from .env

Rebuild after large file additions/deletions:

rm ~/.mcp-server/index.db && npm run index

The index also builds:

  • Include graph — transitive #include dependency map (used by blast_radius)

  • CMake target map — which targets own which files (used by blast_radius and diff_review)


Secret Scrubbing

Secrets are redacted before indexing — they never enter the SQLite database.

Redacted patterns include:

  • PEM private keys

  • API keys and auth tokens

  • Hardcoded passwords

  • Internal IP addresses

  • Flask / Django secret keys

  • Base64-encoded credentials

All redacted values are replaced with [REDACTED:<type>] in signatures.


Audit Logs

Every tool call is logged to ~/.mcp-server/audit/YYYY-MM-DD.jsonl.

Each entry contains: timestamp, session ID, developer identity, tool name, query, files accessed, result count, duration.

Logs never contain: raw code, secret values, or file contents.


Project Structure

mcp-codebase-server/
├── src/
│   ├── index.ts                  # Entry point — boots server, registers all 8 tools
│   ├── config/
│   │   └── config.ts             # Zod-validated config from env vars + ~/.mcp-server/config.json
│   ├── audit/
│   │   └── audit-logger.ts       # Structured JSONL audit logging (never logs code)
│   ├── security/
│   │   ├── secret-scrubber.ts    # Pre-index secret redaction pipeline
│   │   ├── output-validator.ts   # Post-response secret pattern scanner
│   │   └── ldap-identity.ts      # LDAP developer identity (OS username fallback)
│   ├── indexer/
│   │   ├── cpp-indexer.ts        # tree-sitter AST C++ parser → SQLite symbol index
│   │   ├── include-graph.ts      # #include transitive dependency graph
│   │   ├── cmake-parser.ts       # CMakeLists.txt target → file mapping
│   │   └── index-runner.ts       # CLI entry point for npm run index
│   └── tools/
│       ├── search-code.ts        # search_code
│       ├── get-symbol.ts         # get_symbol
│       ├── explain-file.ts       # explain_file
│       ├── index-stats.ts        # index_stats
│       ├── blast-radius.ts       # blast_radius
│       ├── diff-review.ts        # diff_review
│       ├── run-linter.ts         # run_linter (clang-tidy via Docker)
│       └── format-check.ts       # format_check (clang-format on host)
├── scripts/
│   ├── verify-blast-radius.ts
│   ├── verify-diff-review.ts
│   ├── verify-run-linter.ts
│   ├── verify-run-linter-live.ts
│   └── verify-format-check.ts
├── .env.example                  # Template — copy to .env and fill in
├── package.json
└── tsconfig.json

Roadmap

Phase

Status

Items

Phase 1

✅ Complete

Symbol index, code search, file explanation, secret scrubbing, LDAP audit

Phase 2

✅ Complete

tree-sitter parser, include graph, CMake map, blast_radius, diff_review, run_linter, format_check

Phase 3

Planned

Mermaid diagram generation (include graph, CMake targets, C4 architecture)

Phase 4

Planned

Convention registry, project memory, git history context

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides semantic code intelligence to help users search, navigate, and analyze entire codebases using plain English. It enables Claude to perform architectural overviews, bug detection, and refactor suggestions through local semantic search and keyword indexing.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides Claude Code with local semantic search and indexing of your codebase using AST-aware chunking and hybrid search, enabling deep code understanding without sending data to the cloud.
      56 PyPI
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      Provides precise C++ code semantic analysis for AI coding tools like Claude Code and Cursor by integrating clangd static analysis, enabling symbol definition lookup, reference tracking, and hover information.
      1
      -