ExMCP.ACP.Adapters.Codex (ex_mcp v0.9.0)

View Source

Adapter for Codex CLI (OpenAI) using codex app-server persistent mode.

Translates between ACP JSON-RPC and Codex's app-server JSON-RPC protocol. The app-server runs as a persistent subprocess communicating over NDJSON on stdin/stdout, with a JSON-RPC initialize handshake.

Ported from nshkrdotcom/codex_sdk's AppServer.Connection pattern.

Codex App-Server Protocol

  • Command: codex app-server
  • Handshake: initialize request → response → initialized notification
  • Session: thread/startturn/start → notifications → turn/completed
  • Notifications: NDJSON events for items, text deltas, reasoning, tool calls, etc.

ACP Mapping

ACP MessageCodex JSON-RPC
session/newthread/start request
session/loadthread/start with threadId (resume)
session/promptturn/start request
session/cancelturn/interrupt request
item/agentMessage/deltasession/update (text)
item/reasoning/textDeltasession/update (thinking)
item/completed (tool)session/update (tool_call/tool_result)
item/commandExecution/*session/update (tool_output)
turn/completedprompt response result

Features

  • Initialize handshake with post_connect/1
  • Text and thinking streaming
  • Tool call and tool result notifications
  • Command execution output streaming
  • Token usage tracking
  • Turn interrupt/cancel support
  • Image content in prompts

Limitations

  • No session listing (Codex doesn't expose session enumeration)
  • No mode switching (static approval policy at session start)
  • No model switching mid-session (set at thread/start)
  • No authentication flow (relies on user's local auth)