code-ast-mcp
This server lets you analyze and refactor Python codebases structurally using AST, without loading raw files into an LLM context.
Parse a Python file into an AST outline: docstrings, imports, classes, functions, variables, and line counts.
Retrieve all methods of a specific class with signatures, type annotations, line ranges, and docstrings.
Recursively search directories or files for classes, functions, methods, or variables by name.
Build an import dependency graph and output it as a Mermaid diagram string.
Audit docstring coverage across a codebase, including optional private items, and get missing docstring details.
Generate a structured refactoring prompt for a file via the
refactor_code_summaryprompt.Access workspace statistics (files scanned, docstring coverage, missing counts) via the
codeast://statsresource.
Analyzes Python codebases by extracting AST outlines, symbols, classes, methods, import dependency graphs, and docstring coverage.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@code-ast-mcpanalyze the AST of src/utils.py"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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.
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.
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://statsLive JSON resource providing workspace statistics (total files scanned, docstring coverage %, missing item counts).
Related MCP server: codeweave-mcp
๐ 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-mcpGlama 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-mcpNote: 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
pytestTest 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.
Maintenance
Related MCP Servers
- FlicenseBqualityDmaintenanceAn MCP server that enables LLMs to understand and analyze code structure through function call graphs, allowing AI assistants to explore relationships between functions and analyze dependencies in Python repositories.618
- AlicenseNot gradedqualityCmaintenanceAn MCP server that gives AI agents structured code understanding and precise code intelligence via local indexing of AST, call graphs, and semantic search.1084Apache 2.0
- -licenseNot gradedqualityNot gradedmaintenanceAn 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.
- AlicenseNot gradedqualityCmaintenanceUniversal MCP server that analyzes any codebase and provides structured context to AI assistants. Dynamic, accurate, and token-efficient.19MIT
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โฆ
Driflyte MCP server which lets AI assistants query topic-specific knowledge from web and GitHub.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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