Token导航 LogoToken导航TokenDH.com
Ast Grep MCP Rs logo
开发工具未说明官方级别未说明来源级核验

Ast Grep MCP Rs

MCP Server

基于Rust实现的MCP服务器,通过ast-grep提供结构化代码搜索功能,适用于AI助手和开发工具集成。

工具数

4

提示词数

0

GitHub Stars

1

资源数

0
代码搜索开发工具RustClaudeClaude DesktopClaudeCursorVS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

GodSpeedAI

提供方

GodSpeedAI

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

ast grep MCP服务器(Rust)

上游归因

此存储库是Rust移植的 ast-grep/ast-grep-mcp. 原始归属和MIT许可证通知保存在 许可证.

此服务器提供什么

服务器公开了四个MCP工具:

  • dump_syntax_tree:检查语法树或模式结构以了解调试规则。
  • test_match_code_rule:针对stdin中的代码测试YAML ast grep规则。
  • find_code:使用ast-grep模式搜索项目。
  • find_code_by_rule:使用完整的YAML ast grep规则搜索项目。

find_codefind_code_by_rule 支持:

  • output_format: text (默认)或 json
  • max_results:返回匹配项的可选正限制

需求

  1. 安装ast grep CLI(必须在您的 PATH)
# Choose one installation method from ast-grep docs
brew install ast-grep
cargo install ast-grep --locked
  1. 安装Rust工具链
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. 使用MCP兼容客户端(Cursor、Claude Desktop等)

安装

选项1:从crates.io安装(推荐)

cargo install ast-grep-mcp

这会将可执行文件安装为:

ast-grep-mcp-server

在Linux/macOS上,Cargo将二进制文件安装到 ~/.cargo/bin 默认情况下。 确保该目录位于您的 PATH.

选项2:从GitHub发布版下载预构建的二进制文件

  1. 打开“发布”页面:
  2. 下载适用于您平台的存档。
  3. 取出并放置 ast-grep-mcp-server (或 ast-grep-mcp-server.exe 在Windows上)的某个位置 PATH.
  4. 使用验证校验和 SHA256SUMS.txt 从同一个释放。

发布资产的名称如下:

  • ast-grep-mcp-server-vX.Y.Z-x86_64-unknown-linux-gnu.tar.gz
  • ast-grep-mcp-server-vX.Y.Z-x86_64-apple-darwin.tar.gz
  • ast-grep-mcp-server-vX.Y.Z-aarch64-apple-darwin.tar.gz
  • ast-grep-mcp-server-vX.Y.Z-x86_64-pc-windows-msvc.zip
  • SHA256SUMS.txt

校验和验证示例:

sha256sum -c SHA256SUMS.txt

快速入门(已安装二进制文件)

  1. 安装ast grep CLI和此服务器。
  2. 验证 ast-grep-mcp-server 从你的壳里跑出来。
  3. 配置您的MCP客户端以启动 ast-grep-mcp-server.

快速验证命令:

ast-grep-mcp-server --help

默认传输为stdio:

ast-grep-mcp-server

使用自定义ast-grep配置:

ast-grep-mcp-server --config /absolute/path/to/sgconfig.yaml

您还可以设置:

export AST_GREP_CONFIG=/absolute/path/to/sgconfig.yaml

运输支持

  • stdio:支持和推荐
  • sse:当前未在此Rust端口中实现

如果你与 --transport sse,服务器退出时出错,提示您使用stdio。

客户端配置

如果您是通过安装的 cargo install ast-grep-mcp 或从GitHub发布中,使用命令名 ast-grep-mcp-server 直接。

光标

添加到MCP设置中:

{
  "mcpServers": {
    "ast-grep": {
      "command": "ast-grep-mcp-server",
      "args": [],
      "env": {}
    }
  }
}

克劳德桌面版

添加到您的Claude Desktop MCP配置中:

{
  "mcpServers": {
    "ast-grep": {
      "command": "ast-grep-mcp-server",
      "args": [],
      "env": {}
    }
  }
}

VS Code

添加到您的VS代码MCP配置中:

{
  "mcpServers": {
    "ast-grep": {
      "command": "ast-grep-mcp-server",
      "args": [],
      "env": {}
    }
  }
}

常用VS Code用户设置位置:

  • Linux: ~/.config/Code/User/settings.json
  • macOS: ~/Library/Application Support/Code/User/settings.json
  • 窗户: %APPDATA%\\Code\\User\\settings.json

CLI选项

  • --config PATH:路径 sgconfig.yaml
  • --transport {stdio|sse}:默认值为 stdio (sse未实施)
  • --port PORT:已解析,但目前仅与未来的SSE支持相关

工具行为注释

  • project_folder 参数必须是绝对路径。
  • test_match_code_rule 未找到匹配项时返回错误。
  • 对于关系规则(inside, has),添加 stopBy: end 以避免不完整的遍历。
  • 文本输出紧凑(file:start-end +匹配的片段)以减少令牌使用。

MCP客户端的示例查询

  • 在此仓库中查找所有Python函数定义。
  • 查找锈迹 impl 具有模式匹配的块。
  • 用代码片段测试这个ast grep YAML规则。
  • 转储此TypeScript代码段的CST。

贡献

贡献者和发布维护者说明见 贡献.md.

支持的语言

内置语言集包括:

  • bash、c、cpp、csharp、css、elixir、go、haskell、html、java
  • javascript、json、jsx、kotlin、lua、nix、php、python、ruby、rust
  • scala、solidity、swift、tsx、typescript、yaml

您可以在中使用自定义语言扩展语言支持 sgconfig.yaml.

故障排除

  1. ast-grep 找不到命令:安装astgrep并验证它是否在 PATH.
  2. 没有符合复杂关系规则的匹配项:添加 stopBy: end.
  3. 意外的解析/匹配行为:使用 dump_syntax_tree 检查CST/模式表示。
  4. 配置路径错误:确保 --configAST_GREP_CONFIG 指向现有文件。

许可证

MIT。看 许可证.

目录标签

目录标签

代码搜索开发工具RustClaude本地部署语法树分析Rust实现AI集成

支持客户端

Claude DesktopClaudeCursorVS Code

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

4

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP