Skip to main content

mcp-codebase-cartography

This repository hosts the code for an MCP server exposing various tools aimed at efficiently exploring codebases without wasting tokens, using AST-based tools and graph representations.

Usage

MCP configuration mcp.json:

{
  "servers": {
    "mcp-codebase-cartography": {
      "type": "stdio",
      "command": "uvx",
      "args": ["mcp-codebase-cartography", "serve"]
    }
  }
}

Building from source

The server ships a native extension (python-bindings/) built with maturin. From python-bindings/, build and install it into the active virtual environment:

maturin develop --release

or build a wheel and install it:

maturin build --release
pip install target/wheels/mcp_codebase_cartography-*.whl

Installing from PyPI

The package is published to PyPI. Run it without installing via uvx, or install it with pip:

uvx mcp-codebase-cartography serve
pip install mcp-codebase-cartography

Releasing

Releases are cut from semver tags. The version lives in python-bindings/Cargo.toml (package.version) and is read dynamically by pyproject.toml.

  1. Bump package.version in python-bindings/Cargo.toml.
  2. Run the quality gates (cargo clippy, cargo test, uvx ruff check python-bindings, uv run pyrefly check python-bindings).
  3. Commit and push a matching tag: git tag v0.1.0 && git push origin v0.1.0 (or jj tag set v0.1.0).

Pushing a vMAJOR.MINOR.PATCH tag triggers .github/workflows/release.yml, which builds the sdist and wheels, verifies the tag matches the package version, publishes to PyPI, and creates a GitHub release with the artifacts.

Prerequisite: PyPI Trusted Publishing must be configured for the pypi GitHub environment so the workflow can publish without a token.

Repository root

The server indexes the repository root, discovered from the process working directory by walking up until a VCS marker (.git or .jj) is found. Run the server from the repository root (or set the working directory of the MCP client to it) so the tools operate on the intended codebase.

Tools

The various exposed tools by this server are:

  • get_codebase_map(max_depth: int = 2): Returns the root folder directory tree as a structured object, filtering out ignored files (.git, node_modules, build dirs). Each node has a name, workspace-relative path, kind (dir or file), and nested children; directories truncated by max_depth carry a collapsed_entries count of omitted entries. Gives the agent a macro overview of the structural layout.

  • get_file_structure(file_path: string): Preferred over standard file reading. Returns a file's structured view: its workspace-relative path, unique imports, and each declaration's metadata and signature (the declaration's first line). Returns {path, imports: [string], symbols: [{name, kind, line_start, line_end, signature}]}.

  • search_codebase(pattern: string, extension: string | undefined, max_results: int = 10): Runs regex search over indexed files using an ultra-fast in-memory/ripgrep backend. Returns matching files and snippets truncated to 1 line of context.

  • get_symbol_definition(symbol_name: string, file_path: string | undefined): Fetches the implementation code for a single symbol by name without returning the rest of the file. Returns the extracted source string of the AST node. Use this to drill into a symbol's body after locating it via get_file_structure.

  • get_downstream_refs(symbol_key: string, max_depth: int = 2): Traverses the reference graph to list the transitive callers and impact paths of a symbol — the symbols/files that depend on, call, or reference it — up to max_depth hops. Helps evaluate impact before modifying code. Returns {callers: [{symbol, kind, file, line_start, line_end, depth}], paths: [{path}]} with workspace-relative paths. symbol_key is a bare name or file:name to disambiguate; resolution is conservative and name-based (lexical) with ambiguity errors where applicable.

  • get_upstream_refs(symbol_name: string): Finds every reference site for this symbol — the files and lines where it is called, used, or referenced across the codebase. Upstream results are direct reference sites with workspace-relative paths and the surrounding source line as context. Returns [{file, line, context}]. Resolution is conservative and name-based (lexical) with ambiguity errors where applicable.

  • get_ast_diff(base_ref: string = "HEAD"): Summarizes code changes structurally across commits or uncommitted working trees. Filters out formatting and whitespace changes. Returns a text summary listing modified, added, or deleted functions/classes.

    JJ is an optional diff backend, not an installation requirement. Git repositories (a .git directory) use Git without needing jj. Only JJ-backed repositories (a .jj directory) require the jj executable, and only when calling get_ast_diff; if it is missing, the tool returns a clear error. CI installs jj solely for integration coverage.

Metadata

Release files for mcp-codebase-cartography 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-codebase-cartography 1.0.0
File Size Uploaded
mcp_codebase_cartography-1.0.0.tar.gz 74.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mcp-codebase-cartography 1.0.0
File Interpreter ABI Platform
mcp_codebase_cartography-1.0.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
mcp_codebase_cartography-1.0.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details
mcp_codebase_cartography-1.0.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details

Total release size: 7.4 MB

Release files / mcp_codebase_cartography-1.0.0.tar.gz

Download URL mcp_codebase_cartography-1.0.0.tar.gz
Size 74.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6ee2be1ada175c38c1c7651aaeab5bddbc1b336604144a828eabfafe3d6f66fd
BLAKE2b-256 checksum
How to use checksums
5a3b1624e594ed9a9ced31a9c72fd2f5da377857741623d2faff1918298c4778
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mcp_codebase_cartography-1.0.0-cp312-abi3-win_amd64.whl

Download URL mcp_codebase_cartography-1.0.0-cp312-abi3-win_amd64.whl
Size 2.3 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9df8fb14dca597cb3e964f7e46a35f77317ede1fe05b49997b82076735970688
BLAKE2b-256 checksum
How to use checksums
7b37e28f91b2697a502e8ffcdf769a15efeb7674f8db3cdb867776972ca88259
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mcp_codebase_cartography-1.0.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mcp_codebase_cartography-1.0.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
6a187521f7ec3ef9580ac37b8507073cdfe9c9f2269aef39d138868b3f4ca340
BLAKE2b-256 checksum
How to use checksums
edae0bcbb9b55208ee72b636aa8cf93917764dfc1d006caab3ef19001fe59eda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mcp_codebase_cartography-1.0.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL mcp_codebase_cartography-1.0.0-cp312-abi3-macosx_11_0_arm64.whl
Size 2.5 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bf13d04cc6129bf5025edecf6e4d3f9d99122a74cf713dd24ce1fcbd1715e90f
BLAKE2b-256 checksum
How to use checksums
b087be8a219ca654f0af74889a9e06c1e3362893d2538859881fcf7039a3fed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

1.1.0

4 release files

This release

1.0.0 This release

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page