
ast-grep/ast-grep-mcp
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
ast-grepを用いた強力な構造コード検索機能を提供する実験的なモデルコンテキストプロトコル(MCP)サーバーです。
概要
ast-grepを用いた強力な構造コード検索機能を提供する実験的なモデルコンテキストプロトコル(MCP)サーバーです。 このMCPサーバーにより、CursorやClaude DesktopなどのAIアシスタントが、単純なテキストベース検索ではなく、抽象構文木(AST)パターンマッチングを用いてコードベースを検索・分析できます。ast-grepの構造検索機能を活用することで、AIは以下を実現できます: - 単なるテキストマッチングではなく構文構造に基づくコードパターンを見つける - 特定のプログラミング構造(関数、クラス、インポートなど)を検索 - YAML構成を使って複雑な検索ルールを作成・テスト - より良いパターン開発のためにAST構造をデバッグ・可視化する 3. : Cursor、Claude Desktop、その他のMCPクライアントなど GitHubからUVXを使って直接サーバーを稼働させることができます: これはリポジトリをクローンせずにサーバーを素早く試すのに役立ちます。 MCPの設定(通常は.cursor-mcp/settings.json)に追加してください: Claude Desktop MCPの設定に追加:
概要(AI 翻訳)
ast-grepを用いた強力な構造コード検索機能を提供する実験的なモデルコンテキストプロトコル(MCP)サーバーです。
概要
このMCPサーバーにより、CursorやClaude DesktopなどのAIアシスタントが、単純なテキストベース検索ではなく、抽象構文木(AST)パターンマッチングを用いてコードベースを検索・分析できます。ast-grepの構造検索機能を活用することで、AIは以下を実現できます:
- テキストマッチングだけでなく構文構造に基づくコードパターンを見つける
- 特定のプログラミング構造(関数、クラス、インポートなど)を検索する
- YAML構成を用いた複雑な検索ルールの作成とテスト
- より良いパターン開発のためのAST構造のデバッグと可視化
前提条件
-
ast-grepのインストール:ast-grepのインストールガイドに従う
-
Install uv: Python package manager
-
MCP互換クライアント:例えばCursor、Claude Desktop、その他のMCPクライアント
設置
-
このリポジトリのクローン:
-
依存関係のインストール:
-
ast-grepのインストール確認:
[[T0]と走る
GitHubからuvxを使ってサーバーを直接実行できます:
これはリポジトリをクローンせずにサーバーを素早く試すのに役立ちます。
このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。
README
以下は原文 README の抜粋です。原文を見る。
ast-grep MCP Server
An experimental Model Context Protocol (MCP) server that provides AI assistants with powerful structural code search capabilities using ast-grep.
Overview
This MCP server enables AI assistants (like Cursor, Claude Desktop, etc.) to search and analyze codebases using Abstract Syntax Tree (AST) pattern matching rather than simple text-based search. By leveraging ast-grep’s structural search capabilities, AI can:
- Find code patterns based on syntax structure, not just text matching
- Search for specific programming constructs (functions, classes, imports, etc.)
- Write and test complex search rules using YAML configuration
- Debug and visualize AST structures for better pattern development
Prerequisites
-
Install ast-grep: Follow ast-grep installation guide
# macOS brew install ast-grep nix-shell -p ast-grep cargo install ast-grep --locked -
Install uv: Python package manager
curl -LsSf https://astral.sh/uv/install.sh | sh -
MCP-compatible client: Such as Cursor, Claude Desktop, or other MCP clients
Installation
-
Clone this repository:
git clone https://github.com/ast-grep/ast-grep-mcp.git cd ast-grep-mcp -
Install dependencies:
uv sync -
Verify ast-grep installation:
ast-grep --version
Running with uvx
You can run the server directly from GitHub using uvx:
uvx --from git+https://github.com/ast-grep/ast-grep-mcp ast-grep-server
This is useful for quickly trying out the server without cloning the repository.
Configuration
For Cursor
Add to your MCP settings (usually in .cursor-mcp/settings.json):
{
"mcpServers": {
"ast-grep": {
"command": "uv",
"args": ["--directory", "/absolute/path/to/ast-grep-mcp", "run", "main.py"],
"env": {}
}
}
}
For Claude Desktop
Add to your Claude Desktop MCP configuration:
{
"mcpServers": {
"ast-grep": {
"command": "uv",
"args": ["--directory", "/absolute/path/to/ast-grep-mcp", "run", "main.py"],
"env": {}
}
}
}
Custom ast-grep Configuration
The MCP server supports using a custom sgconfig.yaml file to configure ast-grep behavior.
See the ast-grep configuration documentation for details on the config file format.
You can provide the config file in two ways (in order of precedence):
- Command-line argument:
--config /path/to/sgconfig.yaml - Environment variable:
AST_GREP_CONFIG=/path/to/sgconfig.yaml
Custom ast-grep Command
If ast-grep is not in PATH, or must be launched through another command, set
AST_GREP_PATH. The value can be an executable path or a command prefix:
{
インストール
uvx --from git+https://github.com/ast-grep/ast-grep-mcp ast-grep-server設定
{
"mcpServers": {
"ast-grep": {
"command": "uv",
"args": ["--directory", "/absolute/path/to/ast-grep-mcp", "run", "main.py"],
"env": {}
}
}
}