static_analysis -- Technical Specification
Version: v1.1.9 | Status: Active | Last Updated: March 2026
Overview
Static analysis utilities for auditing Python module exports and imports. Provides __all__ compliance checking, dead export detection, layer violation scanning, and unified audit reporting via 3 MCP tools.
Design Principles
- AST-based: All analysis uses Python's
astmodule for reliable parsing. - Non-destructive: All operations are read-only.
- Composable audits: Individual checks (
audit_exports,find_dead_exports) combine intofull_audit.
Architecture
static_analysis/
__init__.py -- Package root (5 exports)
exports.py -- audit_exports, find_dead_exports, full_audit, check_all_defined
imports.py -- scan_imports, check_layer_violations, extract_imports_ast
mcp_tools.py -- 3 MCP tool definitions
Functional Requirements
exports.py
audit_exports(src_dir: Path) -> list[dict]-- Find modules missing__all__definitions.find_dead_exports(src_dir: Path) -> list[dict]-- Find__all__entries never imported elsewhere.full_audit(src_dir: Path) -> dict-- Unified report combining all audit checks withsummarycounts.check_all_defined(src_dir: Path) -> bool-- Check whether__all__is properly defined.
imports.py
scan_imports(path: Path) -> list-- Scan a directory tree for all import statements.check_layer_violations(path: Path) -> list-- Detect imports that violate the project's layer hierarchy.extract_imports_ast(path: Path) -> list-- Extract imports from a single file using AST.
Interface Contracts
MCP tool return formats:
static_analysis_audit_exports:list[dict]withmodule,issue,detailkeysstatic_analysis_find_dead_exports:list[dict]withmodule,export_name,detailkeysstatic_analysis_full_audit:dictwithmissing_all,dead_exports,unused_functions,summary
Dependencies
- Internal:
model_context_protocol.decoratorsfor@mcp_tool - Standard library:
ast,pathlib(no external dependencies)
Constraints
- Relies on filesystem access to
src_dir. - Layer violation rules are defined within the codebase architecture (Foundation -> Core -> Service -> Application).
Navigation
Related Documents
- Agents: AGENTS.md