Skip to main content
Glama
codex-appserver-mcp

codex-appserver-mcp

by azjhf-dev
README.md
# codex-appserver-mcp

A small MCP stdio server that lets an MCP client (for example the Antigravity app) hand tasks to Codex through `codex app-server`. Zero dependencies, Node 20+.

**Status: prototype. Tested only against a mock app-server written from the public docs, not against a real `codex` CLI or a real Antigravity.** The mock mirrors https://learn.chatgpt.com/docs/app-server; field names for approval replies (`{decision}`) and `thread/start` options are from that doc and unverified against a real binary.

`codex mcp-server` was removed in Codex (deprecated 2026-08-24, removed 2026-09-05), so this talks to `codex app-server` instead (JSON-RPC 2.0, one JSON message per line).

## What it does

One MCP tool, `codex_run`:

| arg | meaning |
|---|---|
| `prompt` | task for Codex (required) |
| `threadId` | continue an earlier thread (returned in each result) |
| `cwd`, `model`, `effort` | passed through |
| `sandbox` | new threads only: `read-only` (default), `workspace-write`, `danger-full-access` |

Flow: `initialize` (experimental API on) then `thread/start` or `thread/resume`, `turn/start`, then it collects `item/agentMessage/delta`, `item/completed` and `turn/completed`, and returns the final answer, thread id, commands run, changed files. MCP progress notifications are sent if the client supplies a progress token. A turn that gets no result in 10 minutes is interrupted.

## Safety defaults

- Sandbox `read-only`, approval policy `on-request`.
- Command and file-change approval requests from Codex are **declined**, and the result says how many. Set `CODEX_MCP_AUTO_APPROVE=1` to accept them (only with a sandbox you trust).
- Codex uses its own login (`codex login`) or API key. This server never reads or stores credentials. Using a ChatGPT subscription login this way is the same as using the CLI yourself; check OpenAI's current terms if you share it.

## Dynamic tools (Codex calls back into your machine)

Set `CODEX_MCP_DYNAMIC_TOOLS` to a JSON array. Each entry is registered on new threads as a Codex dynamic tool; when Codex calls it, this server runs `command` with the JSON arguments on stdin and returns stdout.

```json
[{"name":"lookup_ticket","description":"Fetch a ticket","inputSchema":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"]},"command":["python3","/path/lookup.py"]}]
```

This is command-backed only. It does not forward calls to the MCP client's own tools (MCP has no way for a server to call a client's tools).

## Install and use

```
git clone https://github.com/azjhf-dev/codex-appserver-mcp && cd codex-appserver-mcp
npm test
```

MCP config (Antigravity: Customizations > MCP Servers; or any MCP client):

```json
{ "mcpServers": { "codex": { "command": "node", "args": ["/abs/path/codex-appserver-mcp/src/server.mjs"] } } }
```

Env: `CODEX_BIN` (default `codex`), `CODEX_MCP_COMMAND` (full argv, default `codex app-server`), `CODEX_MCP_MODEL`, `CODEX_MCP_SANDBOX`, `CODEX_MCP_APPROVAL`, `CODEX_MCP_CWD`, `CODEX_MCP_AUTO_APPROVE`, `CODEX_MCP_DYNAMIC_TOOLS`.

## Known gaps

- Not run against real Codex. First thing to do: run it against `codex app-server` and check `thread/start` accepts the params.
- One tool, no thread listing or interrupt tool yet (the bridge has `interrupt`).
- Stdio only, no remote or WebSocket app-server.
- Notifications are matched by `threadId`; if the real server omits it on some events they are dropped unless only one run is active.

MIT.