tree ast grep MCP服务器
MCP服务器,用于使用astgrep进行结构代码搜索和转换。无抽象的直接CLI包装器。
ast grep官方文档:https://github.com/ast-grep/ast-grep, https://ast-grep.github.io/
注: 该项目尚处于早期开发阶段。请在以下网址报告问题 .
安装
1.安装ast-grep:
npm install -g @ast-grep/cli # or: brew install ast-grep2.添加到MCP配置:
{
"mcpServers": {
"tree-ast-grep": {
"command": "npx",
"args": ["-y", "@cabbages/tree-grep"]
}
}
}工具
此服务器为LLM代理提供了四种工具:
- ast_search -使用AST模式匹配搜索代码
- ast_replace -使用AST模式替换代码(支持干运行模式)
- ast_run_rule -执行带有约束和修复的YAML规则
- ast_解释_模式 -调试模式并查看元变量捕获
*工具模式和参数通过MCP协议提供。*
故障排除
未找到二进制文件:
npm install -g @ast-grep/cli
ast-grep --version需求
- Node.js>=18.0.0或Bun>=1.0.0
- 系统上安装了ast grep
令牌使用
MCP服务器公开了4个工具,总上下文成本为 约10898个代币 (近似法,±20%方差)。
上下文窗口影响
╔══════════════════════════════════════════════════════════════════════════════╗
║ 🚀 Context Window Impact - Latest 2025 Models ║
╠══════════════════════════════════════════════════════════════════════════════╣
║ 🤖 GPT-5 400K │ 2.72% ██████░░░░░░░░░░░░░░░░░░░░░░░░ ║
║ 🧠 Claude Sonnet 4.5 200K │ 5.45% ███████████░░░░░░░░░░░░░░░░░░░ ║
║ ⚡ Grok 4 2,000K │ 0.54% ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ║
║ 💎 Gemini 2.5 Pro 1,000K │ 1.09% ███░░░░░░░░░░░░░░░░░░░░░░░░░░░ ║
╚══════════════════════════════════════════════════════════════════════════════╝运行令牌分析:
node scripts/count-tool-tokens.js链接
- github:https://github.com/justar96/tree-grep-mcp
- npm:https://www.npmjs.com/package/@卷心菜/树莓
- ast grep:https://ast-grep.github.io
许可证
麻省理工学院
