Skip to main content
Glama

Code AST MCP Server (code-ast-mcp)

Model Context Protocol Python 3.10+ Smithery Server License: MIT

code-ast-mcp is an architectural Model Context Protocol (MCP) server built with Python's native Abstract Syntax Tree (ast) parser. It allows AI models (in Claude Desktop, Cursor, Antigravity, or custom MCP clients) to analyze local Python codebase structures, search symbol definitions, build dependency graphs, audit docstring coverage, and refactor code without loading entire raw source files into LLM context windows.

๐Ÿ”— Live Repository: https://github.com/m-sameerkhan/code-ast-mcp
๐Ÿ”— Smithery Registry: https://smithery.ai/servers/sameerbalouch758/code-ast-mcp


โšก Features & Capabilities

๐Ÿ› ๏ธ Tools

  1. analyze_file_ast(file_path: str)

    • Parses a .py file into a clean AST outline.

    • Extracts module docstrings, line counts, imports, top-level functions, classes, methods, and variables.

  2. find_class_methods(file_path: str, class_name: str)

    • Locates a specific class and returns method signatures, type annotations, line ranges, and docstrings.

  3. find_symbol(target_dir: str, symbol_name: str)

    • Recursively searches a directory for classes, functions, methods, or variable assignments matching symbol_name.

  4. get_imports_graph(target_dir: str)

    • Scans Python files to build a dependency import map and outputs a Mermaid diagram string.

  5. find_missing_docstrings(target_dir: str, include_private: bool = False)

    • Audits codebase docstrings and calculates overall docstring coverage percentage.

๐Ÿ“ Prompts

  • refactor_code_summary(file_path: str)

    • Generates a structured prompt instructing the LLM to review the AST outline of a file and propose refactoring, design pattern improvements, and documentation fixes.

๐Ÿ“Š Resources

  • codeast://stats

    • Live JSON resource providing workspace statistics (total files scanned, docstring coverage %, missing item counts).


Related MCP server: codeweave-mcp

๐Ÿš€ Quickstart & Installation

Option 1: Install via Smithery CLI

smithery mcp add sameerbalouch758/code-ast-mcp

Option 2: Local Installation from Source

Clone the repository and install dependencies in editable mode:

git clone https://github.com/m-sameerkhan/code-ast-mcp.git
cd code-ast-mcp

# Create & activate virtual environment (or Conda)
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate

# Install project and dependencies
pip install -r requirements.txt
pip install -e .

Option 3: Package as an MCP Bundle (.mcpb)

For desktop clients that support MCP Bundles (like Claude Desktop):

# Install MCPB toolchain
npm install -g @anthropic-ai/mcpb

# Build bundle
mcpb pack . code-ast-mcp.mcpb

๐Ÿงช Testing Locally

Run Unit Tests

pytest

Test with MCP Inspector

Use the official MCP Inspector to interactively test tools and resources:

npx @modelcontextprotocol/inspector python -m code_ast_mcp.server

โš™๏ธ Client Configuration

Claude Desktop / Cursor / Antigravity Integration

Add code-ast-mcp to your client configuration file (claude_desktop_config.json or mcp_config.json):

{
  "mcpServers": {
    "code-ast-mcp": {
      "command": "python",
      "args": [
        "-m",
        "code_ast_mcp.server"
      ],
      "cwd": "/path/to/code-ast-mcp"
    }
  }
}

Note for Windows users: You can point "command" to your virtual environment or Conda Python path (e.g. C:/Users/<Username>/.conda/envs/code-ast-mcp/python.exe or D:/my_mcp/.venv/Scripts/python.exe).


๐Ÿ“ฆ Project Structure

code-ast-mcp/
โ”œโ”€โ”€ code_ast_mcp/          # Core package
โ”‚   โ”œโ”€โ”€ __init__.py        # Package exports
โ”‚   โ”œโ”€โ”€ analyzer.py        # Python AST parsing & static analysis engine
โ”‚   โ””โ”€โ”€ server.py          # FastMCP server definition & tool handlers
โ”œโ”€โ”€ tests/                 # Test suite
โ”‚   โ””โ”€โ”€ test_analyzer.py   # Unit tests with pytest
โ”œโ”€โ”€ manifest.json          # MCPB extension manifest
โ”œโ”€โ”€ smithery.yaml          # Smithery registry configuration
โ”œโ”€โ”€ Dockerfile             # Container image definition
โ”œโ”€โ”€ pyproject.toml         # Packaging & metadata
โ””โ”€โ”€ requirements.txt       # Dependencies

๐Ÿ“„ License

MIT License. Created by m-sameerkhan.

Install Server
A
license - permissive license
A
quality
C
maintenance

Maintenance

โ€“Maintainers
โ€“Response time
โ€“Release cycle
โ€“Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • -
    license
    -
    quality
    -
    maintenance
    An advanced MCP server that provides deep code understanding and analysis using GraphRAG, AST parsing, and semantic memory, enabling AI agents to query and interact with complex codebases.
  • A
    license
    -
    quality
    C
    maintenance
    Universal MCP server that analyzes any codebase and provides structured context to AI assistants. Dynamic, accurate, and token-efficient.
    19
    MIT

View all related MCP servers

Related MCP Connectors

  • An MCP server that gives your AI access to the source code and docs of all public github repos

  • A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yoโ€ฆ

  • Hosted MCP server for structured code review passes on human- and AI-written code. Free tier.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/m-sameerkhan/code-ast-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server