Skip to main content
Glama
benzkittisak

codex-async-mcp

by benzkittisak

codex_start

Initiate a background codex task and receive an immediate job ID to track progress without blocking or timeout.

Instructions

Start a codex task asynchronously in the background.

Returns a job_id immediately — does not block or timeout. Use codex_poll(job_id) to check progress.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe task description to pass to codex.
cwdYesAbsolute path to the working directory for codex.
approval_policyNoOne of 'suggest', 'auto-edit', 'full-auto'. Default: 'suggest'.suggest

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The MCP tool handler function for 'codex_start'. Decorated with @mcp.tool(), accepts prompt, cwd, and optional approval_policy, and delegates to start_job().
    def codex_start(prompt: str, cwd: str, approval_policy: str = "suggest") -> dict:
        """
        Start a codex task asynchronously in the background.
    
        Returns a job_id immediately — does not block or timeout.
        Use codex_poll(job_id) to check progress.
    
        Args:
            prompt: The task description to pass to codex.
            cwd: Absolute path to the working directory for codex.
            approval_policy: One of 'suggest', 'auto-edit', 'full-auto'. Default: 'suggest'.
        """
        return start_job(prompt, cwd, approval_policy)
  • Registration of the tool via the @mcp.tool() decorator on the codex_start function.
    @mcp.tool()
  • The start_job() helper function that implements the actual logic: creates a job_id, spawns a subprocess, writes metadata, and returns the job_id/status.
    def start_job(prompt: str, cwd: str, approval_policy: str = DEFAULT_APPROVAL_POLICY) -> dict:
        job_id = uuid.uuid4().hex[:8]
        job_dir = _job_dir(job_id)
        job_dir.mkdir(parents=True, exist_ok=True)
        output_path = job_dir / "output.txt"
    
        # Map legacy approval_policy values to codex exec flags (v0.125.0+)
        approval_flags = {
            "suggest": ["-s", "read-only"],
            "auto-edit": ["--full-auto"],
            "full-auto": ["--dangerously-bypass-approvals-and-sandbox"],
        }
        flags = approval_flags.get(approval_policy, ["--full-auto"])
        cmd = [CODEX_BIN, "exec"] + flags + [prompt]
    
        with open(output_path, "w") as out_file:
            proc = subprocess.Popen(
                cmd,
                stdin=subprocess.DEVNULL,
                stdout=out_file,
                stderr=subprocess.STDOUT,
                cwd=cwd,
            )
    
        meta = {
            "job_id": job_id,
            "status": "running",
            "prompt": prompt,
            "cwd": cwd,
            "approval_policy": approval_policy,
            "pid": proc.pid,
            "started_at": datetime.now(timezone.utc).isoformat(),
            "finished_at": None,
            "exit_code": None,
        }
        _write_meta(job_id, meta)
    
        with _lock:
            _active_procs[job_id] = proc
    
        t = threading.Thread(target=_monitor, args=(job_id, proc), daemon=True)
        t.start()
    
        return {"job_id": job_id, "status": "running", "pid": proc.pid}
  • Configuration constants used by the tool, including JOBS_DIR, DEFAULT_APPROVAL_POLICY, CODEX_BIN, and limits.
    from pathlib import Path
    
    JOBS_DIR = Path.home() / ".codex-async" / "jobs"
    DEFAULT_APPROVAL_POLICY = "suggest"
    CODEX_BIN = "codex"
    JOB_TAIL_LINES = 100
    MAX_OUTPUT_CHARS = 8000
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Discloses async, non-blocking, immediate return of job_id. Does not mention side effects or auth, but core behavior is adequately covered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no wasted words. Front-loaded with purpose and key behavior. Highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Has output schema. Describes async nature and returns job_id. Could mention cancellation via sibling codex_cancel, but sufficient for a simple start tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so baseline 3. Description does not add meaning beyond schema; each parameter is defined in schema. No extra context provided.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the verb 'Start', resource 'codex task', and key behavior 'asynchronously in the background'. Distinguishes from siblings by mentioning that codex_poll is used to check progress.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit guidance to use codex_poll for progress checking. Implicitly tells when to use this tool (async tasks) but lacks explicit when-not-to-use or alternatives beyond polling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/benzkittisak/claude-codex-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server