Skip to main content
Glama
README.md
# agy-omp-mcp

零第三方依赖的 MCP (Model Context Protocol) stdio 桥接服务,让 **Google Antigravity** 直接调用本机的 **`omp` (oh-my-pi)** CLI。

## 特性

- **零第三方依赖**:仅依赖 Python 3.11+ 标准库,克隆后可直接运行,无需 `pip install`。
- **复用本机 `omp` 环境**:通过 `omp --mode json -p` 调用本机已配置的 `omp`,直接沿用 `~/.omp/agent` 的登录凭据、模型角色配置与会话历史。
- **当前模型透明提示**:
  - 流式解析 `omp` JSONL 事件中的实际 `provider/model`(若单次执行中发生模型切换,会一并列出全部涉及的模型)。
  - 执行启动及识别到真实模型时发送 MCP `notifications/message` 通知;若宿主客户端提供了 `progressToken`,同步调用还会发送 `notifications/progress` 通知。
  - 正常工具结果首行输出当前调用的模型名称(`omp_get_model` 展示本机默认配置模型;`omp_start_task` 启动时先展示指定/默认模型并在运行中更新为实际模型),并在 MCP `instructions` 与工具描述中要求宿主 Agent 向用户汇报模型名称。
- **多轮会话续接**:当 `omp` 返回 `session` 事件时,结果中包含 `Session: <id>`,传入 `session_id` 可通过 `omp --resume` 继续同一上下文。
- **同步与异步双模式**:支持只读问答/代码审查、同步任务执行,以及保存在当前服务进程内存中的后台任务启动、状态轮询与取消(Windows 上尝试终止进程树,其他平台终止子进程)。

## 目录结构

```text
agy-omp-mcp/
├── LICENSE                          # MIT 许可证
├── README.md
├── pyproject.toml                   # 项目元数据与可选安装入口(无第三方运行时依赖)
├── run_server.py                    # MCP stdio 入口脚本
├── omp_mcp/
│   ├── __init__.py
│   ├── __main__.py                  # 支持 `python -m omp_mcp` 启动
│   ├── omp_client.py                # 本机 omp CLI 调用、JSONL 解析与后台任务管理
│   └── server.py                    # JSON-RPC 2.0 MCP stdio 服务与工具定义
├── examples/
│   ├── mcp_config.json              # Antigravity 全局 MCP 配置示例
│   └── rules/
│       ├── omp-model-notice.md      # 轻量规则:仅约束调用 omp 时提示模型名
│       └── omp-orchestrator.md      # 完整编排规则:Orchestrator 分工、文档核对与模型提示
└── tests/
    └── test_omp_mcp.py              # 单元测试
```

## 提供的 MCP 工具

| 工具 | 说明 | 默认超时 |
| :--- | :--- | :--- |
| `omp_get_model` | 查看本机 `omp` 当前默认模型、角色模型(`default`/`smol`/`slow`/`plan`)、预设与思考深度,可选列出或按关键字搜索可用模型 | — |
| `omp_ask` | 只读问答、代码审查、架构诊断与文档核对;默认开启只读工具 `read,grep,glob`,传 `allow_codebase_read=false` 可切换为纯文本问答,不修改文件 | 300s(10–3600s) |
| `omp_run_task` | 在指定 `cwd` 中同步执行编码、重构、调试或验证任务(自动审批工具调用,可传 `tools` 限制工具集) | 600s(10–7200s) |
| `omp_start_task` | 在后台异步启动耗时任务并返回 `task_id`;默认可写并自动审批,可传 `read_only=true` 切为只读(任务状态仅存活于当前 MCP 进程内) | 900s(10–7200s) |
| `omp_task_status` | 查询后台任务状态、当前识别到的模型、耗时、最近工具活动以及最终输出 | — |
| `omp_cancel_task` | 取消运行中的后台任务并终止对应的本地 `omp` 进程 | — |

> 安全边界说明:`cwd` 仅作为工作目录传给 `omp`,并非文件系统沙箱;另外本地桥接仍会通过本机 `omp` 调用所配置的远端/本地模型提供方,提示词与读取的代码内容将发送至对应模型。

## 前置要求

- Python 3.11+
- 本机已安装并完成登录配置的 [`omp` (oh-my-pi)](https://github.com/can1357/oh-my-pi) CLI

## 配置方法

### 1. 注册到 Antigravity MCP 配置

编辑 `~/.gemini/config/mcp_config.json`(Windows 为 `C:\Users\<用户名>\.gemini\config\mcp_config.json`),参考 `examples/mcp_config.json` 添加 `omp` 服务(将路径替换为本机仓库的绝对路径):

```json
{
  "mcpServers": {
    "omp": {
      "command": "python",
      "args": ["/path/to/agy-omp-mcp/run_server.py"]
    }
  }
}
```

如果 GUI 启动的 Antigravity 环境中 `python` 或 `omp` 不在默认 `PATH` 里,建议填绝对路径并通过 `env.OMP_BIN` 显式指定:

```json
{
  "mcpServers": {
    "omp": {
      "command": "C:/Path/To/Python/python.exe",
      "args": ["C:/Path/To/agy-omp-mcp/run_server.py"],
      "env": {
        "OMP_BIN": "C:/Users/<用户名>/.bun/bin/omp.exe"
      }
    }
  }
}
```

也支持通过 `python -m omp_mcp` 启动,或执行 `pip install -e .` 后使用 `agy-omp-mcp` 命令启动。保存配置后,在 Antigravity 中刷新 MCP 服务或新开会话即可生效。

### 2. (推荐)启用 Antigravity 规则

从 `examples/rules/` 中二选一复制到 `~/.gemini/config/rules/`(全局生效)或具体仓库的 `.agents/rules/`(仅当前项目生效):

- **仅提示模型**(轻量版):`examples/rules/omp-model-notice.md`
- **完整 Orchestrator 编排 + 模型提示**:`examples/rules/omp-orchestrator.md`
  - 明确 Antigravity(规划、小改动、文档/注释编写、最终验收)与 `omp`(多文件实现/重构、跨模型审查、核对文档与注释)的协作边界。
  - 已包含模型透明提示要求,启用此规则时无需同时保留轻量版。

## 开发与测试

运行单元测试(不发起真实网络请求):

```bash
python -m unittest discover -s tests -v
```

TDQS

A3.9/5.0

Scored across 6 tools

Disambiguation5/5

Each tool has a clearly distinct role: read-only Q&A (omp_ask) vs. synchronous write-capable execution (omp_run_task) vs. asynchronous background execution (omp_start_task). The task lifecycle tools (start/status/cancel) and the model configuration query are cleanly separated with no meaningful overlap.

Naming Consistency4/5

All tools share a consistent 'omp_' prefix and mostly follow a verb_noun pattern (get_model, ask, run_task, start_task, cancel_task). omp_task_status is the one deviation, using a noun_phrase rather than a verb-first form like get_task_status.

Tool Count5/5

Six tools is well-scoped for a local omp delegation wrapper: one config query, one read-only query, one sync runner, and a three-tool async lifecycle. Every tool earns its place without redundancy.

Completeness4/5

The surface covers model inspection, read-only Q&A, synchronous execution, and full async task lifecycle (start/status/cancel). Minor gaps exist around session continuation or streaming live logs, but agents can work around these through polling and repeated calls.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues