codenav-mcp

Python code navigation and type-checked refactoring over MCP, powered by Astral's ty.
Use it to follow typed calls through imports and dependency injection, find structural
Protocol implementations, and preview refactors that touch several files. Use grep
for exact-name text lookups and Read for a known file or excerpt.
An agent asks by name, and ty follows the types to answer. For an edit, codenav builds the change in memory, offers
names it found in strings, docs and shell heredocs as optional sites, and writes only if ty reports no new type
errors. Every change has a preview ID to apply and an undo ID.
What it can do
- Follow typed code: find callers and Protocol implementations across imports and dependency injection.
- Preview refactors: rename symbols, change signatures and move definitions with their linked usages.
- Catch overlooked sites: surface mentions in strings, docs and shell heredocs for review.
- Review and undo: inspect type-checked previews before applying them, then undo stored changes.
For agent workflows, exact calls and parameters, see the agent tool guide.
Quick start
Install uv and Node.js 22+, then run this from your project folder. mcps prompts you to choose agents and registers CodeNav locally:
npx @danielxir96/mcps add illescasDaniel/codenav-mcp
When installing for OpenCode, CodeNav requests codemode: false so its tools appear directly to the agent.
See the OpenCode setup for older installers and manual registration.
claude mcp add codenav -- uvx codenav-mcp
codex mcp add codenav -- uvx codenav-mcp
For OpenCode, use the configuration entry with codemode: false.
Some models need a prompt to pick up new tools (see What has been measured). Add this to
the project's AGENTS.md or CLAUDE.md.
For Python symbol navigation and refactors, start with Codenav’s `lookup` or `search`.
If those tools aren’t visible, use your harness’s MCP tool catalog or discovery mechanism to find and invoke them before falling back to grep, sed, or hand edits.
If Codenav is unavailable, briefly explain why and proceed.
Requirements and limits
- Python 3.11 or later. ty installs with codenav, and a workspace's own ty takes priority when present.
- Python navigation and writes cover
.py and .pyi files. Positions use 1-based lines and UTF-16 columns.
- The write gate checks types only. Run the relevant tests and documentation checks after applying a change.
- Static analysis can't resolve every dynamic reference, mock, framework registration or library extension; review
the optional sites a rename offers. Known limits
What has been measured
Small models (Claude Haiku 5.5, GPT-6 Luna) did real tasks on one project with and without codenav, and every run was
graded against a hand-checked key. These are pilots with a few runs per task: read them as direction, not effect
sizes.
- Completeness on a big rename: a 35-file rename where the tests can't see 4 of the files (an example, a doc page,
two shell scripts). Luna with codenav updated all 4 in 4 of 5 runs, without it in 0 of 4.
- Effort: Haiku was usually complete either way, but with codenav it used 161k-359k input tokens against
368k-519k.
- Adoption: Haiku used codenav unprompted in 17 of 18 runs. Luna used it in 0 of 12 runs without the hint line
above, and 12 of 13 with it.
- Where it didn't help: on tasks where names are distinct and the tests thorough, careful grep was just as
correct, and codenav sometimes cost more tokens.
Findings, data and the harness to repeat the runs: Research.
How it is tested
A refactoring tool must not break code quietly, so codenav is tested in several ways:
- About 1,300 tests: unit tests, plus about 350 integration tests that run the tools against a real ty server.
- Property tests: about 190, with Hypothesis and generated Python (hypothesmith), including a state machine for
preview, apply and undo, and CrossHair symbolic checks.
- A refactor fuzzer: random renames, moves and signature changes on real projects (srxy, click, tomlkit), each
checked against the project's own tests and ty. 187 refactors so far, none silently broke code.
- Differential checks: references agree with jedi on 40 of 40 symbols, and renames with rope on 38 of 40; the 2
differences are call sites rope misses.
- Mutation testing (mutmut) of the modules where a wrong edit would go unnoticed, to find tests that don't check
enough. The suite catches about 84% of the mutants there; the gaps that mattered got tests.
- Agent pilots: the small-model runs above, graded by hand.
The results and their data are in Research; how to run each check is in
Hardening checks.
Documentation
- Tool reference
- Migrating from 1.x
- Host setup, workspace selection and environment variables
- Local setup and tests
- Research: measured results and data
- Documentation index
License
MIT