By Celia Chen, Member of the Technical Staff
Overview
This article explains how OpenAI built the Codex App Server, a bidirectional JSON-RPC API that serves as the critical link between the Codex harness (agent loop and logic) and various client surfaces including the web app, CLI, IDE extensions, and the macOS desktop app. It covers the architecture, protocol design with conversation primitives (items, turns, threads), and integration patterns for local apps, web runtime, and the TUI.
What You'll Learn
How the Codex App Server architecture exposes the Codex harness to clients via a bidirectional JSON-RPC protocol
How to design conversation primitives (items, turns, threads) for agent-based interaction protocols
When to choose between App Server, MCP server, Codex Exec, and Codex SDK integration methods
How different client surfaces (IDEs, web apps, CLI) integrate with a shared agent harness via stdio and JSON-RPC
Why backward-compatible protocol design matters for evolving agent APIs across multiple client release cycles
Prerequisites & Requirements
- Understanding of JSON-RPC or similar request/response protocols
- Familiarity with agent loops and LLM-based coding assistants
- Basic understanding of stdio-based inter-process communication(optional)
- Experience with IDE extension development or client-server architectures(optional)
- Familiarity with OpenAI Codex CLI(optional)
Key Questions Answered
What is the Codex App Server and why was it built?
What are the main components of the Codex App Server architecture?
What are the conversation primitives in the Codex App Server protocol?
How do local IDE integrations connect to the Codex App Server?
How does Codex Web handle ephemeral browser sessions with the App Server?
Why did OpenAI choose JSON-RPC over MCP for the Codex App Server?
How does the approval flow work in the Codex App Server protocol?
How can developers generate client bindings for the Codex App Server?
Technologies & Tools
Some links below are affiliate links. We may earn a commission if you make a purchase.
Key Actionable Insights
1Use the App Server's JSON-RPC protocol as the primary integration method when embedding Codex into your product, as it provides the full Codex harness functionality including thread management, tool execution, approval flows, and streaming events. This is the first-class integration method OpenAI will maintain going forward.The App Server protocol is designed to be backward compatible, meaning older clients can safely communicate with newer server versions without breaking changes.
2Design agent interaction protocols around three clear primitives: items (atomic I/O units), turns (user-initiated work units), and threads (durable session containers). This separation makes the interaction stream easy to integrate and resilient across different UI surfaces, from terminal to web to IDE.Each item has an explicit lifecycle (started, delta, completed) that lets clients start rendering immediately, stream incremental updates, and finalize cleanly, enabling rich real-time UIs.
3Decouple your App Server binary version from client release cycles to enable faster iteration. Partners like Xcode keep the client stable and allow it to point to newer App Server binaries, enabling server-side improvements and bug fixes without waiting for a client release.This works because the JSON-RPC surface is designed for backward compatibility, so older clients can talk to newer servers safely.
4When building web-based agent interfaces, keep state and progress on the server side rather than in the browser. This ensures that long-running tasks continue even if the browser tab closes or network drops, and new sessions can reconnect and catch up without rebuilding state.Codex Web uses containers with the App Server binary running inside, communicating via HTTP and SSE to the browser, making the client-side UI lightweight.
5Use the 'codex app-server generate-ts' or 'codex app-server generate-json-schema' commands to auto-generate client bindings rather than hand-coding JSON-RPC types. Teams have successfully built integrations in Go, Python, TypeScript, Swift, and Kotlin using these generated definitions.Many teams were able to quickly achieve a working integration by feeding the JSON schema and documentation directly to Codex itself for generating the client code.
6Consider using Codex as an MCP server (via 'codex mcp-server') if you already have an MCP-based workflow and need Codex as a callable tool, but be aware that Codex-specific interactions relying on richer session semantics like diff updates may not map cleanly through MCP endpoints.For the full agent experience including sign-in, model discovery, configuration management, and streaming events, the App Server protocol is the recommended approach over MCP.