codex-octopus 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +242 -0
- package/assets/codex-octopus.png +0 -0
- package/assets/codex-octopus.svg +48 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +47 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +86 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +54 -0
- package/dist/lib.d.ts +30 -0
- package/dist/lib.js +148 -0
- package/dist/tools/factory.d.ts +2 -0
- package/dist/tools/factory.js +110 -0
- package/dist/tools/query.d.ts +3 -0
- package/dist/tools/query.js +167 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +1 -0
- package/package.json +32 -0
- package/src/config.ts +67 -0
- package/src/constants.ts +88 -0
- package/src/index.ts +69 -0
- package/src/lib.test.ts +301 -0
- package/src/lib.ts +187 -0
- package/src/tools/factory.ts +153 -0
- package/src/tools/query.ts +200 -0
- package/src/types.ts +34 -0
- package/tsconfig.json +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xiaolai Li
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/xiaolai/codex-octopus/main/assets/codex-octopus.svg" alt="Codex Octopus" width="200" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# Codex Octopus
|
|
6
|
+
|
|
7
|
+
One brain, many arms.
|
|
8
|
+
|
|
9
|
+
An MCP server that wraps the [OpenAI Codex SDK](https://www.npmjs.com/package/@openai/codex-sdk), letting you run multiple specialized Codex agents — each with its own model, sandbox, effort, and personality — from any MCP client.
|
|
10
|
+
|
|
11
|
+
## Why
|
|
12
|
+
|
|
13
|
+
Codex is powerful. But one instance does everything the same way. Sometimes you want a **strict code reviewer** in read-only sandbox. A **test writer** with workspace-write access. A **cheap quick helper** on minimal effort. A **deep thinker** on xhigh.
|
|
14
|
+
|
|
15
|
+
Codex Octopus lets you spin up as many of these as you need. Same binary, different configurations. Each one shows up as a separate tool in your MCP client.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
- **Node.js** >= 18
|
|
20
|
+
- **Codex CLI** — the [Codex SDK](https://www.npmjs.com/package/@openai/codex-sdk) spawns the Codex CLI under the hood, so you need it installed (`@openai/codex`)
|
|
21
|
+
- **OpenAI API key** (`CODEX_API_KEY` env var) or inherited from parent process
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install codex-octopus
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or use `npx` directly in your `.mcp.json` (see Quick Start below).
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
Add to your `.mcp.json`:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"mcpServers": {
|
|
38
|
+
"codex": {
|
|
39
|
+
"command": "npx",
|
|
40
|
+
"args": ["codex-octopus"],
|
|
41
|
+
"env": {
|
|
42
|
+
"CODEX_SANDBOX_MODE": "workspace-write",
|
|
43
|
+
"CODEX_APPROVAL_POLICY": "never"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This gives you two tools: `codex` and `codex_reply`. That's it — you have Codex as a tool.
|
|
51
|
+
|
|
52
|
+
## Multiple Agents
|
|
53
|
+
|
|
54
|
+
The real power is running several instances with different configurations:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"code-reviewer": {
|
|
60
|
+
"command": "npx",
|
|
61
|
+
"args": ["codex-octopus"],
|
|
62
|
+
"env": {
|
|
63
|
+
"CODEX_TOOL_NAME": "code_reviewer",
|
|
64
|
+
"CODEX_SERVER_NAME": "code-reviewer",
|
|
65
|
+
"CODEX_DESCRIPTION": "Strict code reviewer. Read-only sandbox.",
|
|
66
|
+
"CODEX_MODEL": "o3",
|
|
67
|
+
"CODEX_SANDBOX_MODE": "read-only",
|
|
68
|
+
"CODEX_APPEND_INSTRUCTIONS": "You are a strict code reviewer. Report real bugs, not style preferences.",
|
|
69
|
+
"CODEX_EFFORT": "high"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"test-writer": {
|
|
73
|
+
"command": "npx",
|
|
74
|
+
"args": ["codex-octopus"],
|
|
75
|
+
"env": {
|
|
76
|
+
"CODEX_TOOL_NAME": "test_writer",
|
|
77
|
+
"CODEX_SERVER_NAME": "test-writer",
|
|
78
|
+
"CODEX_DESCRIPTION": "Writes thorough tests with edge case coverage.",
|
|
79
|
+
"CODEX_MODEL": "gpt-5-codex",
|
|
80
|
+
"CODEX_SANDBOX_MODE": "workspace-write",
|
|
81
|
+
"CODEX_APPEND_INSTRUCTIONS": "Write tests first. Cover edge cases. TDD."
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"quick-qa": {
|
|
85
|
+
"command": "npx",
|
|
86
|
+
"args": ["codex-octopus"],
|
|
87
|
+
"env": {
|
|
88
|
+
"CODEX_TOOL_NAME": "quick_qa",
|
|
89
|
+
"CODEX_SERVER_NAME": "quick-qa",
|
|
90
|
+
"CODEX_DESCRIPTION": "Fast answers to quick coding questions.",
|
|
91
|
+
"CODEX_EFFORT": "minimal"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Your MCP client now sees three distinct tools — `code_reviewer`, `test_writer`, `quick_qa` — each purpose-built.
|
|
99
|
+
|
|
100
|
+
## Agent Factory
|
|
101
|
+
|
|
102
|
+
Don't want to write configs by hand? Add a factory instance:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"mcpServers": {
|
|
107
|
+
"agent-factory": {
|
|
108
|
+
"command": "npx",
|
|
109
|
+
"args": ["codex-octopus"],
|
|
110
|
+
"env": {
|
|
111
|
+
"CODEX_FACTORY_ONLY": "true",
|
|
112
|
+
"CODEX_SERVER_NAME": "agent-factory"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This exposes a single `create_codex_mcp` tool — an interactive wizard. Tell it what you want ("a strict code reviewer with read-only sandbox") and it generates the `.mcp.json` entry for you.
|
|
120
|
+
|
|
121
|
+
## Tools
|
|
122
|
+
|
|
123
|
+
Each non-factory instance exposes:
|
|
124
|
+
|
|
125
|
+
| Tool | Purpose |
|
|
126
|
+
| -------------- | ------------------------------------------------------ |
|
|
127
|
+
| `<name>` | Send a task to the agent, get a response + `thread_id` |
|
|
128
|
+
| `<name>_reply` | Continue a previous conversation by `thread_id` |
|
|
129
|
+
|
|
130
|
+
Per-invocation parameters (override server defaults):
|
|
131
|
+
|
|
132
|
+
| Parameter | Description |
|
|
133
|
+
| ---------------- | -------------------------------------------------- |
|
|
134
|
+
| `prompt` | The task or question (required) |
|
|
135
|
+
| `cwd` | Working directory override |
|
|
136
|
+
| `model` | Model override |
|
|
137
|
+
| `additionalDirs` | Extra directories the agent can access |
|
|
138
|
+
| `effort` | Reasoning effort (`minimal` to `xhigh`) |
|
|
139
|
+
| `sandboxMode` | Sandbox override (can only tighten, never loosen) |
|
|
140
|
+
| `approvalPolicy` | Approval override (can only tighten, never loosen) |
|
|
141
|
+
| `networkAccess` | Enable network access from sandbox |
|
|
142
|
+
| `webSearchMode` | Web search: `disabled`, `cached`, `live` |
|
|
143
|
+
| `instructions` | Additional instructions (prepended to prompt) |
|
|
144
|
+
|
|
145
|
+
## Configuration
|
|
146
|
+
|
|
147
|
+
All configuration is via environment variables in `.mcp.json`. Every env var is optional.
|
|
148
|
+
|
|
149
|
+
### Identity
|
|
150
|
+
|
|
151
|
+
| Env Var | Description | Default |
|
|
152
|
+
| -------------------- | --------------------------------------------- | ---------------- |
|
|
153
|
+
| `CODEX_TOOL_NAME` | Tool name prefix (`<name>` and `<name>_reply`) | `codex` |
|
|
154
|
+
| `CODEX_DESCRIPTION` | Tool description shown to the host AI | generic |
|
|
155
|
+
| `CODEX_SERVER_NAME` | MCP server name in protocol handshake | `codex-octopus` |
|
|
156
|
+
| `CODEX_FACTORY_ONLY` | Only expose the factory wizard tool | `false` |
|
|
157
|
+
|
|
158
|
+
### Agent
|
|
159
|
+
|
|
160
|
+
| Env Var | Description | Default |
|
|
161
|
+
| -------------------------- | ----------------------------------------------------- | ------------- |
|
|
162
|
+
| `CODEX_MODEL` | Model (`gpt-5-codex`, `o3`, `codex-1`, etc.) | SDK default |
|
|
163
|
+
| `CODEX_CWD` | Working directory | `process.cwd()` |
|
|
164
|
+
| `CODEX_SANDBOX_MODE` | `read-only`, `workspace-write`, `danger-full-access` | `read-only` |
|
|
165
|
+
| `CODEX_APPROVAL_POLICY` | `never`, `on-failure`, `on-request`, `untrusted` | `on-failure` |
|
|
166
|
+
| `CODEX_EFFORT` | `minimal`, `low`, `medium`, `high`, `xhigh` | SDK default |
|
|
167
|
+
| `CODEX_ADDITIONAL_DIRS` | Extra directories (comma-separated) | none |
|
|
168
|
+
| `CODEX_NETWORK_ACCESS` | Allow network from sandbox | `false` |
|
|
169
|
+
| `CODEX_WEB_SEARCH` | `disabled`, `cached`, `live` | `disabled` |
|
|
170
|
+
|
|
171
|
+
### Instructions
|
|
172
|
+
|
|
173
|
+
| Env Var | Description |
|
|
174
|
+
| ---------------------------- | -------------------------------------------------------- |
|
|
175
|
+
| `CODEX_INSTRUCTIONS` | Replaces the default instructions |
|
|
176
|
+
| `CODEX_APPEND_INSTRUCTIONS` | Appended to the default (usually what you want) |
|
|
177
|
+
|
|
178
|
+
### Advanced
|
|
179
|
+
|
|
180
|
+
| Env Var | Description |
|
|
181
|
+
| ---------------------- | -------------------------------------------------------- |
|
|
182
|
+
| `CODEX_PERSIST_SESSION`| `true`/`false` — enable session resume (default: `true`) |
|
|
183
|
+
|
|
184
|
+
### Authentication
|
|
185
|
+
|
|
186
|
+
| Env Var | Description | Default |
|
|
187
|
+
| --------------- | ------------------------------ | --------------------- |
|
|
188
|
+
| `CODEX_API_KEY` | OpenAI API key for this agent | inherited from parent |
|
|
189
|
+
|
|
190
|
+
## Security
|
|
191
|
+
|
|
192
|
+
- **Sandbox defaults to `read-only`** — the agent can't write files unless you explicitly set `workspace-write` or `danger-full-access`.
|
|
193
|
+
- **`cwd` overrides preserve agent knowledge** — when the host overrides `cwd`, the agent's configured base directory is automatically added to `additionalDirectories`.
|
|
194
|
+
- **Security overrides narrow, never widen** — per-invocation `sandboxMode` and `approvalPolicy` can only tighten (e.g., `workspace-write` → `read-only`), never loosen.
|
|
195
|
+
- **`_reply` tool respects persistence** — not registered when `CODEX_PERSIST_SESSION=false`.
|
|
196
|
+
- **API keys are redacted** — the factory wizard never exposes `CODEX_API_KEY` in generated configs.
|
|
197
|
+
|
|
198
|
+
## Architecture
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
┌─────────────────────────────────┐
|
|
202
|
+
│ MCP Client │
|
|
203
|
+
│ (Claude Desktop, Cursor, etc.) │
|
|
204
|
+
│ │
|
|
205
|
+
│ Sees: code_reviewer, │
|
|
206
|
+
│ test_writer, quick_qa │
|
|
207
|
+
└──────────┬──────────────────────┘
|
|
208
|
+
│ JSON-RPC / stdio
|
|
209
|
+
┌──────────▼──────────────────────┐
|
|
210
|
+
│ Codex Octopus (per instance) │
|
|
211
|
+
│ │
|
|
212
|
+
│ Env: CODEX_MODEL=o3 │
|
|
213
|
+
│ CODEX_SANDBOX_MODE=... │
|
|
214
|
+
│ CODEX_APPEND_INSTRUCTIONS │
|
|
215
|
+
│ │
|
|
216
|
+
│ Calls: Codex SDK thread.run() │
|
|
217
|
+
└──────────┬──────────────────────┘
|
|
218
|
+
│ in-process
|
|
219
|
+
┌──────────▼──────────────────────┐
|
|
220
|
+
│ Codex SDK → Codex CLI │
|
|
221
|
+
│ Runs autonomously: reads files,│
|
|
222
|
+
│ writes code, runs commands │
|
|
223
|
+
│ Returns result + thread_id │
|
|
224
|
+
└─────────────────────────────────┘
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Known Limitations
|
|
228
|
+
|
|
229
|
+
- **`minimal` effort + web_search**: OpenAI does not allow `web_search` tools with `minimal` reasoning effort. Use `low` or higher if web search is needed.
|
|
230
|
+
|
|
231
|
+
## Development
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
pnpm install
|
|
235
|
+
pnpm build # compile TypeScript
|
|
236
|
+
pnpm test # run tests (vitest)
|
|
237
|
+
pnpm test:coverage # coverage report
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
[ISC](https://github.com/xiaolai/codex-octopus/blob/main/LICENSE) - Xiaolai Li
|
|
Binary file
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32" shape-rendering="crispEdges">
|
|
2
|
+
<rect x="7" y="6" width="18" height="1" fill="#606060"/>
|
|
3
|
+
<rect x="7" y="7" width="18" height="1" fill="#606060"/>
|
|
4
|
+
<rect x="7" y="8" width="18" height="1" fill="#606060"/>
|
|
5
|
+
<rect x="7" y="9" width="18" height="1" fill="#606060"/>
|
|
6
|
+
<rect x="7" y="10" width="4" height="1" fill="#606060"/>
|
|
7
|
+
<rect x="13" y="10" width="6" height="1" fill="#606060"/>
|
|
8
|
+
<rect x="21" y="10" width="4" height="1" fill="#606060"/>
|
|
9
|
+
<rect x="7" y="11" width="4" height="1" fill="#606060"/>
|
|
10
|
+
<rect x="13" y="11" width="6" height="1" fill="#606060"/>
|
|
11
|
+
<rect x="21" y="11" width="4" height="1" fill="#606060"/>
|
|
12
|
+
<rect x="5" y="12" width="22" height="1" fill="#606060"/>
|
|
13
|
+
<rect x="5" y="13" width="22" height="1" fill="#606060"/>
|
|
14
|
+
<rect x="3" y="14" width="26" height="1" fill="#606060"/>
|
|
15
|
+
<rect x="3" y="15" width="26" height="1" fill="#606060"/>
|
|
16
|
+
<rect x="3" y="16" width="26" height="1" fill="#606060"/>
|
|
17
|
+
<rect x="3" y="17" width="26" height="1" fill="#606060"/>
|
|
18
|
+
<rect x="3" y="18" width="22" height="1" fill="#606060"/>
|
|
19
|
+
<rect x="27" y="18" width="2" height="1" fill="#606060"/>
|
|
20
|
+
<rect x="3" y="19" width="22" height="1" fill="#606060"/>
|
|
21
|
+
<rect x="27" y="19" width="2" height="1" fill="#606060"/>
|
|
22
|
+
<rect x="3" y="20" width="2" height="1" fill="#606060"/>
|
|
23
|
+
<rect x="7" y="20" width="18" height="1" fill="#606060"/>
|
|
24
|
+
<rect x="27" y="20" width="2" height="1" fill="#606060"/>
|
|
25
|
+
<rect x="3" y="21" width="2" height="1" fill="#606060"/>
|
|
26
|
+
<rect x="7" y="21" width="18" height="1" fill="#606060"/>
|
|
27
|
+
<rect x="27" y="21" width="2" height="1" fill="#606060"/>
|
|
28
|
+
<rect x="7" y="22" width="2" height="1" fill="#606060"/>
|
|
29
|
+
<rect x="11" y="22" width="2" height="1" fill="#606060"/>
|
|
30
|
+
<rect x="15" y="22" width="2" height="1" fill="#606060"/>
|
|
31
|
+
<rect x="19" y="22" width="2" height="1" fill="#606060"/>
|
|
32
|
+
<rect x="23" y="22" width="2" height="1" fill="#606060"/>
|
|
33
|
+
<rect x="7" y="23" width="2" height="1" fill="#606060"/>
|
|
34
|
+
<rect x="11" y="23" width="2" height="1" fill="#606060"/>
|
|
35
|
+
<rect x="15" y="23" width="2" height="1" fill="#606060"/>
|
|
36
|
+
<rect x="19" y="23" width="2" height="1" fill="#606060"/>
|
|
37
|
+
<rect x="23" y="23" width="2" height="1" fill="#606060"/>
|
|
38
|
+
<rect x="7" y="24" width="2" height="1" fill="#606060"/>
|
|
39
|
+
<rect x="11" y="24" width="2" height="1" fill="#606060"/>
|
|
40
|
+
<rect x="15" y="24" width="2" height="1" fill="#606060"/>
|
|
41
|
+
<rect x="19" y="24" width="2" height="1" fill="#606060"/>
|
|
42
|
+
<rect x="23" y="24" width="2" height="1" fill="#606060"/>
|
|
43
|
+
<rect x="7" y="25" width="2" height="1" fill="#606060"/>
|
|
44
|
+
<rect x="11" y="25" width="2" height="1" fill="#606060"/>
|
|
45
|
+
<rect x="15" y="25" width="2" height="1" fill="#606060"/>
|
|
46
|
+
<rect x="19" y="25" width="2" height="1" fill="#606060"/>
|
|
47
|
+
<rect x="23" y="25" width="2" height="1" fill="#606060"/>
|
|
48
|
+
</svg>
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { envStr, envList, envBool, validateSandboxMode, validateApprovalPolicy, validateEffort, } from "./lib.js";
|
|
2
|
+
export function buildBaseConfig() {
|
|
3
|
+
const config = {
|
|
4
|
+
cwd: envStr("CODEX_CWD") || process.cwd(),
|
|
5
|
+
persistSession: envBool("CODEX_PERSIST_SESSION", true),
|
|
6
|
+
};
|
|
7
|
+
const model = envStr("CODEX_MODEL");
|
|
8
|
+
if (model)
|
|
9
|
+
config.model = model;
|
|
10
|
+
const rawSandbox = envStr("CODEX_SANDBOX_MODE") || "read-only";
|
|
11
|
+
const sandbox = validateSandboxMode(rawSandbox);
|
|
12
|
+
if (rawSandbox !== sandbox) {
|
|
13
|
+
console.error(`codex-octopus: invalid CODEX_SANDBOX_MODE "${rawSandbox}", using "read-only"`);
|
|
14
|
+
}
|
|
15
|
+
config.sandboxMode = sandbox;
|
|
16
|
+
const rawApproval = envStr("CODEX_APPROVAL_POLICY") || "on-failure";
|
|
17
|
+
const approval = validateApprovalPolicy(rawApproval);
|
|
18
|
+
if (rawApproval !== approval) {
|
|
19
|
+
console.error(`codex-octopus: invalid CODEX_APPROVAL_POLICY "${rawApproval}", using "on-failure"`);
|
|
20
|
+
}
|
|
21
|
+
config.approvalPolicy = approval;
|
|
22
|
+
const effort = envStr("CODEX_EFFORT");
|
|
23
|
+
if (effort) {
|
|
24
|
+
const validated = validateEffort(effort);
|
|
25
|
+
if (effort !== validated) {
|
|
26
|
+
console.error(`codex-octopus: invalid CODEX_EFFORT "${effort}", using "medium"`);
|
|
27
|
+
}
|
|
28
|
+
config.effort = validated;
|
|
29
|
+
}
|
|
30
|
+
const dirs = envList("CODEX_ADDITIONAL_DIRS");
|
|
31
|
+
if (dirs)
|
|
32
|
+
config.additionalDirectories = dirs;
|
|
33
|
+
const networkAccess = envStr("CODEX_NETWORK_ACCESS");
|
|
34
|
+
if (networkAccess !== undefined) {
|
|
35
|
+
config.networkAccess = networkAccess === "true" || networkAccess === "1";
|
|
36
|
+
}
|
|
37
|
+
const webSearch = envStr("CODEX_WEB_SEARCH");
|
|
38
|
+
if (webSearch)
|
|
39
|
+
config.webSearchMode = webSearch;
|
|
40
|
+
const instructions = envStr("CODEX_INSTRUCTIONS");
|
|
41
|
+
if (instructions)
|
|
42
|
+
config.instructions = instructions;
|
|
43
|
+
const appendInstructions = envStr("CODEX_APPEND_INSTRUCTIONS");
|
|
44
|
+
if (appendInstructions)
|
|
45
|
+
config.appendInstructions = appendInstructions;
|
|
46
|
+
return config;
|
|
47
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export const OPTION_CATALOG = [
|
|
2
|
+
{
|
|
3
|
+
key: "model",
|
|
4
|
+
envVar: "CODEX_MODEL",
|
|
5
|
+
label: "Model",
|
|
6
|
+
hint: "Which model to use",
|
|
7
|
+
example: '"gpt-5-codex", "o3", "codex-1"',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
key: "appendInstructions",
|
|
11
|
+
envVar: "CODEX_APPEND_INSTRUCTIONS",
|
|
12
|
+
label: "Behavior instructions",
|
|
13
|
+
hint: "Instructions appended to the default system prompt",
|
|
14
|
+
example: '"Always explain your reasoning step by step."',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: "instructions",
|
|
18
|
+
envVar: "CODEX_INSTRUCTIONS",
|
|
19
|
+
label: "Full instructions",
|
|
20
|
+
hint: "Completely replaces the default instructions",
|
|
21
|
+
example: '"You are a security auditor..."',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: "sandboxMode",
|
|
25
|
+
envVar: "CODEX_SANDBOX_MODE",
|
|
26
|
+
label: "Sandbox mode",
|
|
27
|
+
hint: "How file system access is restricted",
|
|
28
|
+
example: '"read-only", "workspace-write", "danger-full-access"',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: "approvalPolicy",
|
|
32
|
+
envVar: "CODEX_APPROVAL_POLICY",
|
|
33
|
+
label: "Approval policy",
|
|
34
|
+
hint: "When to prompt for command approval",
|
|
35
|
+
example: '"never" (auto-approve), "on-failure", "on-request", "untrusted"',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "cwd",
|
|
39
|
+
envVar: "CODEX_CWD",
|
|
40
|
+
label: "Working directory",
|
|
41
|
+
hint: "Default directory the agent operates in",
|
|
42
|
+
example: '"/home/user/project"',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "additionalDirs",
|
|
46
|
+
envVar: "CODEX_ADDITIONAL_DIRS",
|
|
47
|
+
label: "Additional directories",
|
|
48
|
+
hint: "Extra directories the agent can access (comma-separated)",
|
|
49
|
+
example: '"/shared/libs,/data"',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "effort",
|
|
53
|
+
envVar: "CODEX_EFFORT",
|
|
54
|
+
label: "Reasoning effort",
|
|
55
|
+
hint: "How hard the agent thinks",
|
|
56
|
+
example: '"minimal" (fastest), "low", "medium", "high", "xhigh" (deepest)',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "networkAccess",
|
|
60
|
+
envVar: "CODEX_NETWORK_ACCESS",
|
|
61
|
+
label: "Network access",
|
|
62
|
+
hint: "Allow network access from sandbox",
|
|
63
|
+
example: '"true" or "false" (default)',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: "webSearchMode",
|
|
67
|
+
envVar: "CODEX_WEB_SEARCH",
|
|
68
|
+
label: "Web search",
|
|
69
|
+
hint: "Web search mode",
|
|
70
|
+
example: '"disabled" (default), "cached", "live"',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "persistSession",
|
|
74
|
+
envVar: "CODEX_PERSIST_SESSION",
|
|
75
|
+
label: "Persist sessions",
|
|
76
|
+
hint: "Save sessions for later resume via _reply tool",
|
|
77
|
+
example: '"true" (default) or "false"',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "apiKey",
|
|
81
|
+
envVar: "CODEX_API_KEY",
|
|
82
|
+
label: "API key",
|
|
83
|
+
hint: "OpenAI API key for this agent (overrides inherited auth)",
|
|
84
|
+
example: '"sk-..." — leave unset to inherit from parent',
|
|
85
|
+
},
|
|
86
|
+
];
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Codex Octopus — one brain, many arms.
|
|
4
|
+
*
|
|
5
|
+
* Wraps the OpenAI Codex SDK as MCP servers, letting you spawn multiple
|
|
6
|
+
* specialized Codex agents — each with its own model, sandbox, effort,
|
|
7
|
+
* and personality.
|
|
8
|
+
*/
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import { envStr, envBool, sanitizeToolName } from "./lib.js";
|
|
13
|
+
import { buildBaseConfig } from "./config.js";
|
|
14
|
+
import { registerQueryTools } from "./tools/query.js";
|
|
15
|
+
import { registerFactoryTool } from "./tools/factory.js";
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
const { version: PKG_VERSION } = require("../package.json");
|
|
18
|
+
// ── Configuration ──────────────────────────────────────────────────
|
|
19
|
+
const BASE_CONFIG = buildBaseConfig();
|
|
20
|
+
const API_KEY = envStr("CODEX_API_KEY");
|
|
21
|
+
const TOOL_NAME = sanitizeToolName(envStr("CODEX_TOOL_NAME") || "codex");
|
|
22
|
+
const REPLY_TOOL_NAME = `${TOOL_NAME}_reply`;
|
|
23
|
+
const SERVER_NAME = envStr("CODEX_SERVER_NAME") || "codex-octopus";
|
|
24
|
+
const FACTORY_ONLY = envBool("CODEX_FACTORY_ONLY", false);
|
|
25
|
+
const DEFAULT_DESCRIPTION = [
|
|
26
|
+
"Send a task to an autonomous Codex agent.",
|
|
27
|
+
"It reads/writes files, runs shell commands, searches codebases,",
|
|
28
|
+
"and handles complex software engineering tasks end-to-end.",
|
|
29
|
+
`Returns the result text plus a thread_id for follow-ups via ${REPLY_TOOL_NAME}.`,
|
|
30
|
+
].join(" ");
|
|
31
|
+
const TOOL_DESCRIPTION = envStr("CODEX_DESCRIPTION") || DEFAULT_DESCRIPTION;
|
|
32
|
+
// ── Server ─────────────────────────────────────────────────────────
|
|
33
|
+
const server = new McpServer({ name: SERVER_NAME, version: PKG_VERSION });
|
|
34
|
+
if (!FACTORY_ONLY) {
|
|
35
|
+
registerQueryTools(server, BASE_CONFIG, TOOL_NAME, TOOL_DESCRIPTION, API_KEY);
|
|
36
|
+
}
|
|
37
|
+
if (FACTORY_ONLY) {
|
|
38
|
+
registerFactoryTool(server);
|
|
39
|
+
}
|
|
40
|
+
// ── Start ──────────────────────────────────────────────────────────
|
|
41
|
+
async function main() {
|
|
42
|
+
const transport = new StdioServerTransport();
|
|
43
|
+
await server.connect(transport);
|
|
44
|
+
const toolList = FACTORY_ONLY
|
|
45
|
+
? ["create_codex_mcp"]
|
|
46
|
+
: BASE_CONFIG.persistSession !== false
|
|
47
|
+
? [TOOL_NAME, REPLY_TOOL_NAME]
|
|
48
|
+
: [TOOL_NAME];
|
|
49
|
+
console.error(`${SERVER_NAME}: running on stdio (tools: ${toolList.join(", ")})`);
|
|
50
|
+
}
|
|
51
|
+
main().catch((error) => {
|
|
52
|
+
console.error(`${SERVER_NAME}: fatal:`, error);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
});
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, testable logic extracted from index.ts.
|
|
3
|
+
*/
|
|
4
|
+
export declare function envStr(key: string, env?: Record<string, string | undefined>): string | undefined;
|
|
5
|
+
export declare function envList(key: string, env?: Record<string, string | undefined>): string[] | undefined;
|
|
6
|
+
export declare function envNum(key: string, env?: Record<string, string | undefined>): number | undefined;
|
|
7
|
+
export declare function envBool(key: string, fallback: boolean, env?: Record<string, string | undefined>): boolean;
|
|
8
|
+
export declare const MAX_TOOL_NAME_LEN: number;
|
|
9
|
+
export declare function sanitizeToolName(raw: string): string;
|
|
10
|
+
export declare function isDescendantPath(requested: string, baseCwd: string): boolean;
|
|
11
|
+
export declare const VALID_SANDBOX_MODES: Set<string>;
|
|
12
|
+
export declare function validateSandboxMode(mode: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Narrow sandbox mode: returns the stricter of base and override.
|
|
15
|
+
* Callers can tighten but never loosen.
|
|
16
|
+
*/
|
|
17
|
+
export declare function narrowSandboxMode(base: string, override: string): string;
|
|
18
|
+
export declare const VALID_APPROVAL_POLICIES: Set<string>;
|
|
19
|
+
export declare function validateApprovalPolicy(policy: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Narrow approval policy: returns the stricter of base and override.
|
|
22
|
+
* Callers can tighten but never loosen.
|
|
23
|
+
*/
|
|
24
|
+
export declare function narrowApprovalPolicy(base: string, override: string): string;
|
|
25
|
+
export declare const VALID_EFFORTS: Set<string>;
|
|
26
|
+
export declare function validateEffort(effort: string): string;
|
|
27
|
+
export declare function deriveServerName(description: string): string;
|
|
28
|
+
export declare function deriveToolName(name: string): string;
|
|
29
|
+
export declare function serializeArrayEnv(val: unknown[]): string;
|
|
30
|
+
export declare function formatErrorMessage(error: unknown): string;
|