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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。