codenav-mcp
An MCP server for type-resolved Python code navigation (and type-checked, previewable edits) powered by ty's language server.
Answer "what is this?" in one call —
symbol_inforeturns header, hover, definition and references grouped by file for a name (dottedClass.methodsupported,file_pathto disambiguate)Map a file —
outlinelists classes, methods and functions with line numbers, so you can navigate large files without reading themFind symbols by name —
search_symbolsearches the workspace (ranked, capped, production code before tests) with optionalkind/pathfilters andfuzzy=trueJump to definitions —
definitionresolves through ty's type inference, working even when the call site only has a typed parameter or attribute (imports, injected dependencies, dataclass fields)Find usages —
referenceslists every usage across the workspace, withinclude_declarationtoggleTrace calls —
callersshows actual call sites only, excluding imports and type-only usagesFind Protocol implementers —
implementationsfinds classes that structurally satisfy aProtocolport, verified by a real type-check probe (inherited members and fields count)Inspect types at a position —
hovergives type and docs forpath:line:col(1-indexed, UTF-16 column offsets)Type-check a file —
diagnosticsreturns ty's errors/warnings for one fileCheck where you are —
workspacereports which directory is being navigated and why (useful when results look like the wrong worktree)Documented but not in this schema: write tools —
edit,edit_symbol,rename_symbol,change_signature,move,quick_fix,verify_changes,apply_edit/undo_edit(type-checked, previewable, undoable, gated byCODENAV_MCP_READ_ONLY), plusbatchfor running up to 25 calls in one request.
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
An MCP server that gives AI agents type-resolved Python navigation, backed by ty's language server. Definitions, references and call sites go through real type inference (imports, dependency-injected parameters, dataclass fields), not text grep.
The same resolution powers its edits: rename a symbol, change a signature, or move a function or module, and every usage follows, including overriding methods and injected dependencies. Edits are type-checked and previewable before they are written, and can be undone.
Quick start
ty is installed with the package, so all you need is
uv (or pipx):
uvx codenav-mcpRegister it with your MCP host. For Claude Code, from the project root:
claude mcp add codenav -- uvx codenav-mcpOr add it to a project .mcp.json (Claude Code) or .cursor/mcp.json (Cursor):
{
"mcpServers": {
"codenav": {
"command": "uvx",
"args": ["codenav-mcp"],
"env": {
"CODENAV_MCP_SOURCE_ROOT": "src"
}
}
}
}In Cursor, also set "CODENAV_MCP_WORKSPACE": "${workspaceFolder}", because
Cursor may start MCP servers with your home directory as the working directory.
Related MCP server: LSP MCP
Tools
Start with the name-based tools:
Tool | Answers |
| What is this? Header, hover, definition and references in one call |
| What's in this file? (classes, methods, functions) |
| Who actually calls this function? (call hierarchy, not imports) |
| Which classes structurally implement this |
| Workspace symbol search by name (ranked, capped; optional |
| Which directory is being navigated, and why |
Then use the position tools once you have a path:line:col:
Tool | Answers |
| Type and docs at a position |
| Go to definition (resolves through injected parameters) |
| All usages across the workspace |
| ty type-check diagnostics for one file |
name and query are accepted as aliases on the name-based tools
(port_name / name / query on implementations). A missing or wrong
parameter gets a short hint back instead of a validation error. Dotted names
may nest (Outer.Inner.method). implementations also takes file_path to
pick one port when the name exists in several files, and counts inherited
members and dataclass/self.x fields toward a port's required names.
Write tools: change code with a type check before every write
The navigation tools above are read-only. These change code, and share one rule: the edit is applied to in-memory copies first, ty re-checks the edited files and the files importing them, and the response says which diagnostics the edit would add or fix. Nothing is written until that is on the table.
Tool | Does |
| Type-checked text edit of a Python file: |
|
|
| Rename across the workspace (imports, aliases, keyword arguments, |
| Add / remove / reorder parameters and rewrite every call site (found through ty's references, so injected dependencies and typed attributes work). Overrides follow. |
| With |
| Apply ty's own fixes (missing imports) with correct placement; ambiguous fixes are listed instead of guessed |
| After editing with any tool: which type errors the working tree gained or lost since a git revision (default |
| Write a previewed edit by id; revert an applied one |
One rule for every write tool: it writes when the edit adds no more than max_new_errors
(default 0) type errors in the edited files and their importers. Otherwise nothing is
written and you get the diagnostics plus an id for apply_edit. apply=false always
previews. Hint-level diagnostics (unused, deprecated) are not counted.
Safety rules, enforced in code:
Only
.py/.pyifiles inside the workspace are written; virtualenvs,site-packages, typeshed and symlinks that leave the workspace are refused.A preview remembers the exact bytes of every file;
apply_editrefuses if any file changed since. Files are replaced atomically, and a failure part-way restores the ones already written.Every applied edit is undoable (
undo_edit) unless the files were changed after it.Output is never written if it is not valid Python.
Edits touching more than 40 files need
allow_large=true.CODENAV_MCP_READ_ONLY=1turns every write into a refusal (previews still work).
New files an edit would create are written to disk for the few moments of the type check (ty finds modules through the file system) and removed again, even on errors.
Positions are 1-indexed. column is a UTF-16 character offset (a leading
tab counts as one character).
Python only (.py / .pyi).
Several calls in one request: batch
Reading three files or changing five symbols no longer costs one round-trip each.
batch takes a list of calls for any tool above (reads and writes mixed):
{"calls": [
{"tool": "outline", "args": {"file_path": "src/pkg/core.py"}},
{"tool": "symbol_info", "args": {"name": "Cart.total"}},
{"tool": "edit", "args": {"file_path": "src/pkg/core.py", "old_string": "x = 1", "new_string": "x = 2"}},
{"tool": "edit_symbol", "args": {"action": "delete", "name": "legacy_parse"}}
]}Calls run in order, each through the real tool, so every write is type-checked, previewed or applied, and undoable on its own (one edit id per write), and later calls see what earlier ones wrote.
One numbered section per call, then a summary line (
batch: 3/4 ok, 1 failed).A bad tool name or argument is reported in its own section with a hint; the rest still run.
stop_on_error(default: stop when the batch contains a write, continue when it only reads) skips the remaining calls after the first failure or write that was not applied.Not atomic: calls that ran stay applied. After an edit, prefer name-based calls over line/column positions computed earlier. Max 25 calls, no nesting, each result capped at 20,000 characters.
Which ty runs
The project's own
.venv/bin/ty(.venv\Scripts\ty.exeon Windows), so the ty version matches the project's pin and config.The
tyinstalled alongside codenav-mcp.tyonPATH.uvx ty serveras a last resort.
Environment
Variable | Default | Purpose |
| unset: follows the client's MCP roots when they name a worktree of the same git repository, else | Pins the project root (never overridden). See the |
| whole workspace | Directory scanned for |
| unset |
|
| none | Comma-separated directories (e.g. |
Requirements
Python ≥ 3.11
Installed automatically:
mcp,ty,ruff(sorts imports in files a move touched, only where they were already sorted),mcp-nav-shared
Related
webnav-mcp: the same kind of navigation for JS/TS/HTML/CSS.Design notes (Protocol conformance probe, positioning, output formats): docs/agent-tooling.md.
Development
Source: github.com/illescasDaniel/codenav-mcp. From a
checkout: uv sync --group dev, then uv run codenav-mcp.
License
MIT. See LICENSE.
Available Tools
10 toolscallersA
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.
Inputs: name, query, file_path. Returns: result
definitionA
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.
Inputs: line (required), column (required), file_path (required). Returns: result
diagnosticsB
Get ty's type-check diagnostics (errors/warnings) for a single file.
Inputs: file_path (required). Returns: result
hoverB
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.
Inputs: line (required), column (required), file_path (required). Returns: result
implementationsA
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. Returns: result
outlineA
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. Follow up with hover/definition/references at a listed line, or symbol_info by name.
Inputs: file_path (required). Returns: result
referencesB
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.
Inputs: line (required), column (required), file_path (required), include_declaration. Returns: result
search_symbolA
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.
name is accepted as an alias for query. Narrow broad queries with
kind (SymbolKind labels, comma-separated: class, function,method,
interface, ...) and path (workspace-relative prefix such as src/,
or a glob such as src/**/*.py). Production code ranks before tests.
Loose fuzzy hits whose names don't contain the query are summarised as a
count when real matches exist; pass fuzzy=true to list them too.
Inputs: kind, name, path, fuzzy, +1 more. Returns: result
symbol_infoA
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. 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.
query is accepted as an alias for name.
Inputs: name, query, file_path, include_references. Returns: result
workspaceA
Which directory is codenav navigating, and why? Use when results look like they come from the wrong checkout/worktree.
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
symbol_info explicitly overlaps with hover, definition, references, and search_symbol by providing a one-call summary, which could confuse an agent choosing between name-based and position-based lookups. However, the descriptions clearly delineate position-based precise navigation from name-based summary and distinguish callers from references. Overall mostly distinct with only minor intentional layering.
Most tools are lowercase snake_case nouns describing the returned information (workspace, diagnostics, hover, definition, references, outline, callers, implementations). search_symbol and symbol_info deviate slightly with verb_noun or noun_noun phrasing, but the set remains predictable and readable. Minor inconsistency, not chaotic.
Ten tools is well-scoped for a code navigation server, and each tool earns its place by covering a distinct navigation need. No tool appears redundant or extraneous at the count level.
The surface covers core navigation operations: symbol lookup, definition, references, hover, outline, callers, implementations, and file diagnostics. Minor gaps exist, such as no workspace-wide diagnostics, no callees (outgoing call hierarchy), or rename, but these are workaroundable and not central to navigation.
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.
Write, type-check and run AILANG in a sandbox, with Z3-proved contracts and docs search.
Search @imqueue docs and scaffold typed services & clients from your AI coding agent.
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 gradedqualityDmaintenanceExposes 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.-