Skip to main content
Glama

codenav-mcp

version PyPI

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-mcp

Register it with your MCP host. For Claude Code, from the project root:

claude mcp add codenav -- uvx codenav-mcp

Or 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

symbol_info

What is this? Header, hover, definition and references in one call

outline

What's in this file? (classes, methods, functions)

callers

Who actually calls this function? (call hierarchy, not imports)

implementations

Which classes structurally implement this Protocol? (type-checked)

search_symbol

Workspace symbol search by name (ranked, capped; optional kind= / path= filters; production code before tests; fuzzy-only hits summarised unless fuzzy=true)

workspace

Which directory is being navigated, and why

Then use the position tools once you have a path:line:col:

Tool

Answers

hover

Type and docs at a position

definition

Go to definition (resolves through injected parameters)

references

All usages across the workspace

diagnostics

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

edit

Type-checked text edit of a Python file: old_string/new_string or a whole new_text. For anything that is not a whole definition

edit_symbol

action="replace" / "insert" / "delete" a function, method or class by name: re-indented to the file's style, PEP 8 spacing, imports=[...] added, syntax-checked. Delete refuses while anything uses the symbol and prunes now-dead imports

rename_symbol

Rename across the workspace (imports, aliases, keyword arguments, parameter= for a function's parameter). Also renames what ty's rename misses: overriding methods, super().name() calls, and Protocol members together with the classes that satisfy them (linked=false to opt out). Lists remaining mentions of the old name (untyped accesses, strings, comments, docs; other worktrees are skipped)

change_signature

Add / remove / reorder parameters and rewrite every call site (found through ty's references, so injected dependencies and typed attributes work). Overrides follow. *args calls and uses as a value are listed as manual work

move

With name: move a module-level function or class to another file with the imports it needs; without it, move or rename the module file_path. Rewrites imports everywhere, drops imports only the moved code used, warns about import cycles

quick_fix

Apply ty's own fixes (missing imports) with correct placement; ambiguous fixes are listed instead of guessed

verify_changes

After editing with any tool: which type errors the working tree gained or lost since a git revision (default HEAD)

apply_edit / undo_edit

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/.pyi files 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_edit refuses 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=1 turns 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

  1. The project's own .venv/bin/ty (.venv\Scripts\ty.exe on Windows), so the ty version matches the project's pin and config.

  2. The ty installed alongside codenav-mcp.

  3. ty on PATH.

  4. uvx ty server as a last resort.

Environment

Variable

Default

Purpose

CODENAV_MCP_WORKSPACE

unset: follows the client's MCP roots when they name a worktree of the same git repository, else CLAUDE_PROJECT_DIR, else the working directory

Pins the project root (never overridden). See the workspace tool

CODENAV_MCP_SOURCE_ROOT

whole workspace

Directory scanned for implementations candidates and used to derive dotted import paths (e.g. src)

CODENAV_MCP_READ_ONLY

unset

1/true: write tools refuse to write (previews and checks still work)

CODENAV_MCP_EXTRA_SOURCE_ROOTS

none

Comma-separated directories (e.g. tests) that implementations also scans; matches (test doubles) are listed under a separate heading

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

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 tools
callersA

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

    A3.9/5.0

    Scored across 10 tools

    Disambiguation4/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Exposes 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.
      9
      540 npm
      3
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides AI agents with language-aware code analysis through the Language Server Protocol, enabling tasks like getting code insights and diagnostics.
      194
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Exposes 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
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables 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.
      -