Skip to main content
Glama
ast-mcp
by sqzxwd

⚡ ast-mcp: Smart Context Compiler & MCP Server for AI Agents

Python MCP Tests Context Reduction

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.

Related MCP server: @penqwin/mcp

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+:

git clone https://github.com/your-username/ast-mcp.git
cd ast-mcp
uv pip install -e .

CLI Usage

# 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:

ast-mcp run

Add to your MCP Client Configuration (~/.gemini/config/mcp_config.json or Claude Desktop):

{
  "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.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides AI assistants with a structured, token-efficient map of a codebase's symbols, dependencies, and relationships via MCP tools like overview, query, and impact analysis.
      9
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      An AST-based MCP server that provides token-efficient codebase skeletons to LLM agents, reducing context token usage by 80-95% by exposing structural information instead of full source files.
      5
      13 npm
      3
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that folds function and class implementations into structural skeletons while preserving signatures, interfaces, and docstrings, reducing tokens by up to 90%+ for AI agents. Exposes tools to get repository skeletons, unfold specific symbols on demand, and retrieve exact token and prompt cost savings metrics.
      MIT