codenav-mcp
codenav-mcp provides Python code navigation and type-checked refactoring over MCP using ty.
Inspect the active workspace and file structure via
workspace,outline, anddiagnostics.Navigate code by symbol or position with
hover,definition,references,search_symbol,symbol_info,callers, andimplementations.Preview, apply, and undo type-checked refactors with
rename_symbol,change_signature,edit,edit_symbol,move, andquick_fix.Check edits for new type errors against a git revision using
verify_changes.Run multiple independent tool calls in one request using
batch.
Integrates with the project's Git repository: it detects worktrees of the same repository to decide which checkout is being navigated, and it compares the working tree's type errors against a Git revision (default HEAD) to report which errors an edit gained or lost.
Provides type-resolved navigation and editing for Python codebases (backed by ty's language server): symbol lookup and outline, go-to-definition and references resolved through real type inference (including injected parameters and dataclass fields), call-site/guard call hierarchy, Protocol implementation discovery, and type-check diagnostics. The same resolution powers type-checked refactors — rename across a workspace, change a signature and rewrite every call site, move functions/classes/modules, and apply ty quick fixes — with previews, undo, and an error-count gate before anything is written.
Used automatically by the write/refactor tools to sort imports in files touched by a move (only where the imports were already sorted), keeping refactored Python files tidy.
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.
Related MCP server: LSP MCP
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-mcpWhen 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-mcpFor 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
.pyand.pyifiles. 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
License
Available Tools
20 toolsapply_editADestructive
Write a previewed edit (the id comes from a write tool's preview). The applied edit keeps that id, so undo_edit(id) reverts it. Fails if any file changed since the preview.
Inputs: id (required), allow_large.
batchADestructive
Run several codenav tool calls in ONE request (saves round-trips and tokens).
Example: batch(calls=[{"tool": "outline", "args": {"file_path": "src/a.py"}}, {"tool": "symbol_info", "args": {"name": "Cart.total"}}]). Works for reads and writes
alike, e.g. two edits in different files: [{"tool": "edit", "args": {"file_path": "src/a.py", "old_string": "x = 1", "new_string": "x = 2"}}, {"tool": "edit_symbol", "args": {...}}].
Each call takes the same arguments as the tool called alone (args is that tool's
parameter object) and behaves as if you had called it separately: calls run in order,
so a later call sees what an earlier write changed, and every write is type-checked,
previewed/applied and undoable on its own (see its own section for the edit id).
The result has one numbered section per call, then a summary line.
stop_on_error: stop at the first call that fails or does not apply a write (the
rest are skipped and listed). Default (null): stop when the batch contains a write,
keep going when it only reads. Up to 25 calls; batch cannot be nested. A call cannot
refer to an earlier call's result ("$1" is refused): make the calls independent.
Annotated as possibly destructive because a batch may contain write calls; a batch made only of read tools (outline, symbol_info, hover, ...) writes nothing.
Not atomic: calls that already ran stay applied (each has its own undo id). Line/column positions you computed before the batch may be stale after an earlier edit in it, so prefer name-based calls (symbol_info, edit_symbol, rename_symbol) after writes. A preview id is invalid once a later call changes the same file.
Inputs: calls (required), stop_on_error.
callersARead-only
Who calls this function? Example: callers(name="create_user").
Narrower than references, since it leaves out imports and type-only usages and only lists actual call sites.
name resolves the same way as symbol_info (dotted Class.method accepted;
pass file_path to disambiguate a common name). query is accepted as an
alias for name. The first line is the exact count of callers; limit
(default 200) caps how many are listed. A function that is only used as a
value (passed or stored, never called) gets a note saying so. For a method of
a class that has subclasses the reply says overriding methods are not included.
Callers in files outside the workspace are not shown.
Inputs: name, limit, query, file_path.
change_signatureADestructive
Add, remove or reorder a function's parameters and update every call site. Example:
change_signature(name="send_mail", add=[{"name": "retries", "annotation": "int", "default": "3"}]).
name is a function, a method (Class.method) or a class (its __init__).
add: list of{"name", "annotation"?, "default"?, "value"?, "position"?, "keyword_only"?}.defaultis written in the definition and callers need not change;valueis inserted at every call site asname=value(give both for a required-at-call parameter with a default).positionis a 0-based index among the parameters (self/cls not counted); the default is the end. One ofdefault/valueis required.remove: parameter names; the matching argument is dropped at each call.reorder: the complete new order of the named parameters. Positional arguments are rearranged, and turned into keywords where a position would no longer line up.
Call sites come from the type checker's references, so calls through injected
dependencies and typed attributes are found, not just textual matches. Overriding
methods get the same change (include_overrides). Calls using *args/**kwargs
and places where the function is passed around as a value are listed as manual
work rather than guessed at. Unresolved alias calls, calls with comments, and
effectful argument reorderings are also listed for manual review. Decorators
and docstrings mentioning removed parameters produce notes. Writes when new errors stay within max_new_errors
(default 0), else previews with an id for apply_edit; apply=false always previews.
Inputs: name (required), add, apply, remove, +5 more.
definitionARead-only
Go to the definition of the symbol at a position.
line and column are 1-indexed. column is a UTF-16 character offset
on the line (not a visual/display column): a leading tab counts as one
character.
Resolves through ty's type inference, so this works even when the call
site only has a typed parameter/attribute (e.g. services.some_method()
where services: AppServices is a constructor argument), not just
direct references to a name in scope. A module with a .pyi stub gives
the stub first and the .py implementation as an Also: line. Library
locations show as <stdlib>/... or <site-packages>/....
Inputs: line (required), column (required), file_path (required).
diagnosticsARead-only
Get ty's type-check diagnostics (errors/warnings) for a single file.
Each line starts with the file's workspace-relative path, then line:column.
Inputs: file_path (required).
editADestructive
Edit text in a Python file, type-checked: edit(file_path="src/app.py", old_string="x = 1", new_string="x = 2").
Use this for changes that are not a whole definition (a few lines, an import, a
module-level statement) or for rewriting a whole file (new_text). To replace,
add or delete a function/method/class by name use edit_symbol.
Give either old_string -> new_string (old_string must match exactly once unless
replace_all=true; the reply gives the matching lines and the replacement count) or the
complete new_text (also creates a new file), never both. Each text is at most 1,000,000
characters. The text must be valid Python; new lines take the file's line endings (CRLF
stays CRLF). Writes when the new errors in the file and in the files that import it
stay within max_new_errors (default 0, null = no limit); otherwise nothing is written
and the result lists the errors plus an id for apply_edit. apply=false always
previews. undo_edit reverts.
Inputs: file_path (required), apply, new_text, new_string, +4 more.
edit_symbolADestructive
Replace, add or delete a function, method or class by name. Examples:
edit_symbol(action="replace", name="Cart.total", source="def total(self): ..."),
edit_symbol(action="insert", file_path="src/utils.py", name="parse", source="def helper(): ..."),
edit_symbol(action="delete", name="legacy_parse").
action="replace":name(the symbol; dottedClass.methodok) andsource(the complete new definition, decorators included: anything not given is dropped and the result says so). Re-indented to the old one's place, file style kept. A changed signature shows up as errors at call sites; to change a signature and its callers together usechange_signature.action="insert":source(the new definition) andfile_path.positionsays where, relative toname: "after" (default whennameis given) / "before" a symbol defined in the file (a method likeCart.totalplaces it inside that class), "into" a class (appended to its body), or "end" of the file (default withoutname). PEP 8 blank lines, matching indentation. Refuses a name that already exists in that scope (use "replace").action="delete":nameonly. Deletes only when nothing uses it, otherwise lists the users and writes nothing (force=truedeletes anyway and shows what breaks). Imports that are the only remaining users are removed (prune_imports). Uses the type checker cannot see (strings,getattr, docs) are listed and the deletion is previewed. Comments directly above a definition are kept.
file_path narrows name when several symbols share it. imports (replace/insert) is a
list of import statements the new code needs, added if missing. Writes when the new errors
stay within max_new_errors (default 0, null = no limit); else previews with an id for
apply_edit; apply=false always previews. undo_edit reverts.
Inputs: action (required), name, apply, force, +6 more.
hoverARead-only
Get type/documentation info for the symbol at a position.
line and column are 1-indexed. column is a UTF-16 character offset
on the line (not a visual/display column): a leading tab counts as one
character. Put the position on the symbol's name: on a def/class
keyword there is no hover. Paths outside the workspace are refused
before the file is read.
Inputs: line (required), column (required), file_path (required).
implementationsARead-only
Find concrete classes that structurally satisfy a Protocol port.
Many hexagonal codebases define ports as Protocols that adapters never
subclass explicitly, so ty's own implementation/typeHierarchy return
nothing for them. This scans classes under SOURCE_ROOT (the whole
workspace by default; see CODENAV_MCP_SOURCE_ROOT) whose method names
cover the protocol's, then verifies each candidate with ty's real type
checker via an in-memory probe file (never written to disk) — so a
result means "assignable", not just "same method names". port_name
must itself resolve to a Protocol class; other classes' subclasses are
better found with references/symbol_info. name and query are
accepted as aliases for port_name. file_path narrows the port lookup
to one file when the name exists in several. Members inherited from
same-workspace base classes, and fields/properties declared by the port,
count when matching names. Directories listed in
CODENAV_MCP_EXTRA_SOURCE_ROOTS (e.g. tests) are scanned too; their
matches (test doubles) are listed under a separate heading.
Inputs: name, query, file_path, port_name.
moveADestructive
Move a function/class to another file, or a whole module file, and fix every import. Examples:
move(name="parse_date", to_file="src/app/dates.py") (one symbol),
move(file_path="src/app/util.py", to_file="src/app/common/helpers.py") (the whole module).
With name: moves that module-level function or class (file_path narrows which one).
The destination is created if missing. The code travels with the imports it needs
(relative ones made absolute), imports only the moved code used are dropped from the old
file, and if the old file still uses it, it imports it from the new place
(keep_reexport=true always leaves that import so old from old import name keeps
working). Every from old import name elsewhere is rewritten. A move that would create a
module-level import cycle is refused unless allow_import_cycle=true. Importers the move
cannot update (too many, unreadable, unparsable) are reported by name and held back unless
apply=true and allow_large=true; uses through the old module (old.name) and strings
are listed for you.
Without name: file_path is the module to move or rename (required); every
from old import x, import old [as y] and from package import old is rewritten
(a relative import stays relative when the module stays in its package, else it becomes
absolute). Strings and docs naming the old path are listed.
Writes when the new errors stay within max_new_errors (default 0); else previews with
an id for apply_edit; apply=false always previews. undo_edit reverts.
Inputs: to_file (required), name, apply, file_path, +4 more.
outlineARead-only
What's in this file? Example: outline(file_path="src/app/services.py").
Indented outline (classes, methods, functions, with line numbers) of a
Python file, so you can navigate a large file without reading it in full.
depth=1 lists only the top-level definitions. A file with a syntax error
gets a warning line first (the outline may be incomplete); a file that
contains a NUL byte is refused.
Follow up with hover/definition/references at a listed line, or
symbol_info by name.
Inputs: file_path (required), depth.
quick_fixADestructive
Apply ty's own fixes for a file's diagnostics (today: add the missing import). Example: quick_fix(file_path="src/app.py").
Looks at the file's diagnostics (narrow with line or a rule code such as
unresolved-reference), asks ty for the quick fixes, and applies them.
Imports are placed after the docstring and the existing imports, merged into
an existing from x import ... where there is one. When a diagnostic has
several equally good fixes (two modules that both export Path) nothing is
applied: the options are listed, and you repeat the call with choice set to
part of the title you want (choice="pathlib") or a 1-based choice number. Fixes that only silence the
error (# ty: ignore) are skipped unless allow_suppress=true.
Inputs: file_path (required), code, line, apply, +3 more.
referencesARead-only
Find all usages of the symbol at a position across the workspace.
line and column are 1-indexed. column is a UTF-16 character offset
on the line (not a visual/display column): a leading tab counts as one
character.
The first line is the exact total (N reference(s) in M file(s):). limit
(default 200) caps how many hits are listed; production code is listed before
tests. Hits in files outside the workspace are not shown.
Inputs: line (required), column (required), file_path (required), limit, +1 more.
rename_symbolADestructive
Rename a symbol everywhere it is used, type-checking the result before writing it.
Example: rename_symbol(name="UserService.create_user", new_name="register_user").
Give name (dotted Class.method accepted; file_path narrows it) or
file_path + line + column (1-indexed). Use parameter="x" with a
function's name to rename one of its parameters (keyword arguments at call
sites follow).
Built on ty's rename (imports, aliases, keyword arguments) plus what ty
misses: with linked=true (default) overriding methods in subclasses,
super().name() calls, and Protocol members together with the classes that
satisfy them are renamed as one, since renaming only one side would silently
break the override or the conformance. The result lists every extra member
it included, and the places still using the old name that the type checker
could not link (untyped attribute accesses, strings, comments, docs).
Writing: apply=true (default) writes when the new errors are within
max_new_errors (default 0); otherwise nothing is written and you get a
preview id for apply_edit. apply=false always previews. undo_edit reverts.
Inputs: new_name (required), line, name, apply, +6 more.
search_symbolARead-only
Search the whole workspace for a symbol by name (class, function, method, etc.).
Use this to find a symbol's file/position first, then pass that position
to definition/references/hover for precise, type-resolved navigation.
Returned positions point at the identifier name (not the class/def
keyword) and use the same character-offset column convention as the
other tools. Results include a SymbolKind label and are capped; hits in
files outside the workspace, and in nested git checkouts below it (a
vendored repo, a linked worktree), are not shown.
name is accepted as an alias for query. Narrow broad queries with
kind (SymbolKind labels, comma-separated: class, function,method,
interface, ...) and path. path is a workspace-relative prefix matched
against the start of each file's path (src/ matches src/..., but p also
matches plugins/...); a value with *, ? or [ is a glob matched against the
whole relative path (src/**/*.py; * also matches /). An absolute path inside
the workspace is accepted. Production code ranks before tests.
Loose fuzzy hits whose names don't contain the query are summarised as a
count; pass fuzzy=true to list them with a fuzzy marker.
A dotted query (Cart.total, pkg.mod.func) finds the name after the last dot
whose owner is the part before it (its class, or its module path).
Inputs: kind, name, path, fuzzy, +1 more.
symbol_infoARead-only
What is X and where is it used? Example: symbol_info(name="UserService.create_user").
One-call summary for a name: header, hover text, definition, and references grouped by file — the usual first lookup instead of chaining search_symbol → hover → definition → references by hand.
name is a symbol name, or a dotted Class.method to resolve a specific
method when the plain name is ambiguous. A dotted module path
(pkg.mod.func) resolves to the function in that module. Pass file_path
(relative to the workspace root) to disambiguate when several symbols share
a name elsewhere in the workspace; if it's still ambiguous, the candidates
are listed back so you can retry with a narrower name or file_path. Local
variables and parameters are not indexed, so they are not found by name.
query is accepted as an alias for name; passing both with different
values is refused.
Inputs: name, query, file_path, include_references.
undo_editADestructive
Revert an edit applied by the write tools (the latest one by default). The undo history keeps the last 20 edits of this server session; older ones, and ids that were already undone, cannot be reverted.
Refuses when any of its files was changed after the edit, so later work is never overwritten. An edit blocked by a newer one names that edit, which must be undone first.
Inputs: id.
verify_changesARead-only
What did the edits since a git revision break? Compares ty diagnostics now against since (default HEAD).
Run it after editing with any tool (your own Edit/Write included) to see the type errors the working tree has gained or lost relative to the last commit: the changed Python files and the files importing them are checked with the committed versions of the changed files substituted in for the "before" side. Read-only. A changed pyproject.toml, ty.toml or .ty.toml changes the rules for every file: then the whole project is checked and every current diagnostic is listed, because the old configuration cannot be re-checked.
Inputs: since, include_dependents.
workspaceARead-only
Which directory is codenav navigating, and why?
Also shows the source root, the write mode, the ty command and any configuration warnings. Use when results look like they come from the wrong checkout/worktree.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 20 tools
The tools mostly have distinct scopes: positional navigation, name search, symbol summaries, usage analysis, diagnostics, and type-checked editing. Minor overlap remains between edit and edit_symbol, and between symbol_info/search_symbol/references, but the descriptions give clear guidance on when to use each.
All names use lowercase snake_case, but the set mixes verb_noun forms (edit_symbol, rename_symbol, verify_changes), noun-only forms (hover, definition, references, callers), and noun_noun forms (symbol_info). It is readable, but there is no single predictable naming pattern across the 20 tools.
20 tools is on the heavy side, but the server covers several coherent areas: navigation, diagnostics, refactoring, undo/preview, and batching. Most tools earn their place, though some aggregator/tool pairs could potentially be consolidated.
The surface is very complete for type-aware navigation and refactoring: search, outline, hover, definition, references, callers, implementations, diagnostics, edits, rename, signature changes, move, quick fix, undo, and verify. Minor gaps include no explicit read-file/list-files or textual-search tool, which may be expected from the client rather than this server.
Maintenance
Related MCP Connectors
Persistent cloud workspaces for AI agents: run commands, edit files, use git and a browser.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Web scraping, Google SERP, Markdown and ChatGPT/Gemini answers as typed tools for AI agents.
Write, type-check and run AILANG in a sandbox, with Z3-proved contracts and docs search.
Related MCP Servers
- AlicenseBqualityDmaintenanceExposes TypeScript Language Server Protocol functionality to AI agents, enabling them to query types at specific positions, find definitions and references, get diagnostics, run type tests, and type-check inline code just like in an IDE.9540 npm3MIT
- AlicenseNot gradedqualityDmaintenanceProvides AI agents with language-aware code analysis through the Language Server Protocol, enabling tasks like getting code insights and diagnostics.194MIT
- AlicenseNot gradedqualityNot gradedmaintenanceExposes type-aware code navigation and fast file search to AI agents via language servers, enabling definitions, references, symbols, and file lookup without reading entire codebases.MIT
- FlicenseNot gradedqualityAmaintenanceEnables AI coding agents to retrieve real-time LSP diagnostics, symbol and type information, and code references, and to perform workspace-aware file operations such as symbol renaming. This avoids waiting for slow tsc/eslint checks while improving code navigation and editing accuracy.-