Skip to main content
Glama

agy-bus

一个轻量级本地异步任务总线(Stdio MCP Server + 后台并发 Worker),用于在 macOS 上以单向调度架构将 Gemini 桌面客户端(Task 模式) 与终端 agy CLI 解耦串联:

  • Gemini 客户端 负责需求拆解、架构规划、派单与结果验收;

  • 后台 agy Worker 负责重度编码、多仓库并发执行与批量任务;

  • 零全盘权限:MCP Server 只读写位于已连接文件夹内的 SQLite(WAL)与日志,无需给 Gemini 客户端勾选 Allow full file access。

架构设计

Gemini Desktop (Local MCP Sandbox)
        │  enqueue_task / get_task_status / list_tasks / cancel_task
        ▼
  agy-bus-mcp  ──(read/write)──▶  .agy_bus/bus.db (SQLite WAL) + .agy_bus/logs/
                                         ▲
                                         │  atomic claim (per-cwd mutex)
                                         │
  agy-bus-worker (常规终端 / LaunchAgent,继承完整 PATH / Git / SSH / Keychain)
        │
        ▼  subprocess: agy -p ... --output-format json --mode ...
                         [--sandbox] [--conversation ...] [--model ...]
                         [--effort ...] [--agent ...] [--add-dir ...]
     agy CLI

核心特性

  • 同目录串行互斥,不同目录并发:claim_next_task() 通过 BEGIN IMMEDIATE 原子抢占任务,跳过正在执行的 cwd,避免两个 agy 同时修改同一 Git 仓库。

  • 传引用不传全文:MCP 默认只返回任务状态、退出码、会话 ID、<= 1500 字精简摘要和日志文件路径,避免长输出撑爆客户端上下文。

  • 短任务阻塞等待:get_task_status 支持 wait_seconds(0..20),可等待短任务完成后再返回,减少轮询次数。

  • 异常自动恢复:Worker 启动时自动将异常中断遗留的 running 任务标记为 failed。

  • 兼容 agy 多种输出:自动解析单行 JSON、多行 NDJSON 与纯文本降级,提取 conversation_id 供续接会话。

Related MCP server: Antigravity Worker MCP

快速开始

前置依赖

  • macOS + Python 3.11+

  • uv(brew install uv)

  • 已登录的 agy CLI(已在 agy 1.5.21 实测验证)

第 1 步:在 Gemini 已连接文件夹一键安装

重要:请先进入你在 Gemini 客户端中已授权的 Connected Folder(这样无需开启全盘文件访问权限)。安装脚本会自动拉取代码到当前目录下的 agy-bus/(也可通过 --dir <路径> 或 AGY_BUS_INSTALL_DIR 自定义目录)。

cd <你的-Gemini-已连接文件夹>
curl -fsSL https://raw.githubusercontent.com/backtomyfuture/agy-bus/main/install.sh | bash

安装脚本会自动完成以下工作:

  • 自动拉取或更新 agy-bus 源码(支持 git 与无 git 环境的 tarball 下载);

  • 安装依赖并构建 .venv 虚拟环境;

  • 运行离线自检测试(uv run --offline pytest -q);

  • 自动安装并启动 macOS LaunchAgent 后台常驻 Worker(支持开机自启;如需跳过可追加 --no-service);

  • 自动将 MCP 命令路径复制到剪贴板(可直接 Cmd + V 粘贴)。

第 2 步:在 Gemini 桌面客户端添加 Local MCP

打开 Gemini 客户端 Task 模式 → Connected Apps → Local MCP,将已自动复制的命令直接 Cmd + V 粘贴到 Command,保持 Allow full file access 不勾选即可立即使用:

配置项

填写内容

Name

agy-bus

Description

Local async task bus for agy CLI

Command

Cmd + V 粘贴(<项目绝对路径>/.venv/bin/agy-bus-mcp)

Allow full file access

保持不勾选

为什么不填 uv run? 在未勾选 Allow full file access 的沙箱中,uv 会尝试访问 ~/.cache/uv 而被拦截;直接指向 .venv/bin/agy-bus-mcp 可免去 uv 依赖且毫秒级握手。

卸载后台服务:curl -fsSL https://raw.githubusercontent.com/backtomyfuture/agy-bus/main/install.sh | bash -s -- --uninstall

MCP 工具列表

工具

说明

enqueue_task(prompt, cwd, mode="accept-edits", use_sandbox=True, conversation_id="", model="", effort="", agent="", add_dirs=[])

校验参数并入队,毫秒级返回 task_id、status、log_path 及任务配置

get_task_status(task_id, include_log_tail=False, tail_lines=40, wait_seconds=0)

查询状态、退出码、精简摘要、会话 ID 与日志路径;wait_seconds 支持 0..20 秒短暂阻塞等待至结束;按需附带日志末尾

list_tasks(limit=10, status="")

列出最近任务概览(支持按 pending / running / done / failed / cancelled 过滤)

cancel_task(task_id)

取消尚处于 pending 状态的任务

enqueue_task 支持的 agy 参数映射

MCP 参数

对应 agy 选项

默认值 / 可选值

说明

prompt

-p

必填

给 agy 的完整任务指令(建议包含目标、约束与验收标准)

cwd

工作目录

必填

目标工作目录路径(同目录串行互斥,不同目录并发)

mode

--mode

"accept-edits"(可选 accept-edits | auto | plan)

执行权限模式

use_sandbox

--sandbox

True

为 True 时附加 --sandbox 终端限制

conversation_id

--conversation

""

传入既有会话 ID 以续接上下文;留空表示新会话

model

--model

""

