py-ast-mcp
v0.2.1MCP server for deep structural analysis of Python source via the stdlib ast module
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
analyze_file
High-level summary of every symbol in a Python file. Lists classes (with dataclass/enum/Protocol/TypedDict classification), functions, async functions, methods and module-level assignments with line numbers. Start here when exploring an unfamiliar module. Args: path: Path to a .py file.
| Parameter | Type | Description |
|---|---|---|
path * | string |
list_functions
List all functions and methods with full signatures and line ranges. Includes parameter annotations and defaults, return annotation, decorators, async flag, and nested function relationships. Args: path: Path to a .py file.
| Parameter | Type | Description |
|---|---|---|
path * | string |
get_function_body
Extract the full source of a function or method, with line numbers. Args: path: Path to a .py file. name: Function name, `Class.method`, or a dotted nested path.
| Parameter | Type | Description |
|---|---|---|
name * | string | |
path * | string |
list_methods
List every method of a class: declared, inherited, properties, class and static methods, plus class-level attributes. Inherited members are only resolved for base classes defined in the same file; bases from other modules are reported as unresolved. Args: path: Path to a .py file. type: Class name.
| Parameter | Type | Description |
|---|---|---|
path * | string | |
type * | string |
get_type_definition
Extract a class, TypeAlias, Enum, Protocol, TypedDict or NamedTuple definition with its members and source. Args: path: Path to a .py file. name: Type name.
| Parameter | Type | Description |
|---|---|---|
name * | string | |
path * | string |
list_declarations
List module-level assignments with annotated or inferred types. Args: path: Path to a .py file.
| Parameter | Type | Description |
|---|---|---|
path * | string |
list_exports
List the public symbols of a module. Respects `__all__` when present, otherwise reports non-underscore module-level names, and flags re-exported imports. Args: path: Path to a .py file.
| Parameter | Type | Description |
|---|---|---|
path * | string |
list_imports
List all imports: bound name, module path, relative level and aliases, grouped into stdlib / third-party / relative. Args: path: Path to a .py file.
| Parameter | Type | Description |
|---|---|---|
path * | string |
find_usages
Find every occurrence of an identifier with surrounding source lines. Covers reads, assignments, parameters, attribute access, imports and global/nonlocal declarations. Always reports a project-wide references section: either the cross-file hits, or that there are none, or that `jedi` is not installed and cross-file references were therefore not checked. An empty result and an unchecked one are not the same answer. Args: path: Path to a .py file. identifier: Name to search for. context: Lines of context to show around each hit (default 1).
| Parameter | Type | Description |
|---|---|---|
identifier * | string | |
path * | string | |
context | integer |
call_graph
Emit a Mermaid flowchart of the call relationships in a file or package. Args: path: Path to a .py file. function: Optional root; only calls reachable from it are drawn. direction: Mermaid layout direction: TD, TB, LR, RL or BT. include_external: Include calls to names not defined in scope. scope: "file" (default) or "package" to walk every .py file in the containing directory.
| Parameter | Type | Description |
|---|---|---|
path * | string | |
direction | string | |
function | ||
include_external | boolean | |
scope | string |
get_callers
Reverse call graph: who calls this function, directly and transitively. Args: path: Path to a .py file. function: Function name or `Class.method`. scope: "file" (default) or "package".
| Parameter | Type | Description |
|---|---|---|
function * | string | |
path * | string | |
scope | string |
code_complexity
Cyclomatic complexity per function, with rank and decision-point breakdown. Counts if/elif, for, while, except, comprehension fors and ifs, boolean operators, ternaries, and match cases other than the irrefutable one. Scores match `radon cc --no-assert`. `with` and `assert` are deliberately not counted: neither branches. `with` still adds nesting depth. Args: path: Path to a .py file. function: Optional single function to analyse in detail.
| Parameter | Type | Description |
|---|---|---|
path * | string | |
function |
code_smells
Detect long functions, deep nesting, god classes, too many parameters, mutable default arguments, mutable `@dataclass` field defaults, high complexity, bare excepts and shadowed builtins. Args: path: Path to a .py file. function: Optional single function to analyse.
| Parameter | Type | Description |
|---|---|---|
path * | string | |
function |
find_errors
Find Python-specific hazards: bare/broad except, `except: pass`, handlers made unreachable by an earlier one, mutable default args, mutable `@dataclass` field defaults (an import-time ValueError), unawaited coroutines (best effort), `assert` used for runtime validation, late-binding closures over a loop or comprehension variable, `==` against None/True/False, `is` against a literal, and methods that never use `self`. Args: path: Path to a .py file. function: Optional single function to analyse.
| Parameter | Type | Description |
|---|---|---|
path * | string | |
function |
dead_code
Find unreferenced private and module-level symbols across a directory. If `path` is a file, its containing directory is scanned so that cross-file references are seen. Args: path: A .py file or a directory. include_tests: Also scan test files (default False).
| Parameter | Type | Description |
|---|---|---|
path * | string | |
include_tests | boolean |
find_implementations
Find classes implementing a Protocol or ABC, both explicitly (as a base class, including indirect subclasses) and structurally (method-set match). Args: path: A .py file or directory; the containing directory is scanned. interface: Name of the Protocol/ABC/base class. Named `interface` rather than `protocol` to match the identical tool in the TypeScript server, so one vocabulary works across both.
| Parameter | Type | Description |
|---|---|---|
interface * | string | |
path * | string |
get_doc
Extract a docstring and parse it into summary/params/returns/raises when it follows Google or NumPy style. Args: path: Path to a .py file. name: Symbol name, `Class.method`, or "module" for the module docstring.
| Parameter | Type | Description |
|---|---|---|
name * | string | |
path * | string |
analyze_package
Directory-level summary of every .py file: sizes, class/function counts, docstrings and per-file symbol lists. Args: path: Directory to analyse. include_tests: Include test files (default False).
| Parameter | Type | Description |
|---|---|---|
path * | string | |
include_tests | boolean |
diff_ast
Structural diff between two Python files: added, removed and modified functions, classes, methods, module variables, imports and `__all__`. Signature-level, not text-level. Args: old_path: Path to the original file. new_path: Path to the updated file.
| Parameter | Type | Description |
|---|---|---|
new_path * | string | |
old_path * | string |
find_node_at_position
Identify the AST node at a cursor position with its enclosing scope chain. Args: path: Path to a .py file. line: 1-based line number. column: 0-based column offset.
| Parameter | Type | Description |
|---|---|---|
column * | integer | |
line * | integer | |
path * | string |