Skip to main content
Glama
MCP Codebase Inspector

MCP Codebase Inspector

by crizmo

MCP Codebase Inspector

A tiny read-only MCP server that gives an LLM safe, on-demand access to a local codebase. The model discovers the tools itself, picks the right ones, and answers from real files instead of guesses.

Built to demonstrate the Model Context Protocol end to end: stdio transport, tool and prompt discovery, runtime path confinement, and a real model driving the loop (Big Pickle via OpenCode). No API key is needed.

Why this exists

Most MCP tutorials call hardcoded functions and call it an agent. This one doesn't:

  • The server registers capabilities; the client discovers them at runtime.

  • The model chooses tools and arguments — no keyword matching.

  • Every tool routes through one shared path guard, so "read-only" is enforced, not promised.

  • The whole thing is ~150 lines of server code and uses only the mcp SDK plus the standard library.

Related MCP server: Local Code MCP Server

What it exposes

Four tools:

Tool

Purpose

project_summary(path)

File/line counts, languages, largest files

list_directory(path)

One directory level, with sizes

read_file(path, start_line, max_lines)

Numbered lines from any offset, capped

search_code(query, path, file_glob, max_results)

Regex search → file:line:match

One prompt: codebase_report(path) tells the model how to chain the tools into a short report.

Vendor directories and files over 2 MB are skipped. Paths are confined to MCP_ROOT (default: launch directory); traversal and symlinks pointing outside are rejected.

Quickstart

git clone https://github.com/crizmo/mcp-codebase-inspector.git
cd mcp-codebase-inspector
python3 -m pip install -e .
opencode mcp add codebase -- "$(python3 -c 'import sys;print(sys.executable)')" mcp_server.py
opencode run --model opencode/big-pickle --auto \
  "Use the codebase MCP tools to analyze this project. What does it do, main components, and two improvements?"

Requires Python 3.10+ and opencode. opencode mcp add writes a local opencode.json with this machine's Python path (the file is gitignored, so the repo stays portable).

To inspect a different directory, set MCP_ROOT in opencode.json:

"environment": { "MCP_ROOT": "/path/to/project" }

Example output

> build · big-pickle
⚙ execute {"code":"const [summary, root] = await Promise.all([
    tools.codebase.project_summary({ path: \".\" }),
    tools.codebase.list_directory({ path: \".\" })]); return { summary, root };"}

## What it does
mcp-codebase-inspector is a tiny read-only MCP server that gives an LLM safe, on-demand
access to a local codebase...

## Two concrete improvements
1. Cap read_file inputs.
2. Return a readable error on path escape.

Those two suggestions were real bugs. Both were fixed — this is the loop actually working.

Other commands

python3 mcp_inspect.py                              # raw MCP protocol
python3 -m unittest discover -s tests -t . -v       # 4 trust-boundary tests

mcp_inspect.py is the fastest way to learn MCP: it prints the exact requests and responses the model sees.

VS Code: open the folder → Terminal → Run Task → Big Pickle: analyze this repo, MCP protocol inspector, or Run tests.

Layout

mcp_server.py          server: tools, prompt, path guard
mcp_inspect.py         tiny stdio client that prints the protocol flow
tests/                 unittest checks for traversal, symlinks, line and result caps
pyproject.toml         package metadata and console entry points
opencode.json          generated by `opencode mcp add` (gitignored)
.github/workflows/     CI: install + unit tests on Python 3.10 and 3.13

Design decisions

  • Read-only by construction. No write, delete, or execute tools.

  • One guard, all callers. _path() and _files() are the only places that resolve paths.

  • Stdlib first. Only the MCP SDK is a dependency.

  • No framework. unittest is enough.

MIT licensed.

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 secure and efficient tools for codebase analysis, including file management, metadata retrieval, and dependency tree traversal. It allows LLMs to explore project structures and search for configuration files within a restricted root directory.
      21 npm
      3
      MIT
    • F
      license
      B
      quality
      D
      maintenance
      Provides LLMs with safe, read-only access to local codebases for searching, reading files, and finding function definitions. All source code remains local, ensuring privacy while enabling AI assistants to explore project structures and functionality.
      4
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables language models to explore and analyze source code repositories through read-only tools for listing directories, reading files, searching code, finding symbols, and inspecting git history, with strict sandboxing and security controls.
      MIT