mcpField
M
Mcp Await

Mcp Await

本地服务
github.com/ricardo-hdrn开发工具234 周前更新

关于 Mcp Await

Mcp Await 是供 AI 助手使用的 MCP 服务和命令行工具,可等待端口、文件、URL、进程和命令等开发条件。它支持阻塞等待,也可在后台监视并读取或取消任务。

主要功能

  1. 01等待端口、文件、URL 和进程
  2. 02等待 Docker 容器及 GitHub Actions 运行
  3. 03重复执行命令直至成功
  4. 04运行阻塞式或后台监视
  5. 05通过 MCP 资源读取监视结果

适用场景

  1. 01等待本地服务接受连接
  2. 02检测文件创建、修改或删除
  3. 03等待健康检查 URL 或命令成功
  4. 04监视 Docker 容器或 GitHub Actions 运行

MCP 相关

提供 wait_for_port、wait_for_file、wait_for_url 和 wait_for_command 等条件等待工具。后台监视会作为 MCP 资源公开,并可取消。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"await": {
"command": "npx",
"args": [
"-y",
"mcp-await"
]
}
}
}
启动命令npx -y mcp-await

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmmcp-await0.1.3

工具

8

收录的工具列表 · 更新于 2 周前

参数类型必填说明
watch_idstring是要取消的 watch_id

详细介绍

mcp-await

crates.io CI license

面向 AI 命令行助手(Claude Code、Codex、Cursor 等)的条件监视器 MCP 服务 + CLI。

无需使用会浪费 API 往返的 sleep 循环和 curl --retry 轮询,只需调用一次等待工具——它会阻塞,直到条件满足并返回结果。

demo

安装

# Prebuilt binary (Linux, macOS, Windows) — download from GitHub Releases
# https://github.com/ricardo-hdrn/mcp-await/releases/latest

# From crates.io
cargo install mcp-await

# From source
git clone https://github.com/ricardo-hdrn/mcp-await.git
cd mcp-await
cargo build --release

快速开始

# Wait for a service to be ready
mcp-await port localhost 8080 --timeout 30

# Wait for a file to appear
mcp-await file /tmp/deploy.lock --event create --timeout 60

# Wait for a command to succeed
mcp-await cmd "curl -sf http://localhost:8080/health" --interval 2 --timeout 30

工具

工具关键参数监视方式
wait_for_porthost、portTCP 连接循环,间隔 500ms
wait_for_filepath、event(create/modify/delete)通过 notify crate 使用 inotify,不进行轮询
wait_for_urlurl、expected_status(默认 200)curl 循环,间隔 2s(需要 curl)
wait_for_pidpid检查 /proc/{pid},间隔 500ms
wait_for_dockercontainerdocker wait(需要 docker)
wait_for_gh_runrun_id、repo(可选)gh run watch(需要 gh)
wait_for_commandcommand、interval_seconds(默认 5)通过 sh -c 重新运行,直到退出码为 0
cancel_watchwatch_id取消非阻塞监视

所有工具都接受 timeout_seconds(默认值:300)和 blocking(默认值:true)。

CLI 用法

该二进制文件也可作为独立 CLI 工具使用:

# TCP port
mcp-await port localhost 5432 --timeout 30

# File events
mcp-await file /var/log/app.log --event modify --timeout 120
mcp-await file /tmp/flag --event create --timeout 60
mcp-await file /tmp/old.pid --event delete --timeout 30

# HTTP status
mcp-await url https://api.example.com/health --status 200 --timeout 120

# Process exit
mcp-await pid 12345 --timeout 300

# Docker container exit
mcp-await docker my-container --timeout 600

# GitHub Actions run
mcp-await gh-run 12345678 --repo owner/repo --timeout 1800

# Arbitrary shell command (exit 0 = success)
mcp-await cmd "test -f /tmp/ready" --interval 2 --timeout 30
退出码
代码含义
0条件满足(成功)
1超时
2错误
输出格式

所有命令均输出 JSON:

{
  "status": "success",
  "elapsed_seconds": 1.23,
  "detail": "localhost:8080 is accepting connections"
}

MCP 服务设置

Claude Code

添加到 ~/.claude.json:

{
  "mcpServers": {
    "await": {
      "command": "/path/to/mcp-await"
    }
  }
}

不带子命令调用二进制文件时(或使用 mcp-await serve),它会作为 stdio MCP 服务运行。

MCP Inspector
npx @modelcontextprotocol/inspector ./target/release/mcp-await

阻塞与非阻塞模式

阻塞(默认)

工具调用会一直等待,直到条件满足、超时或被取消。这是最简单的模式——AI 助手会等待结果。

非阻塞

设置 blocking: false,即可立即获得包含 watch_id 和资源 URI 的响应。服务会在后台监视,并在完成时推送通知。

流程:

  1. 使用 blocking: false 调用 wait_for_port
  2. 立即获得响应:
    {"watch_id": "port-1", "resource": "watch://port-1", "status": "watching"}
    
  3. 等待期间执行其他工作
  4. 条件满足时收到 notifications/resources/updated
  5. 读取 watch://port-1 获取完整结果
取消

使用 cancel_watch 取消任何非阻塞监视:

{"watch_id": "port-1"}

资源

非阻塞监视会作为 MCP 资源公开,地址为 watch://{watch_id}。

  • list_resources — 返回所有活动中和已完成的监视
  • read_resource("watch://port-1") — 返回包含监视状态和结果的 JSON

强化 Agent 用法

Agent 有时会改用 shell 变通方案,而不是使用 mcp-await。可以在项目的 Agent 指令文件中添加一段内容,以强化此行为:

Agent指令文件
Claude CodeCLAUDE.md
CodexAGENTS.md
Gemini CLIGEMINI.md
Cursor.cursor/rules/
Windsurf.windsurfrules
## Waiting for conditions

Use mcp-await tools instead of shell workarounds:
- `wait_for_port` instead of `while ! nc ...; do sleep 1; done`
- `wait_for_url` instead of `curl --retry`
- `wait_for_file` instead of polling loops
- `wait_for_command` instead of `while ! cmd; do sleep N; done`

Prefer `blocking: false` when there is independent work to do in parallel.

路线图

  • 添加 Agent 级指令,在所有 Agent 中强制使用 mcp-await(系统提示词、工具元数据提示)
  • 扩大 Agent 兼容性测试范围(Codex、Gemini CLI、Cursor、Windsurf)

开发

cargo build           # debug build
cargo build --release # release build
cargo test            # run tests
cargo clippy          # lint
cargo fmt             # format

许可证

MIT

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。