使用
Linux x86_64
需要先準備
- 執行環境:
uv - 系統套件:
ast-grep
用 uv tool install 從 git 安裝 MCP 伺服器,並安裝 ast-grep-cli 取得 ast-grep 執行檔
uv tool install git+https://github.com/ast-grep/ast-grep-mcp && uv tool install ast-grep-cli
確認能用
ast-grep --version輸出應包含「ast-grep 0.51.2」。
加進你的 agent
claude mcp add ast-grep-mcp -- ast-grep-serverClaude Desktop、Cursor 等用戶端用的 JSON
{
"mcpServers": {
"ast-grep-mcp": {
"command": "ast-grep-server",
"args": []
}
}
}在 MCP 用戶端中將 ast-grep-server 加為伺服器指令,再請助理使用 find_code 等工具。
它能做什麼
- 依語法結構搜尋程式碼已測試
怎麼使用
- 請助理以專案資料夾、
console.log($$$)這類模式和語言呼叫find_code工具。 - 查看回傳的符合程式碼位置清單。
- 請助理以專案資料夾、
- 撰寫並測試 YAML 搜尋規則已測試
怎麼使用
- 撰寫含
id、language和rule: pattern: <your pattern>的 YAML 規則。 - 請助理以該規則和 <your code> 範例呼叫
test_match_code_rule工具。 - 檢查回傳的符合結果,確認規則有效。
- 撰寫含
- 檢視程式碼片段的語法樹已測試
怎麼使用
- 請助理以 <your code> 及其語言呼叫
dump_syntax_tree工具。 - 閱讀印出的語法樹了解程式碼結構,例如修正比對不到的模式。
- 請助理以 <your code> 及其語言呼叫
pickfit 測到哪一步
Linux x86_64
- 可以安裝
- 可以連線
- 3 項功能中 3 項可用
- 可離線使用
適合用來
- 找出 JavaScript 程式碼庫中所有 console.log 陳述式
- 找出使用 await 的 async 函式
- 除錯 ast-grep 模式比對不到的原因
pickfit 怎麼測的
每次測試都從乾淨的機器開始,照上面的步驟執行。 pickfit 怎麼驗證
Linux x86_64
MCP 用戶端成功呼叫工具
- 從頭重跑
- 可離線使用
- 檢查於 2026年11月15日
MCP 用戶端透過 stdio 連線,列出 4 個工具,呼叫 find_code 也回傳了結果。
測試機器遇到的差異
- README: Install ast-grep via brew, nix-shell or cargo
測試中: `uv tool install ast-grep-cli`(已發布的 PyPI 套件)不需 root 或 Rust 工具鏈即可將 ast-grep 放上 PATH - README: uv sync in a clone / uvx --from git+... ast-grep-server
測試中: `uv tool install git+https://github.com/ast-grep/ast-grep-mcp` 會把 ast-grep-server 指令裝到 PATH,斷網時也能啟動伺服器 - README: Complex rule example (async-with-await) for test_match_code_rule
測試中: 對 `async function load() { const x = await fetch(1); }` 執行時,README 的 async-with-await 規則讓 test_match_code_rule 回傳錯誤(探測未顯示訊息),可能是規則沒有比對到任何內容。README 較簡單的 console.log 規則可正常運作。