code-ast-mcp
This MCP server enables AI models to analyze local Python codebases using abstract syntax trees, providing tools for file structure analysis, symbol search, import graphing, docstring auditing, and refactoring prompts without loading entire source files into context.
README
Code AST MCP Server (code-ast-mcp)
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
๐ Glama Registry: https://glama.ai/mcp/servers/m-sameerkhan/code-ast-mcp
โก Features & Capabilities
๐ ๏ธ Tools
analyze_file_ast(file_path: str)- Parses a
.pyfile into a clean AST outline. - Extracts module docstrings, line counts, imports, top-level functions, classes, methods, and variables.
- Parses a
find_class_methods(file_path: str, class_name: str)- Locates a specific class and returns method signatures, type annotations, line ranges, and docstrings.
find_symbol(target_dir: str, symbol_name: str)- Recursively searches a directory for classes, functions, methods, or variable assignments matching
symbol_name.
- Recursively searches a directory for classes, functions, methods, or variable assignments matching
get_imports_graph(target_dir: str)- Scans Python files to build a dependency import map and outputs a Mermaid diagram string.
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 โ 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:
- Go to glama.ai/mcp/servers.
- Click "Add Server".
- Authenticate with GitHub OAuth (you must have write access to the repo).
- Submit the repository URL:
https://github.com/m-sameerkhan/code-ast-mcp - Glama will auto-build using the
Dockerfileand verify MCP compliance. - Once the build succeeds, your server will be live on the Glama registry.
Registry URL:
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:
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):
{
"mcpServers": {
"code-ast-mcp": {
"command": "python",
"args": [
"-m",
"code_ast_mcp.server"
],
"cwd": "/path/to/code-ast-mcp"
}
}
}
๐งช Testing Locally
Run Unit Tests
pytest
Test with MCP Inspector
npx @modelcontextprotocol/inspector python -m code_ast_mcp.server
๐ฆ Project Structure
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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.