ast-grep-mcp
A modular MCP server providing structural code search, Schema.org tools, and code quality analysis through 47 tools organized across 9 feature categories.
Overview
ast-grep-mcp is a Model Context Protocol (MCP) server that leverages ast-grep for structural code search and provides comprehensive tools for:
- Code Search - AST-based pattern matching across 9 search tools
- Refactoring - Automated code rewrite and transformation
- Schema.org - Knowledge graph generation and validation
- Code Quality - Complexity analysis and quality metrics
- Documentation - Automatic doc generation from code
Installation
# Clone and install
cd ast-grep-mcp
uv sync
# Run tests
uv run pytest
# Start MCP server
uv run main.py
Tool Categories
| Category | Tools | Description |
|---|---|---|
| Search | 9 | Structural code search with AST patterns |
| Rewrite | 3 | Code transformation and refactoring |
| Refactoring | 2 | Automated refactoring operations |
| Deduplication | 4 | Code duplication detection |
| Schema.org | 9 | Knowledge graph and entity tools |
| Complexity | 3 | Cyclomatic and cognitive complexity |
| Quality | 7 | Code quality metrics and analysis |
| Documentation | 5 | Documentation generation |
| Cross-Language | 5 | Multi-language support tools |
Architecture
src/ast_grep_mcp/
├── core/ # Config, cache, executor, logging
├── models/ # Data models
├── utils/ # Templates, formatters, validation
├── features/ # Feature modules (search, rewrite, etc.)
└── server/ # MCP server registry