Ahma MCP 能让你仅用一个 JSON 文件,就能将命令行工具转化为智能代理。借助真正的多线程工具使用代理式 AI 工作流,它能让你的工作完成得更高效。
ahma_mcp
能快速适配命令行工具,供 AI 调用。AI 调用工具后,能迅速确认后台进程已启动,从而继续进行规划和分析,并在每个操作完成时自动接收工具执行结果。多个并发的工具调用可并行执行。若有需要,个别工具和子命令可标记为 synchronous: true
,以实现传统的阻塞式 MCP 工具调用。通常情况下,AI 无需 await
异步工具完成,因为工具完成时它会自动获取结果,但在必要时也可以这么做。
Ahma(芬兰语中意为狼獾)是一款坚韧且敏捷的工具,与常见的同步工具相比,它能加速你的工作流,让你更快地完成复杂任务。
使用支持 MCP 的 VS Code 是体验 ahma_mcp 的最快方式。
# 1) 克隆仓库并构建发布版本的二进制文件
git clone https://github.com/paulirotta/ahma_mcp.git
cd ahma_mcp
cargo build --release
# 2) 将 `tools/`、`.vscode/` 和 `.gihub/chatmodes/` 复制到你的 VS Code 项目中,并根据需要编辑路径、工具和 AI 工具使用指南。
然后将内容复制到你的 VS Code MCP 配置文件中(各操作系统的文件位置如下),重启 VS Code,即可开始使用。
cargo nextest
进行全面测试,超过 70 个测试用例确保可靠性。cargo llvm-cov
支持,用于详细的测试覆盖率分析和报告(同步操作)。tool_guidance.json
中的可重用指导块通过 guidance_key
引用,确保跨工具的 AI 指令一致。"synchronous": true
,以立即获取结果,无需通知。status
工具跟踪所有运行操作的状态。await
工具监控操作,可配置超时时间(1 - 1800 秒,默认 240 秒)。cargo watch
重启期间优雅处理 SIGTERM/SIGINT 信号。git clone https://github.com/paulirotta/ahma_mcp.git
cd ahma_mcp
cargo build --release
./target/release/ahma_mcp --help
Ahma MCP 使用 tools/
目录中的 MTDF(MCP 工具定义格式)JSON 文件来定义 CLI 工具集成:
内部工具(在 ahma_mcp 中实现):
await.json
- 操作协调,等待一个或多个工具完成。status.json
- 正在进行和最近完成的操作信息。外部工具定义 用于命令行工具,存于 .ahma/tools/
中。复制并编辑你需要的工具,或添加自己的工具:
Rust 生态系统:
cargo.json
- Rust 包管理器,支持递归子命令(13 个子命令)。cargo_audit.json
- 审计 Cargo.lock 的安全漏洞(2 个子命令)。cargo_bench.json
- 为 Rust 项目运行基准测试(1 个子命令)。cargo_clippy.json
- 增强的 Rust 代码 linting 和质量检查(1 个子命令)。cargo_edit.json
- 编辑 Cargo.toml 文件的工具(4 个子命令)。cargo_fmt.json
- 根据风格指南格式化 Rust 代码(1 个子命令)。cargo_llvm_cov.json
- Rust 项目的 LLVM 源代码覆盖率(8 个子命令,同步)。cargo_nextest.json
- Rust 的下一代测试运行器(1 个子命令)。版本控制与 CI/CD:
git.json
- Git 版本控制系统(10 个子命令)。gh.json
- GitHub CLI,支持嵌套操作,如 cache delete
和 run cancel
(10 个子命令)。通用开发:
python3.json
- Python 解释器和模块执行(7 个子命令)。gradlew.json
- Android/Java 项目的 Gradle 包装器(47 个子命令)。shell_async.json
- 异步执行 shell 命令(1 个子命令)。long_running_async.json
- 用于测试异步行为的睡眠实用工具(1 个子命令)。文件操作:
cat.json
- 查看文件内容(单个命令)。每个 MTDF 文件可使用 guidance_key
字段引用 .ahma/tool_guidance.json
中的指导块,避免指导重复,确保一致性。有关详细的模式信息和验证,请参阅 。
运行全面的测试套件以验证一切正常:
# 使用 nextest 运行所有测试(更快的测试运行器)
cargo nextest run
# 运行带覆盖率分析的测试
cargo llvm-cov nextest --html --open
# 替代方案:标准 cargo 测试
cargo test
你应该会看到类似以下的输出:
✓ Finished running 76 tests across 45 binaries (2.34s)
以下是使用 Ahma MCP 与 VS Code 集成的基本步骤:
# 克隆并构建仓库
git clone https://github.com/paulirotta/ahma_mcp.git
cd ahma_mcp
cargo build --release
# 复制配置文件到 VS Code 项目
# 编辑配置文件中的路径、工具和 AI 工具使用指南
# 复制内容到 VS Code MCP 配置文件
# 不同操作系统的配置文件位置不同
# 重启 VS Code
在你的 VS Code 设置中(Ctrl/Cmd+,
→ 搜索 "settings.json")添加以下内容:
{
"chat.mcp.enabled": true
}
创建或编辑你的全局 MCP 配置文件:
位置:
~/Library/Application Support/Code/User/mcp.json
~/.config/Code/User/mcp.json
%APPDATA%\Code\User\mcp.json
{
"servers": {
"ahma_mcp": {
"type": "stdio",
"cwd": "${workspaceFolder}",
"command": "target/release/ahma_mcp",
"args": [
"--server",
"--tools-dir",
"tools"
]
}
},
"inputs": []
}
保存 mcp.json
文件后,重启 VS Code 以激活 MCP 服务器。
ahma_mcp
工具,例如:"使用 ahma_mcp 显示 git 状态"。连接成功后,你将可以使用约 44 个动态生成的 MCP 工具:
Git 操作:
mcp_ahma_mcp_git_status
- 检查工作树状态mcp_ahma_mcp_git_add
- 暂存更改mcp_ahma_mcp_git_commit
- 创建提交mcp_ahma_mcp_git_push
- 上传更改mcp_ahma_mcp_git_pull
- 下载更改Cargo 操作:
mcp_ahma_mcp_cargo_build
- 构建项目mcp_ahma_mcp_cargo_test
- 运行测试mcp_ahma_mcp_cargo_run
- 运行二进制文件mcp_ahma_mcp_cargo_check
- 检查代码而不构建mcp_ahma_mcp_cargo_doc
- 构建文档mcp_ahma_mcp_cargo_add
- 添加依赖项mcp_ahma_mcp_cargo_remove
- 移除依赖项mcp_ahma_mcp_cargo_update
- 更新依赖项mcp_ahma_mcp_cargo_fetch
- 获取依赖项mcp_ahma_mcp_cargo_install
- 安装二进制文件mcp_ahma_mcp_cargo_search
- 搜索 cratemcp_ahma_mcp_cargo_tree
- 依赖树mcp_ahma_mcp_cargo_version
- Cargo 版本mcp_ahma_mcp_cargo_rustc
- 自定义 rustcmcp_ahma_mcp_cargo_metadata
- 包元数据mcp_ahma_mcp_cargo_audit_audit
- 审计依赖项的漏洞mcp_ahma_mcp_cargo_bench_bench
- 运行基准测试mcp_ahma_mcp_cargo_clippy_clippy
- 使用 clippy 进行代码 lintingmcp_ahma_mcp_cargo_edit_add
- 使用 cargo-edit 添加依赖项mcp_ahma_mcp_cargo_edit_remove
- 使用 cargo-edit 移除依赖项mcp_ahma_mcp_cargo_edit_upgrade
- 使用 cargo-edit 升级依赖项mcp_ahma_mcp_cargo_edit_bump_version
- 使用 cargo-edit 提升包版本mcp_ahma_mcp_cargo_fmt_fmt
- 使用 rustfmt 格式化代码mcp_ahma_mcp_cargo_nextest_run
- 使用 nextest 运行测试mcp_ahma_mcp_cargo_llvm_cov_test
- 使用 LLVM 覆盖率运行测试(同步)mcp_ahma_mcp_cargo_llvm_cov_run
- 使用 LLVM 覆盖率运行二进制文件(同步)mcp_ahma_mcp_cargo_llvm_cov_report
- 生成覆盖率报告(同步)mcp_ahma_mcp_cargo_llvm_cov_show_env
- 显示覆盖率环境(同步)mcp_ahma_mcp_cargo_llvm_cov_clean
- 清理覆盖率数据(同步)mcp_ahma_mcp_cargo_llvm_cov_nextest
- 使用 LLVM 覆盖率运行 nextest(同步)clippy
、nextest
、fmt
、audit
、upgrade
、bump_version
、bench
文件操作(核心集):
mcp_ahma_mcp_cat_run
- 查看文件内容mcp_ahma_mcp_grep_run
- 搜索文本模式mcp_ahma_mcp_sed_run
- 编辑文本流mcp_ahma_mcp_echo_run
- 输出文本可选(按需添加):可以重新引入列表工具(ls.json
);测试不再假设其存在。
操作管理:
mcp_ahma_mcp_status
- 检查所有操作的状态(活跃、完成、失败)mcp_ahma_mcp_wait
- 等待操作完成,可配置超时时间(1 - 1800 秒,默认 240 秒)ls -la /path/to/your/ahma_mcp/target/release/ahma_mcp
ls -la /path/to/your/ahma_mcp/.ahma/tools/
mcp.json
中的所有路径都是绝对路径(无 ~
或环境变量)cargo run
chmod +x /path/to/your/ahma_mcp/target/release/ahma_mcp
cargo build --release
cargo run
)cargo build --release
status
工具检查哪些操作仍在运行。await
工具设置自定义超时时间:超时范围为 1 - 1800 秒(最大 30 分钟)。top
或活动监视器监控系统资源。cargo watch
和文件更改重启的优雅关闭处理。Ahma MCP 使用预热的 shell 池来最小化命令启动延迟。详情请参阅 shell_pool.rs
如果你想添加自己的 CLI 工具,可在 tools/
目录中创建一个 MTDF(MCP 工具定义格式)JSON 文件:
{
"name": "your_tool",
"description": "Brief description of the tool",
"command": "your_command",
"enabled": true,
"subcommand": [
{
"name": "subcommand_name",
"guidance_key": "sync_behavior",
"synchronous": true,
"description": "What this subcommand does",
"options": [
{
"name": "option_name",
"type": "string",
"description": "Option description"
}
]
}
]
}
使用集中式指导系统维护一致的 AI 指令:
"guidance_key": "async_behavior"
。"guidance_key": "sync_behavior"
。"guidance_key": "coordination_tool"
。tool_guidance.json
中定义可重用块。cargo.json
、python3.json
、gh.json
)。MTDF 是 ahma_mcp 基于 JSON 的工具配置格式,支持动态工具加载,无需更改代码:
tools/
目录中创建 JSON 文件添加新工具。cargo nextest run
、gh cache delete
)。cargo_fmt
而非 cargo_fmt_default
)。tool_guidance.json
实现可重用的 AI 指导块。除 Grok Code Fast 1
(它更喜欢终端而非 MCP 工具调用)外,测试过的工具调用 AI 均可正常工作。
支持 STDIO MCP 的 IDE 应该可以正常使用,但大多数测试是在 VS Code 中进行的。
基于 HTTP 的 MCP 客户端目前尚不支持。
欢迎提交问题报告和拉取请求。
本项目根据 Apache License 2.0 或 MIT License 许可。