Codex Gemini Delegator V2
This server enables OpenAI Codex to delegate and manage tasks executed by Google Gemini agents in isolated Git worktrees, with full lifecycle management and secure application of changes.
Verify backend health (
list_agent_backends): check that the Gemini CLI and database are operational.List existing runs (
list_agent_runs): view active, idle, or failed Gemini agent workers.Delegate tasks (
delegate_to_agent): spawn a new Gemini worker in an isolated Git worktree with an objective, context, workspace path, effort level, profile (worker,scout,reviewer), and optional model selection.Continue runs (
continue_agent_run): send follow-up instructions to an existing worker to extend or refine its work.Get reports (
get_agent_run_report): retrieve execution status, logs, and the full Git diff of changes made in the worktree.Apply changes (
apply_agent_run): stage the worker's changes into the main branch without auto-committing, so they can be reviewed before finalizing.Clean up (
cleanup_agent_run): cancel a running worker and delete its temporary worktree.Enforce security boundaries: prevent destructive commands, path traversal, and writes outside the delegated scope.
Support profiles:
scoutandreviewerprofiles can disable write access for enhanced security.Ensure persistence and recoverability: agent runs, PIDs, and logs are stored using SQLite WAL.
Allows delegation of coding tasks to Google Gemini (Antigravity) workers, managing isolated Git worktrees, monitoring execution, and applying their results.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Codex Gemini Delegator V2 Delegate the API refactor to Gemini and apply the result when ready."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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, and connects to the already-running Antigravity language server.
Key Features
True Git Worktree Isolation: When Codex delegates a task, the delegator automatically spawns an isolated worktree (
~/.codex/gemini-delegator/worktrees/wt-<uuid>). Gemini executes its code changes strictly inside this isolated environment. Reports include uncommitted and untracked changes; applying a run stages them into a clean target without auto-committing.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.).Antigravity Language-Server Bridge: Workers use the signed-in Antigravity Desktop language server. The bridge discovers its dynamic local port by validating the CSRF page instead of relying on a stale hard-coded port.
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.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.
Related MCP server: sol-luna-orchestrator
Prerequisites
Google Antigravity (
geminiCLI) installed globally.Python 3.10+
Codex CLI (
codex)
Installation
Clone the repository:
git clone https://github.com/psychofanplays/gemini4codex-mcp.git cd gemini4codexRegister the MCP Server in Codex using
uv: Add the following to your~/.codex/config.toml(or equivalent Codex MCP configuration). We highly recommend usinguvto automatically manage the environment and dependencies:[mcp.servers.gemini-delegator] command = "uv" args = [ "--directory", "/ABSOLUTE/PATH/TO/gemini4codex", "run", "-m", "server.gemini_delegator" ]No bootstrap command is required: The MCP server does not execute bootstrap/setup instructions.
GEMINI.mdand Codex-side instructions remain policy references only.
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 the complete tracked/untracked diff from its worktree.apply_agent_run: Stages the worker's worktree patch into a clean target branch; it does not auto-commit.cleanup_agent_run: Cancels a running worker and deletes its isolated worktree.
Example Workflow (From Codex's Perspective)
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."
Codex calls
delegate_to_agent(worker_id="db-refactor", workspace_path=".")Delegator Server creates
~/.codex/gemini-delegator/worktrees/wt-5f8a9b2cand sends the task through the Antigravity language server.Gemini works in the background, modifying files. Codex reviews the complete diff before applying it.
Codex periodically calls
get_agent_run_report("db-refactor").Codex reads the
git diffreturned by the report. "Looks good, the tests passed."Codex calls
apply_agent_run("db-refactor").Delegator Server stages the changes into the main branch but explicitly leaves them uncommitted, 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
scoutorreviewerprofile, which disables all write tools completely.
Architecture Map
The project is structured into three main layers:
gemini4codex/
├── pyproject.toml # Python packaging and dependency config
├── Codex-BOOTSTRAP.md # Optional historical/reference guidance; never executed by the server
└── server/
├── gemini_delegator.py # The FastMCP Server exposing endpoints to Codex
├── agentapi.py # Antigravity language-server bridge and port discovery
├── supervisor.py # Async execution engine and ledger integration
├── worktree.py # Git worktree isolation and patch staging
├── security.py # Dynamic SDK hooks to jail the worker
└── ledger.py # SQLite WAL state manager for robust persistenceLayer 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 worker asynchronously through the Antigravity language server.Layer 3: The Jailed Subordinate (
security.py) restricts the worker's context natively so it cannot harm the host system or primary branch.
Available Tools
7 toolsapply_agent_runB
Merge the changes from the agent's worktree back into the main branch.
Inputs: worker_id (required). Returns: result
cleanup_agent_runA
Cancel a running agent and delete its temporary worktree.
Inputs: worker_id (required). Returns: result
continue_agent_runA
Send follow-up instructions to an existing Gemini worker to continue its workstream.
Inputs: worker_id (required), instruction (required). Returns: result
delegate_to_agentA
Delegate a new task to a Gemini worker. Creates a new Git worktree for isolated execution.
Inputs: context (required), objective (required), worker_id (required), workspace_path (required), +3 more. Returns: result
get_agent_run_reportA
Get the full results, recent events, and the Git diff of an agent run.
Inputs: worker_id (required). Returns: result
list_agent_backendsA
List available agent backends and check their health.
Inputs: no named parameters. Returns: result
list_agent_runsA
List all agent runs, their states, and recent activity. Use this before creating new workers.
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a distinct action: listing backends, listing runs, fetching a report, delegating a task, continuing a run, applying changes, and cleaning up. There is no overlap or ambiguity between them.
All tool names follow a consistent verb_noun pattern in lower snake_case, e.g., list_agent_backends, delegate_to_agent, continue_agent_run. The variation between 'list' and 'get' is minor and conventional.
With 7 tools, the set is well-scoped for managing agent worker lifecycles. Each tool fills a specific niche without redundancy or unnecessary bloat.
The tools cover the full lifecycle of agent runs: creating (delegate), continuing, reading reports, listing, applying, and cleaning up. No critical operations are missing for the stated purpose.
Maintenance
Related MCP Connectors
Official MCP server for Agentwork — delegate tasks to AI agents with human-in-the-loop
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
An MCP server that gives your AI access to the source code and docs of all public github repos
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server that delegates coding and sysops work to cheaper agents via durable background queues, with git worktree isolation, safety policies, and clarification rounds to avoid hitting limits of frontier models.27 PyPI2Apache 2.0
- AlicenseAqualityBmaintenanceAn MCP server that enables a supervising OpenAI Codex agent to delegate bounded implementation tasks to isolated worker threads with enforced file scopes and verification, optionally running in parallel git worktrees.59 npm7MIT
- AlicenseNot gradedqualityCmaintenanceMCP server that lets Codex supervise Claude Code or DeepSeek Harness as workers in isolated Git worktrees, with a bridge_run/bridge_respond/bridge_apply workflow for task delegation and safe cherry-pick integration.19 npmApache 2.0
- AlicenseAqualityDmaintenanceAn MCP server that splits coding work between ChatGPT web (planning, review) and Codex CLI (implementation), enabling agentic workflows over a local repo with risk-gated execution and safety rails.23MIT