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.
- Bump
package.versioninpython-bindings/Cargo.toml. - Run the quality gates (
cargo clippy,cargo test,uvx ruff check python-bindings,uv run pyrefly check python-bindings). - Commit and push a matching tag:
git tag v0.1.0 && git push origin v0.1.0(orjj 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 aname, workspace-relativepath,kind(dirorfile), and nestedchildren; directories truncated bymax_depthcarry acollapsed_entriescount 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-relativepath, uniqueimports, and each declaration's metadata andsignature(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 viaget_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 tomax_depthhops. Helps evaluate impact before modifying code. Returns{callers: [{symbol, kind, file, line_start, line_end, depth}], paths: [{path}]}with workspace-relative paths.symbol_keyis a bare name orfile:nameto 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
.gitdirectory) use Git without needingjj. Only JJ-backed repositories (a.jjdirectory) require thejjexecutable, and only when callingget_ast_diff; if it is missing, the tool returns a clear error. CI installsjjsolely for integration coverage.
Metadata
Release files for mcp-codebase-cartography 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mcp_codebase_cartography-1.1.0.tar.gz | 74.9 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_codebase_cartography-1.1.0-cp312-abi3-win_amd64.whl | CPython 3.12 | abi3 | Windows x86-64 | Details |
| mcp_codebase_cartography-1.1.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.1.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.1.0.tar.gz
| Download URL | mcp_codebase_cartography-1.1.0.tar.gz |
|---|---|
| Size | 74.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bac5e0a31e1718ba3630c745aeaedca55faa775982cc9e01e2993c6d35185ba
|
|
BLAKE2b-256 checksum How to use checksums |
86bd3deea41b3cc44594c7cbe6a8e71a0bcbf9c570c388e3385463bf972aa389
|
| 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.1.0-cp312-abi3-win_amd64.whl
| Download URL | mcp_codebase_cartography-1.1.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 |
792dac2b63f3367b18a695a2bae1cbaae895c6bca9bb3be24863dcb094ce2482
|
|
BLAKE2b-256 checksum How to use checksums |
d97b26850f0247e0fdd7e4752484df800741dbb095c66b4af7f2c51f5c8db84c
|
| 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.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mcp_codebase_cartography-1.1.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 |
982dc22c3e5517b3aee197d68fc7bb53e094d5614260882af1efd328878eb055
|
|
BLAKE2b-256 checksum How to use checksums |
23b972c2c668847bd0ff958d2a0c8b417b08ded4d23f3e4e8da80be6487e8690
|
| 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.1.0-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | mcp_codebase_cartography-1.1.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 |
11b777a13266a10c147da1d0aec0c136c6e26e9fc6f3ef2acc2361fc582338c0
|
|
BLAKE2b-256 checksum How to use checksums |
52a0cda325790b94922af41cec25139f2398865ebddf772049d6bc77a8760fb4
|
| 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}
|