指定模型名称;留空使用 agy 默认模型

effort

--effort

""(可选 low | medium | high | xhigh | max)

指定推理强度

agent

--agent

""

指定 agy Agent 名称

add_dirs

--add-dir

[]

附加到工作区的额外目录列表(自动展开为可重复 --add-dir)

常用环境变量(Worker 侧)

变量

默认值

说明

AGY_BUS_DIR

<项目目录>/.agy_bus

SQLite 数据库与日志目录

AGY_BIN

自动探测(which agy)

agy CLI 可执行文件路径

AGY_POLL_INTERVAL

1.5

队列轮询间隔(秒)

AGY_MAX_WORKERS

2

最大并发执行线程数

AGY_TASK_TIMEOUT

1800

单任务超时时间(秒)

AGY_NOTIFY

1

完成后发送 macOS 原生通知(0 关闭)

常见问题排查

  • Gemini 客户端点 Next 一直卡住:先彻底退出客户端(Cmd + Q)再重启以重置本地 MCP 管理器;同时确保项目使用的是 pyproject.toml 中锁定的 mcp>=1.6.0,<2.0.0(稳定版 FastMCP)。

  • Worker 执行报错 authentication required:请确认 Worker 是在常规 macOS 终端或 LaunchAgent 中启动,并且已在该终端执行过 agy 完成登录。

  • 运行自动化测试:

    uv run --offline pytest -q

License

MIT

Available Tools

4 tools
cancel_taskB

取消尚处于 pending 状态的任务(已在运行或已结束的任务无法取消)。 Cancel a task that is still in 'pending' status.

Args: task_id: 要取消的任务 ID。

Inputs: task_id (required).

enqueue_taskA

将一条编码或执行任务入队,由后台 Worker 异步调用本地 agy CLI 执行。 Enqueue a task into the local agy-bus SQLite queue for asynchronous execution by the background Worker.

Args: prompt: 给 agy 的完整任务指令(建议包含目标、约束与验收标准)。 cwd: 目标工作目录(如 Git 仓库绝对路径);同目录任务会自动串行互斥,不同目录并发执行。 mode: agy 执行权限模式,可选 "accept-edits"(默认)、"auto"、"plan"。 use_sandbox: 是否开启 agy --sandbox 终端限制(默认 True)。 conversation_id: 可选,传入既有会话 ID 以通过 --conversation 续接上下文;留空表示新会话。 model: 可选,指定 agy 使用的模型名称(对应 --model);留空使用默认模型。 effort: 可选,指定推理强度:low / medium / high / xhigh / max(对应 --effort)。 agent: 可选,指定 agy Agent 名称(对应 --agent)。 add_dirs: 可选,附加到工作区的额外目录路径列表(对应可重复的 --add-dir)。

Returns: 包含 task_id、status 与 log_path 的入队回执(毫秒级返回)。

Inputs: cwd (required), prompt (required), mode, agent, +5 more.

get_task_statusA

查询指定任务的执行状态、退出码、精简摘要(<=1500字)、会话 ID 与日志路径。 Query status, exit code, concise summary, conversation ID, and log file path for a task.

默认遵循“传引用不传全文”原则;仅在需要排障时将 include_log_tail 设为 True。 对于短任务,可设置 wait_seconds(1~20)让服务端短暂等待至结束再返回,减少轮询次数。

Args: task_id: enqueue_task 返回的任务 ID。 include_log_tail: 是否附带完整日志文件的末尾若干行(默认 False)。 tail_lines: 当 include_log_tail=True 时返回的末尾行数(默认 40,上限 500)。 wait_seconds: 可选,最多阻塞等待的秒数(0 表示立即返回,上限 20 秒)。

Inputs: task_id (required), tail_lines, wait_seconds, include_log_tail.

list_tasksB

列出最近的任务概览(含截取后的 prompt 预览)。 List recent tasks with truncated prompt previews.

Args: limit: 返回的最大任务数(默认 10,上限 200)。 status: 可选状态过滤:pending / running / done / failed / cancelled;留空表示不过滤。

Inputs: limit, status.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool targets a distinct queue operation: enqueue, list, cancel, and detailed status. The boundary between list_tasks (multi-task overview) and get_task_status (single-task detail) is clear from descriptions and arguments.

    Naming Consistency5/5

    All names follow a consistent snake_case verb_noun pattern: enqueue_task, list_tasks, cancel_task, get_task_status. The naming is predictable and readable.

    Tool Count5/5

    Four tools are well-scoped for a queue-management server, covering creation, listing, cancellation, and status inspection. No tool feels redundant or out of place.

    Completeness4/5

    The core task lifecycle is covered: enqueue, list, inspect status, and cancel. Minor gaps exist around retrying failed tasks, purging completed tasks, or retrieving logs separately, but the included log-tail option mitigates most debugging needs.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      A task-level STDIO MCP server that lets Codex or any other MCP client hand off scoped coding jobs to an asynchronous worker agent which reads the code, edits files, and runs tests, while the client keeps ownership of planning and acceptance. Exposes submit, wait, query, follow-up, and cancel tools so multiple clients can queue and monitor tasks against a chosen project root.
      5
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables STDIO-compatible AI assistants to queue coding work onto the official Google Antigravity CLI and track status, read reports or patches, query capabilities, or cancel running tasks without blocking. Supports trusted direct execution plus optional isolated or read-only modes depending on the platform.
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables dispatching coding tasks to multiple coding-agent CLIs with persistent task history, bounded reads, cancellation, continuation, reusable workflows, and opt-in exact-action approvals.
      63
      Apache 2.0