Skip to main content
Glama
README.md
# Code AST MCP Server (`code-ast-mcp`)

[![Model Context Protocol](https://img.shields.io/badge/MCP-Server-blue.svg)](https://modelcontextprotocol.io)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-brightgreen.svg)](https://python.org)
[![Glama MCP](https://img.shields.io/badge/Glama-MCP_Server-00d992.svg)](https://glama.ai/mcp/servers/m-sameerkhan/code-ast-mcp)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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 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](https://github.com/m-sameerkhan/code-ast-mcp)  
๐Ÿ”— **Glama Registry**: [https://glama.ai/mcp/servers/m-sameerkhan/code-ast-mcp](https://glama.ai/mcp/servers/m-sameerkhan/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).

---

## ๐Ÿš€ Deployment & Usage Modes

### Mode 1: Deploy via Glama MCP Registry

Deploy `code-ast-mcp` to the **[Glama MCP Registry](https://glama.ai/mcp/servers)** โ€” Glama automatically clones your GitHub repo, builds it using the included `Dockerfile`, and hosts it with built-in OAuth 2.1, monitoring, and access control.

#### Steps:
1. Go to [glama.ai/mcp/servers](https://glama.ai/mcp/servers).
2. Click **"Add Server"**.
3. Authenticate with **GitHub OAuth** (you must have write access to the repo).
4. Submit the repository URL:
   ```text
   https://github.com/m-sameerkhan/code-ast-mcp
   ```
5. Glama will **auto-build** using the `Dockerfile` and verify MCP compliance.
6. Once the build succeeds, your server will be live on the Glama registry.

#### Registry URL:
```text
https://glama.ai/mcp/servers/m-sameerkhan/code-ast-mcp
```

> **Note**: No manual hosting required โ€” Glama handles building, deployment, and verification automatically.

---

### Mode 2: Local Stdio MCP Server (Recommended for Local Codebases)

Best for inspecting local Python projects directly on your machine in Claude Desktop, Cursor, or Antigravity.

#### Installation:
```bash
git clone https://github.com/m-sameerkhan/code-ast-mcp.git
cd code-ast-mcp

# Virtual environment setup
python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate

pip install -r requirements.txt
pip install -e .
```

#### Client Configuration (`claude_desktop_config.json` / `mcp_config.json`):
```json
{
  "mcpServers": {
    "code-ast-mcp": {
      "command": "python",
      "args": [
        "-m",
        "code_ast_mcp.server"
      ],
      "cwd": "/path/to/code-ast-mcp"
    }
  }
}
```

---

## ๐Ÿงช Testing Locally

### Run Unit Tests
```bash
pytest
```

### Test with MCP Inspector
```bash
npx @modelcontextprotocol/inspector python -m code_ast_mcp.server
```

---

## ๐Ÿ“ฆ Project Structure

```text
code-ast-mcp/
โ”œโ”€โ”€ code_ast_mcp/          # Core MCP 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
โ”œโ”€โ”€ Dockerfile             # Container image definition (used by Glama)
โ”œโ”€โ”€ pyproject.toml         # Packaging & metadata
โ””โ”€โ”€ requirements.txt       # Dependencies
```

---

## ๐Ÿ“„ License
MIT License. Created by [m-sameerkhan](https://github.com/m-sameerkhan).

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation4/5

Each tool has a distinct role: file outline, class methods, symbol search, import graph, and docstring audit. There is minor overlap because analyze_file_ast, find_class_methods, and find_symbol all inspect Python definitions, but their scopes differ enough to guide selection.

Naming Consistency4/5

All tool names use snake_case and mostly follow a verb_target pattern. Three use find_, while analyze_file_ast and get_imports_graph deviate slightly, but the naming remains predictable and readable.

Tool Count5/5

Five tools is a well-scoped size for an AST inspection server. Each tool serves a distinct static analysis workflow without redundancy or bloat.

Completeness4/5

The set covers file outlines, class methods, symbol lookup, import graphs, and docstring coverage, which handles most Python code-inspection needs. Minor gaps exist, such as a dedicated detail view for standalone functions or arbitrary AST node inspection, but they are not critical.

Maintenance

ActivitySlowing
ResponsivenessNo issues