Codex Gemini Delegator V2

Codex Gemini Delegator V2

An MCP server that lets OpenAI Codex delegate tasks to Google Gemini agents as isolated background workers, with Git worktree isolation, loop detection, and security boundary enforcement.

Category
访问服务器

README

Codex Gemini Delegator V2

A robust, production-ready MCP (Model Context Protocol) server that allows OpenAI Codex to supervise and delegate tasks to Google Gemini (Antigravity) workers as subordinate agents.

Unlike other bridges, this delegator treats Gemini workers as resilient background jobs. It orchestrates isolated Git worktrees, enforces strict security boundaries, monitors stream-json for infinite loop failures, and auto-nudges stuck workers to unblock them.

Key Features

  1. True Git Worktree Isolation: When Codex delegates a task, the delegator automatically spawns an invisible Git worktree (.worktrees/wt-<uuid>). Gemini executes its code changes strictly inside this isolated environment. Your main branch remains completely untouched until Codex explicitly applies the run.
  2. First-Party API Alignment: This MCP server exposes the exact tool names and signatures expected by mainstream Codex delegators (delegate_to_agent, apply_agent_run, get_agent_run_report, etc.).
  3. Loop Detection & Auto-Nudging: Built-in state heuristics actively monitor the stream-json output of the Gemini worker. If the worker gets stuck in an infinite tool failure loop or tries the exact same broken command 3 times in a row, the Supervisor forcefully restarts it with a recursive --session-id and a strict system nudge to change strategies.
  4. Symlink-Resistant Security Boundaries: Subordinate workers are hardened against path traversal and symlink vulnerabilities. A custom hook (enforce_boundaries.py) prevents them from executing destructive commands (rm -rf, git reset) and strictly jails their write access to their delegated scope.
  5. SQLite WAL Persistence: All runs, PIDs, and logs are tracked in a lightning-fast SQLite WAL ledger. If you close your Codex session, the Gemini workers keep running in the background and their state is fully recoverable.

Prerequisites

Installation & Bootstrapping

  1. Clone the repository:

    git clone https://github.com/psychofanplays/gemini4codex-mcp.git
    cd gemini4codex
    
  2. Register the MCP Server in Codex using uv: Add the following to your ~/.codex/config.toml (or equivalent Codex MCP configuration). We highly recommend using uv to automatically manage the environment and dependencies:

    [mcp.servers.gemini-delegator]
    command = "uv"
    args = [
        "--directory", 
        "/ABSOLUTE/PATH/TO/gemini4codex", 
        "run", 
        "-m",
        "server.gemini_delegator"
    ]
    
  3. Provide Codex with the Bootstrapping Instructions: Once connected, you must instruct Codex to read the BOOTSTRAP.md file located in this repository. This file provides Codex with the explicit instructions on how to structure the Multi-Agent Hierarchy and how to leverage gemini-3.1-pro and gemini-3.6-flash as subordinate agents.

    Example Prompt for Codex:

    "I have just connected the gemini-delegator MCP server. Please read the BOOTSTRAP.md file in the gemini4codex repository and apply the agent synergy patterns to your global memory."

How It Works

When Codex is connected to the MCP server, it gains access to the following tools:

  • list_agent_backends: Verifies the Gemini CLI and DB are healthy.
  • list_agent_runs: Displays all active, idle, and failed background workers.
  • delegate_to_agent: Spawns a new Gemini worker inside a new UUID Git Worktree.
  • continue_agent_run: Sends a follow-up instruction to an existing worker.
  • get_agent_run_report: Returns the worker's JSON logs, execution status, and importantly, the raw Git diff of what the worker changed inside its worktree.
  • apply_agent_run: Performs a squash merge of the worker's temporary worktree into your main branch.
  • cleanup_agent_run: Cancels a running worker and deletes its isolated worktree.

Example Workflow (From Codex's Perspective)

  1. Codex: "I need to refactor the database schema, but I don't want to break the app. I'll delegate this to a Gemini worker."
  2. Codex calls delegate_to_agent(worker_id="db-refactor", workspace_path=".")
  3. Delegator Server creates .worktrees/wt-5f8a9b2c and runs the google.antigravity SDK in-process inside it.
  4. Gemini works in the background, modifying files. If it loops or gets stuck, the Supervisor auto-nudges it.
  5. Codex periodically calls get_agent_run_report("db-refactor").
  6. Codex reads the git diff returned by the report. "Looks good, the tests passed."
  7. Codex calls apply_agent_run("db-refactor").
  8. Delegator Server squash merges the changes cleanly into the main branch but explicitly leaves them staged (no auto-commit), allowing Codex or the human user to review and finalize the commit.

Security

This plugin aggressively restricts the Gemini subordinate worker:

  • True OS Sandboxing: The Delegator explicitly prevents subordinate workers from bypassing the Antigravity OS sandbox, meaning they are natively isolated from the filesystem at the kernel level and cannot modify files outside the delegated scope.
  • Git Sandboxing: Workers are forbidden from running structural git commands (git commit, git push, git merge) or destructive operations (rm -rf).
  • Profile Segregation: You can delegate a scout or reviewer profile, which disables all write tools completely.

Architecture Map

The project is structured into three main layers:

gemini4codex/
├── pyproject.toml           # Python packaging and dependency config
├── BOOTSTRAP.md             # Essential instructions for Codex on how to use these agents
└── server/
    ├── gemini_delegator.py  # The FastMCP Server exposing endpoints to Codex
    ├── supervisor.py        # Async execution engine; parses stream-json & detects loops
    ├── worktree.py          # Git worktree isolation and squash-merge orchestrator
    ├── security.py          # Dynamic SDK hooks to jail the worker
    └── ledger.py            # SQLite WAL state manager for robust persistence
  • Layer 1: The Codex Interface (gemini_delegator.py) handles all incoming MCP requests.
  • Layer 2: The Orchestrator (worktree.py & supervisor.py) spins up the isolated environment and runs the process asynchronously via the Antigravity SDK.
  • Layer 3: The Jailed Subordinate (security.py) restricts the worker's context natively so it cannot harm the host system or primary branch.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选