ast-mcp
by sqzxwd
README.md
# ⚡ ast-mcp: Smart Context Compiler & MCP Server for AI Agents
[](https://www.python.org/)
[](https://modelcontextprotocol.io/)
[]()
[]()
> A lightweight, zero-C-extension context compiler and Model Context Protocol (MCP) server that compresses Python codebases into high-signal AST interface skeletons, cutting prompt window consumption by **60% to 80%**.
---
## The Problem: "Fat Context" Exhaustion
LLM-driven coding agents (Antigravity, Claude, Cursor) are often fed hundreds or thousands of lines of code when analyzing a task. In real-world repositories:
- Up to **85%** of source lines consist of internal function algorithms, repetitive loops, and intermediate calculations.
- Feeding raw implementations for every dependency wastes token budgets, slows inference, and dilutes the model's attention over long horizons.
## The Solution: Selective AST Interface Skeletons
`ast-mcp` utilizes Python's built-in `ast` parser to strip out function and method bodies into `...` (Ellipsis), preserving:
- Class declarations, inheritances, and metaclasses
- Method and function signatures with type annotations
- Parameter default values, `*args`, and `**kwargs`
- Module, class, and method docstrings
- Global constants and type aliases
When targeting a specific focus symbol (e.g., `--symbol CoreEngine`), `ast-mcp` preserves the **full implementation** of the target file while delivering all auxiliary project files as ultra-compact AST skeletons.
---
## Compression Benchmark (Tested on `ast-mcp/src`)
| Compression Mode | Files Processed | Original Tokens | Compressed Tokens | Tokens Saved | Reduction (%) | Compression Ratio |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: |
| **All Files (Interface Skeleton)** | 7 | ~5,847 | ~2,230 | **~3,617** | **61.88%** | **2.62x** |
| **Focused (`--symbol CodeSkeletonizer`)** | 7 (1 full, 6 skel) | ~5,847 | ~2,530 | **~3,317** | **56.76%** | **2.31x** |
---
## Quickstart
### Installation
Requires Python 3.14+:
```bash
git clone https://github.com/your-username/ast-mcp.git
cd ast-mcp
uv pip install -e .
```
### CLI Usage
```bash
# Compile entire directory into terminal output
ast-mcp pack src
# Focus on a specific symbol (keeps full code for target, skeletonizes rest)
ast-mcp pack src --symbol CodeSkeletonizer
# Copy compressed markdown context directly to system clipboard
ast-mcp pack src --symbol ContextPacker --copy
# Save compressed context to file
ast-mcp pack src -o context.md
```
### MCP Server Integration
Run standalone over stdio:
```bash
ast-mcp run
```
Add to your MCP Client Configuration (`~/.gemini/config/mcp_config.json` or Claude Desktop):
```json
{
"mcpServers": {
"ast-mcp": {
"command": "/Users/iliaprosvirnikov/Downloads/ast-mcp/.venv/bin/python3",
"args": ["-m", "src.cli", "run"]
}
}
}
```
### Available MCP Tools
- `get_smart_context(repo_path: str, focus_symbol: str = "") -> str`:
Builds a structured markdown slice of the target repository with token reduction metrics.
- `get_file_skeleton(file_path: str) -> str`:
Generates an instant AST skeleton for an individual Python file.
---
## License
MIT © 2026 ast-mcp contributors.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues