Compare commits

..

2 Commits

Author SHA1 Message Date
Thibault Sottiaux
e4a6b36fba Update install.md 2025-10-20 16:25:16 -07:00
Thibault Sottiaux
15472114b1 docs: refresh install guidance 2025-10-20 14:52:06 -07:00
2 changed files with 79 additions and 17 deletions

View File

@@ -8,7 +8,28 @@ This document describes Codexs experimental MCP server interface: a JSONRP
## Overview
Codex now surfaces its functionality through standard MCP `tools/call` requests. A `tools/list` request returns the `codex` tool, which starts a session, and the `codex-reply` tool, which continues an existing session. The JSON schemas backing both tools are generated in `codex-rs/mcp-server/src/codex_tool_config.rs`. Codex continues to reuse the shared event types defined in `codex-rs/protocol/src/protocol.rs`. For clients that still speak the legacy JSONRPC API, its protocol definitions live in `codex-rs/app-server-protocol/src/protocol.rs`.
Codex exposes a small set of MCPcompatible methods to create and manage conversations, send user input, receive live events, and handle approval prompts. The types are defined in `protocol/src/mcp_protocol.rs` and reused by the MCP server implementation in `mcp-server/`.
At a glance:
- Conversations
- `newConversation` → start a Codex session
- `sendUserMessage` / `sendUserTurn` → send user input into a conversation
- `interruptConversation` → stop the current turn
- `listConversations`, `resumeConversation`, `archiveConversation`
- Configuration and info
- `getUserSavedConfig`, `setDefaultModel`, `getUserAgent`, `userInfo`
- Auth
- `loginApiKey`, `loginChatGpt`, `cancelLoginChatGpt`, `logoutChatGpt`, `getAuthStatus`
- Utilities
- `gitDiffToRemote`, `execOneOffCommand`
- Approvals (server → client requests)
- `applyPatchApproval`, `execCommandApproval`
- Notifications (server → client)
- `loginChatGptComplete`, `authStatusChange`
- `codex/event` stream with agent events
See code for full type definitions and exact shapes: `protocol/src/mcp_protocol.rs`.
## Starting the server
@@ -26,39 +47,78 @@ npx @modelcontextprotocol/inspector codex mcp-server
Use the separate `codex mcp` subcommand to manage configured MCP server launchers in `config.toml`.
## Codex tools
## Conversations
Send `tools/list` to discover the available tools:
Start a new session with optional overrides:
- `codex`: starts a new Codex session. The request `arguments` accept the fields surfaced by `CodexToolCallParam`, including the required `prompt` plus optional `model`, `profile`, `cwd`, `approval-policy`, `sandbox`, `config`, `base-instructions`, and `include-plan-tool` overrides. When the tool call finishes, the server resolves the `tools/call` request with the models final message in the response `content`.
- `codex-reply`: continues an existing session. The request `arguments` must include `conversationId` and `prompt`, matching the `CodexToolCallReplyParam` schema. Use the `conversationId` returned in earlier events to correlate with the active session.
Request `newConversation` params (subset):
Both tools run asynchronously. While a tool call is in flight, Codex streams progress via MCP notifications so the client can render intermediate output or handle approvals.
- `model`: string model id (e.g. "o3", "gpt-5", "gpt-5-codex")
- `profile`: optional named profile
- `cwd`: optional working directory
- `approvalPolicy`: `untrusted` | `on-request` | `on-failure` | `never`
- `sandbox`: `read-only` | `workspace-write` | `danger-full-access`
- `config`: map of additional config overrides
- `baseInstructions`: optional instruction override
- `includePlanTool` / `includeApplyPatchTool`: booleans
Response: `{ conversationId, model, reasoningEffort?, rolloutPath }`
Send input to the active turn:
- `sendUserMessage` → enqueue items to the conversation
- `sendUserTurn` → structured turn with explicit `cwd`, `approvalPolicy`, `sandboxPolicy`, `model`, optional `effort`, and `summary`
Interrupt a running turn: `interruptConversation`.
List/resume/archive: `listConversations`, `resumeConversation`, `archiveConversation`.
## Event stream
While a conversation runs, the server sends JSONRPC notifications whose `method` is `codex/event`. The payload embeds the serialized `Event`/`EventMsg` structures from `codex-rs/protocol/src/protocol.rs`. Notifications include `_meta.requestId` so clients can associate each event with the originating `tools/call`.
While a conversation runs, the server sends notifications:
- `codex/event` with the serialized Codex event payload. The shape matches `core/src/protocol.rs`s `Event` and `EventMsg` types. Some notifications include a `_meta.requestId` to correlate with the originating request.
- Auth notifications via method names `loginChatGptComplete` and `authStatusChange`.
Clients should render events and, when present, surface approval requests (see next section).
## Approvals (server → client)
When Codex needs approval to apply a patch or run a command, it issues an MCP elicitation request (`ElicitRequest`). Patch prompts carry `PatchApprovalElicitRequestParams` and command prompts use `ExecApprovalElicitRequestParams`. Respond with JSON that includes a `decision` field whose value is one of the `ReviewDecision` strings: `approved`, `approved_for_session`, `denied`, or `abort`. These map directly to the enum defined in `codex-rs/protocol/src/protocol.rs` and determine whether Codex proceeds, autoapproves similar actions for the current session, or halts work.
When Codex needs approval to apply changes or run commands, the server issues JSONRPC requests to the client:
## Example workflow
- `applyPatchApproval { conversationId, callId, fileChanges, reason?, grantRoot? }`
- `execCommandApproval { conversationId, callId, command, cwd, reason? }`
Start a session with the `codex` tool:
The client must reply with `{ decision: "allow" | "deny" }` for each request.
## Auth helpers
For ChatGPT or APIkey based auth flows, the server exposes helpers:
- `loginApiKey { apiKey }`
- `loginChatGpt` → returns `{ loginId, authUrl }`; browser completes flow; then `loginChatGptComplete` notification follows
- `cancelLoginChatGpt { loginId }`, `logoutChatGpt`, `getAuthStatus { includeToken?, refreshToken? }`
## Example: start and send a message
```json
{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "codex", "arguments": { "prompt": "List the files in this repo.", "approval-policy": "on-request", "sandbox": "workspace-write" } } }
{ "jsonrpc": "2.0", "id": 1, "method": "newConversation", "params": { "model": "gpt-5", "approvalPolicy": "on-request" } }
```
The server streams `codex/event` notifications as the session runs. When the task completes, the `tools/call` response resolves with the final assistant message in its `content`. To keep going, call `codex-reply` with the returned `conversationId`:
Server responds:
```json
{ "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "codex-reply", "arguments": { "conversationId": "c7b0…", "prompt": "Great, please open README.md." } } }
{ "jsonrpc": "2.0", "id": 1, "result": { "conversationId": "c7b0…", "model": "gpt-5", "rolloutPath": "/path/to/rollout.jsonl" } }
```
Any approval prompts during either call arrive as elicitation requests. Reply with the desired `ReviewDecision` to allow, deny, or pause execution.
Then send input:
```json
{ "jsonrpc": "2.0", "id": 2, "method": "sendUserMessage", "params": { "conversationId": "c7b0…", "items": [{ "type": "text", "text": "Hello Codex" }] } }
```
While processing, the server emits `codex/event` notifications containing agent output, approvals, and status updates.
## Compatibility and stability
This interface is experimental. Tool schemas, fields, and event shapes may evolve. For the authoritative definitions, consult `codex-rs/mcp-server/src/codex_tool_config.rs`, the shared event types in `codex-rs/protocol/src/protocol.rs`, and the legacy JSONRPC spec in `codex-rs/app-server-protocol/src/protocol.rs`.
This interface is experimental. Method names, fields, and event shapes may evolve. For the authoritative schema, consult `protocol/src/mcp_protocol.rs` and the corresponding server wiring in `mcp-server/`.

View File

@@ -4,7 +4,7 @@
| Requirement | Details |
| --------------------------- | --------------------------------------------------------------- |
| Operating systems | macOS 12+, Ubuntu 20.04+/Debian 10+, or Windows 11 **via WSL2** |
| Operating systems | macOS 12+, Ubuntu 20.04+/Debian 10+, or Windows 11 (native or via WSL2) |
| Git (optional, recommended) | 2.23+ for built-in PR helpers |
| RAM | 4-GB minimum (8-GB recommended) |
@@ -33,8 +33,10 @@ cargo run --bin codex -- "explain this codebase to me"
# After making changes, ensure the code is clean.
cargo fmt -- --config imports_granularity=Item
cargo clippy --tests
cargo clippy --all-features --tests
# or use `just clippy`
# Run the tests.
cargo test
# or use `just test`
```