codex-mcp-server 1.0.0__tar.gz
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.
- codex_mcp_server-1.0.0/.gitignore +3 -0
- codex_mcp_server-1.0.0/LICENSE +21 -0
- codex_mcp_server-1.0.0/PKG-INFO +238 -0
- codex_mcp_server-1.0.0/README.md +218 -0
- codex_mcp_server-1.0.0/pyproject.toml +39 -0
- codex_mcp_server-1.0.0/src/codexmcp/__init__.py +4 -0
- codex_mcp_server-1.0.0/src/codexmcp/cli.py +12 -0
- codex_mcp_server-1.0.0/src/codexmcp/command_builder.py +43 -0
- codex_mcp_server-1.0.0/src/codexmcp/models.py +80 -0
- codex_mcp_server-1.0.0/src/codexmcp/server.py +252 -0
- codex_mcp_server-1.0.0/src/codexmcp/stream_processor.py +139 -0
- codex_mcp_server-1.0.0/src/codexmcp/task_manager.py +422 -0
- codex_mcp_server-1.0.0/src/codexmcp/tmux.py +86 -0
- codex_mcp_server-1.0.0/src/codexmcp/worktree.py +178 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 guda.studio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codex-mcp-server
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: MCP server for Codex CLI with tmux persistence, git worktree isolation, and async dispatch.
|
|
5
|
+
Project-URL: Homepage, https://github.com/GuDaStudio/codexmcp
|
|
6
|
+
Project-URL: Repository, https://github.com/GuDaStudio/codexmcp
|
|
7
|
+
Author-email: "guda.studio" <gudaclaude@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai-agent,codex,fastmcp,mcp,tmux,worktree
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Requires-Dist: mcp[cli]>=1.20.0
|
|
18
|
+
Requires-Dist: pydantic>=2.0
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
<div align="center">
|
|
22
|
+
|
|
23
|
+
# codex-mcp-server
|
|
24
|
+
|
|
25
|
+
MCP server for Codex CLI — tmux persistence, git worktree isolation, async dispatch.
|
|
26
|
+
|
|
27
|
+
[English](./docs/README_EN.md) | 简体中文
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 特性
|
|
34
|
+
|
|
35
|
+
- **tmux 持久化** — 所有任务运行在 tmux session 中,网络断开、窗口关闭后任务继续执行
|
|
36
|
+
- **git worktree 隔离** — `full-access` 模式自动创建独立 worktree,并行任务互不干扰
|
|
37
|
+
- **阻塞 + 异步双模式** — `codex` 同步等待结果,`codex_dispatch` 立即返回后台运行
|
|
38
|
+
- **多轮对话 (resume)** — 通过 `session_id` 延续上一次 Codex 会话
|
|
39
|
+
- **文件系统持久化** — 任务元数据存储在 `~/.codexmcp/tasks/`,服务重启后可恢复
|
|
40
|
+
- **工作区日志** — 自动在 `<cwd>/.codex-tasks/` 创建 symlink,IDE 中直接查看日志
|
|
41
|
+
|
|
42
|
+
## 工具
|
|
43
|
+
|
|
44
|
+
| 工具 | 作用 | 适合场景 |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| `codex` | 阻塞执行,等待完成后返回结果 | 代码审阅、短任务、并行模块实现 |
|
|
47
|
+
| `codex_dispatch` | 后台分派,立即返回 task_id | 长任务(数十分钟到数小时) |
|
|
48
|
+
| `codex_status` | 查询任务状态和进度 | 追踪后台任务、获取结果 |
|
|
49
|
+
| `codex_cancel` | 取消运行中的任务 | 终止不需要的任务 |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 前置要求
|
|
54
|
+
|
|
55
|
+
- Python `3.12+`
|
|
56
|
+
- `codex` CLI 已安装且在 PATH 中
|
|
57
|
+
- `tmux` 已安装(所有模式必须)
|
|
58
|
+
- `git` 已安装(`full-access` 模式必须)
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
codex --version
|
|
62
|
+
tmux -V
|
|
63
|
+
git --version
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 安装
|
|
69
|
+
|
|
70
|
+
### Claude Code
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
claude mcp add codex -s user --transport stdio -- \
|
|
74
|
+
uvx codex-mcp-server
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
验证:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
claude mcp list
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Cursor / 通用 MCP 配置
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"command": "uvx",
|
|
88
|
+
"args": ["codex-mcp-server"]
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 从 GitHub 源码安装(开发用)
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pip install git+https://github.com/GuDaStudio/codexmcp.git
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 快速上手
|
|
101
|
+
|
|
102
|
+
### 1. 代码审阅(阻塞,只读)
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"tool": "codex",
|
|
107
|
+
"arguments": {
|
|
108
|
+
"prompt": "审阅 src/auth/ 目录的代码质量和安全性",
|
|
109
|
+
"cwd": "/workspace/my-project",
|
|
110
|
+
"topic": "review-auth",
|
|
111
|
+
"sandbox": "read-only"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 2. 并行模块实现(阻塞,写入)
|
|
117
|
+
|
|
118
|
+
并发调用多个 `codex`,每个使用不同 `topic`:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"tool": "codex",
|
|
123
|
+
"arguments": {
|
|
124
|
+
"prompt": "实现用户注册模块...",
|
|
125
|
+
"cwd": "/workspace/my-project",
|
|
126
|
+
"topic": "impl-register",
|
|
127
|
+
"sandbox": "full-access"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
每个 `full-access` 任务自动创建独立的 git worktree 和分支 `agent/<topic>`。
|
|
133
|
+
|
|
134
|
+
### 3. 长任务后台分派
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"tool": "codex_dispatch",
|
|
139
|
+
"arguments": {
|
|
140
|
+
"prompt": "重构整个项目为异步架构...",
|
|
141
|
+
"cwd": "/workspace/my-project",
|
|
142
|
+
"topic": "refactor-async",
|
|
143
|
+
"sandbox": "full-access"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
立即返回 `task_id`。之后用 `codex_status` 查看进度。
|
|
149
|
+
|
|
150
|
+
### 4. Resume 多轮对话
|
|
151
|
+
|
|
152
|
+
首次执行返回 `session_id`。修改代码后继续:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"tool": "codex",
|
|
157
|
+
"arguments": {
|
|
158
|
+
"prompt": "我已修改了代码,请重新审阅",
|
|
159
|
+
"cwd": "/workspace/my-project",
|
|
160
|
+
"topic": "review-auth-r2",
|
|
161
|
+
"sandbox": "read-only",
|
|
162
|
+
"session_id": "thread_abc123"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 参数说明
|
|
170
|
+
|
|
171
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
172
|
+
|------|------|------|------|
|
|
173
|
+
| `prompt` | str | 是 | 任务指令 |
|
|
174
|
+
| `cwd` | Path | 是 | 工作目录(绝对路径) |
|
|
175
|
+
| `topic` | str | 是 | 任务标识。用于 tmux session 名、worktree 分支名、task_id |
|
|
176
|
+
| `sandbox` | `read-only` / `full-access` | 是 | 权限模式。read-only 不建 worktree;full-access 创建 worktree 隔离 |
|
|
177
|
+
| `session_id` | str | 否 | 恢复之前的 Codex 会话(多轮对话) |
|
|
178
|
+
|
|
179
|
+
## 返回结构
|
|
180
|
+
|
|
181
|
+
阻塞 `codex` 完成后返回:
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"success": true,
|
|
186
|
+
"task_id": "codex-impl-feature",
|
|
187
|
+
"session_id": "thread_abc123",
|
|
188
|
+
"result": "Codex 的最终回复文本",
|
|
189
|
+
"exit_code": 0,
|
|
190
|
+
"elapsed_seconds": 45.2,
|
|
191
|
+
"usage": {"input_tokens": 5000, "output_tokens": 1200},
|
|
192
|
+
"worktree_dir": "/workspace/project-agent-impl-feature",
|
|
193
|
+
"agent_branch": "agent/impl-feature",
|
|
194
|
+
"base_branch": "main",
|
|
195
|
+
"diff_stat": "3 files changed, 42 insertions(+), 10 deletions(-)",
|
|
196
|
+
"commits_ahead": 2
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
- `session_id` 用于 resume
|
|
201
|
+
- worktree 相关字段仅 `full-access` 模式返回
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 环境变量
|
|
206
|
+
|
|
207
|
+
通过 MCP 服务进程环境变量配置:
|
|
208
|
+
|
|
209
|
+
| 变量 | 说明 | 示例 |
|
|
210
|
+
|------|------|------|
|
|
211
|
+
| `CODEX_PROFILE` | codex 配置文件名 | `fast` |
|
|
212
|
+
| `CODEX_REASONING_EFFORT` | 推理强度 | `high`、`xhigh` |
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 日志
|
|
217
|
+
|
|
218
|
+
| 位置 | 路径 |
|
|
219
|
+
|------|------|
|
|
220
|
+
| 工作区 symlink | `<cwd>/.codex-tasks/<topic>/codex-exec.log` |
|
|
221
|
+
| 主存储 | `~/.codexmcp/tasks/<task_id>/codex-exec.log` |
|
|
222
|
+
| 实时查看 | `tmux attach -t codex-<topic>` |
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 开发
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
git clone https://github.com/GuDaStudio/codexmcp.git
|
|
230
|
+
cd codexmcp
|
|
231
|
+
pip install -e .
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## 许可证
|
|
237
|
+
|
|
238
|
+
[MIT License](./LICENSE)
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# codex-mcp-server
|
|
4
|
+
|
|
5
|
+
MCP server for Codex CLI — tmux persistence, git worktree isolation, async dispatch.
|
|
6
|
+
|
|
7
|
+
[English](./docs/README_EN.md) | 简体中文
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 特性
|
|
14
|
+
|
|
15
|
+
- **tmux 持久化** — 所有任务运行在 tmux session 中,网络断开、窗口关闭后任务继续执行
|
|
16
|
+
- **git worktree 隔离** — `full-access` 模式自动创建独立 worktree,并行任务互不干扰
|
|
17
|
+
- **阻塞 + 异步双模式** — `codex` 同步等待结果,`codex_dispatch` 立即返回后台运行
|
|
18
|
+
- **多轮对话 (resume)** — 通过 `session_id` 延续上一次 Codex 会话
|
|
19
|
+
- **文件系统持久化** — 任务元数据存储在 `~/.codexmcp/tasks/`,服务重启后可恢复
|
|
20
|
+
- **工作区日志** — 自动在 `<cwd>/.codex-tasks/` 创建 symlink,IDE 中直接查看日志
|
|
21
|
+
|
|
22
|
+
## 工具
|
|
23
|
+
|
|
24
|
+
| 工具 | 作用 | 适合场景 |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| `codex` | 阻塞执行,等待完成后返回结果 | 代码审阅、短任务、并行模块实现 |
|
|
27
|
+
| `codex_dispatch` | 后台分派,立即返回 task_id | 长任务(数十分钟到数小时) |
|
|
28
|
+
| `codex_status` | 查询任务状态和进度 | 追踪后台任务、获取结果 |
|
|
29
|
+
| `codex_cancel` | 取消运行中的任务 | 终止不需要的任务 |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 前置要求
|
|
34
|
+
|
|
35
|
+
- Python `3.12+`
|
|
36
|
+
- `codex` CLI 已安装且在 PATH 中
|
|
37
|
+
- `tmux` 已安装(所有模式必须)
|
|
38
|
+
- `git` 已安装(`full-access` 模式必须)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
codex --version
|
|
42
|
+
tmux -V
|
|
43
|
+
git --version
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 安装
|
|
49
|
+
|
|
50
|
+
### Claude Code
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
claude mcp add codex -s user --transport stdio -- \
|
|
54
|
+
uvx codex-mcp-server
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
验证:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
claude mcp list
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Cursor / 通用 MCP 配置
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"command": "uvx",
|
|
68
|
+
"args": ["codex-mcp-server"]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 从 GitHub 源码安装(开发用)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install git+https://github.com/GuDaStudio/codexmcp.git
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 快速上手
|
|
81
|
+
|
|
82
|
+
### 1. 代码审阅(阻塞,只读)
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"tool": "codex",
|
|
87
|
+
"arguments": {
|
|
88
|
+
"prompt": "审阅 src/auth/ 目录的代码质量和安全性",
|
|
89
|
+
"cwd": "/workspace/my-project",
|
|
90
|
+
"topic": "review-auth",
|
|
91
|
+
"sandbox": "read-only"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 2. 并行模块实现(阻塞,写入)
|
|
97
|
+
|
|
98
|
+
并发调用多个 `codex`,每个使用不同 `topic`:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"tool": "codex",
|
|
103
|
+
"arguments": {
|
|
104
|
+
"prompt": "实现用户注册模块...",
|
|
105
|
+
"cwd": "/workspace/my-project",
|
|
106
|
+
"topic": "impl-register",
|
|
107
|
+
"sandbox": "full-access"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
每个 `full-access` 任务自动创建独立的 git worktree 和分支 `agent/<topic>`。
|
|
113
|
+
|
|
114
|
+
### 3. 长任务后台分派
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"tool": "codex_dispatch",
|
|
119
|
+
"arguments": {
|
|
120
|
+
"prompt": "重构整个项目为异步架构...",
|
|
121
|
+
"cwd": "/workspace/my-project",
|
|
122
|
+
"topic": "refactor-async",
|
|
123
|
+
"sandbox": "full-access"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
立即返回 `task_id`。之后用 `codex_status` 查看进度。
|
|
129
|
+
|
|
130
|
+
### 4. Resume 多轮对话
|
|
131
|
+
|
|
132
|
+
首次执行返回 `session_id`。修改代码后继续:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"tool": "codex",
|
|
137
|
+
"arguments": {
|
|
138
|
+
"prompt": "我已修改了代码,请重新审阅",
|
|
139
|
+
"cwd": "/workspace/my-project",
|
|
140
|
+
"topic": "review-auth-r2",
|
|
141
|
+
"sandbox": "read-only",
|
|
142
|
+
"session_id": "thread_abc123"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## 参数说明
|
|
150
|
+
|
|
151
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
152
|
+
|------|------|------|------|
|
|
153
|
+
| `prompt` | str | 是 | 任务指令 |
|
|
154
|
+
| `cwd` | Path | 是 | 工作目录(绝对路径) |
|
|
155
|
+
| `topic` | str | 是 | 任务标识。用于 tmux session 名、worktree 分支名、task_id |
|
|
156
|
+
| `sandbox` | `read-only` / `full-access` | 是 | 权限模式。read-only 不建 worktree;full-access 创建 worktree 隔离 |
|
|
157
|
+
| `session_id` | str | 否 | 恢复之前的 Codex 会话(多轮对话) |
|
|
158
|
+
|
|
159
|
+
## 返回结构
|
|
160
|
+
|
|
161
|
+
阻塞 `codex` 完成后返回:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"success": true,
|
|
166
|
+
"task_id": "codex-impl-feature",
|
|
167
|
+
"session_id": "thread_abc123",
|
|
168
|
+
"result": "Codex 的最终回复文本",
|
|
169
|
+
"exit_code": 0,
|
|
170
|
+
"elapsed_seconds": 45.2,
|
|
171
|
+
"usage": {"input_tokens": 5000, "output_tokens": 1200},
|
|
172
|
+
"worktree_dir": "/workspace/project-agent-impl-feature",
|
|
173
|
+
"agent_branch": "agent/impl-feature",
|
|
174
|
+
"base_branch": "main",
|
|
175
|
+
"diff_stat": "3 files changed, 42 insertions(+), 10 deletions(-)",
|
|
176
|
+
"commits_ahead": 2
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
- `session_id` 用于 resume
|
|
181
|
+
- worktree 相关字段仅 `full-access` 模式返回
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 环境变量
|
|
186
|
+
|
|
187
|
+
通过 MCP 服务进程环境变量配置:
|
|
188
|
+
|
|
189
|
+
| 变量 | 说明 | 示例 |
|
|
190
|
+
|------|------|------|
|
|
191
|
+
| `CODEX_PROFILE` | codex 配置文件名 | `fast` |
|
|
192
|
+
| `CODEX_REASONING_EFFORT` | 推理强度 | `high`、`xhigh` |
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 日志
|
|
197
|
+
|
|
198
|
+
| 位置 | 路径 |
|
|
199
|
+
|------|------|
|
|
200
|
+
| 工作区 symlink | `<cwd>/.codex-tasks/<topic>/codex-exec.log` |
|
|
201
|
+
| 主存储 | `~/.codexmcp/tasks/<task_id>/codex-exec.log` |
|
|
202
|
+
| 实时查看 | `tmux attach -t codex-<topic>` |
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 开发
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
git clone https://github.com/GuDaStudio/codexmcp.git
|
|
210
|
+
cd codexmcp
|
|
211
|
+
pip install -e .
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 许可证
|
|
217
|
+
|
|
218
|
+
[MIT License](./LICENSE)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "codex-mcp-server"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "MCP server for Codex CLI with tmux persistence, git worktree isolation, and async dispatch."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"mcp[cli]>=1.20.0",
|
|
13
|
+
"pydantic>=2.0",
|
|
14
|
+
]
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "guda.studio", email = "gudaclaude@gmail.com" },
|
|
17
|
+
]
|
|
18
|
+
license = { text = "MIT" }
|
|
19
|
+
keywords = ["mcp", "fastmcp", "codex", "tmux", "worktree", "ai-agent"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"License :: OSI Approved :: MIT License",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Topic :: Software Development :: Libraries",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/GuDaStudio/codexmcp"
|
|
30
|
+
Repository = "https://github.com/GuDaStudio/codexmcp"
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
codexmcp = "codexmcp.cli:main"
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.wheel]
|
|
36
|
+
packages = ["src/codexmcp"]
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.sdist]
|
|
39
|
+
include = ["src/codexmcp", "README.md", "LICENSE"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
|
|
6
|
+
_SANDBOX_MAP = {
|
|
7
|
+
"full-access": "danger-full-access",
|
|
8
|
+
"read-only": "read-only",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_codex_command(
|
|
13
|
+
cwd: str,
|
|
14
|
+
sandbox: str,
|
|
15
|
+
*,
|
|
16
|
+
session_id: str = "",
|
|
17
|
+
) -> list[str]:
|
|
18
|
+
"""Build the ``codex exec`` CLI command as a list of arguments.
|
|
19
|
+
|
|
20
|
+
The prompt is **not** included — it is piped via stdin from a file
|
|
21
|
+
by the caller (typically the tmux shell command).
|
|
22
|
+
|
|
23
|
+
Environment variables ``CODEX_PROFILE`` and ``CODEX_REASONING_EFFORT``
|
|
24
|
+
are read at call time and forwarded to the CLI when set.
|
|
25
|
+
"""
|
|
26
|
+
codex_path = shutil.which("codex") or "codex"
|
|
27
|
+
cli_sandbox = _SANDBOX_MAP.get(sandbox, sandbox)
|
|
28
|
+
cmd = [codex_path, "exec", "--sandbox", cli_sandbox, "--cd", cwd, "--json"]
|
|
29
|
+
|
|
30
|
+
profile = os.environ.get("CODEX_PROFILE", "")
|
|
31
|
+
if profile:
|
|
32
|
+
cmd.extend(["--profile", profile])
|
|
33
|
+
|
|
34
|
+
effort = os.environ.get("CODEX_REASONING_EFFORT", "")
|
|
35
|
+
if effort:
|
|
36
|
+
cmd.extend(["--config", f'model_reasoning_effort="{effort}"'])
|
|
37
|
+
|
|
38
|
+
cmd.append("--skip-git-repo-check")
|
|
39
|
+
|
|
40
|
+
if session_id:
|
|
41
|
+
cmd.extend(["resume", session_id, "-"])
|
|
42
|
+
|
|
43
|
+
return cmd
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from enum import Enum
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SandboxMode(str, Enum):
|
|
12
|
+
READ_ONLY = "read-only"
|
|
13
|
+
FULL_ACCESS = "full-access"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TaskMode(str, Enum):
|
|
17
|
+
BLOCKING = "blocking"
|
|
18
|
+
DISPATCH = "dispatch"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TaskStatus(str, Enum):
|
|
22
|
+
RUNNING = "running"
|
|
23
|
+
COMPLETED = "completed"
|
|
24
|
+
FAILED = "failed"
|
|
25
|
+
CANCELLED = "cancelled"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class EventType(str, Enum):
|
|
29
|
+
THINKING = "thinking"
|
|
30
|
+
TEXT = "text"
|
|
31
|
+
TOOL_CALL = "tool_call"
|
|
32
|
+
TOOL_RESULT = "tool_result"
|
|
33
|
+
COMMAND = "command"
|
|
34
|
+
ERROR = "error"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class TaskMeta(BaseModel):
|
|
38
|
+
"""Persistent task metadata, serialised to ``~/.codexmcp/tasks/<id>/meta.json``."""
|
|
39
|
+
|
|
40
|
+
task_id: str
|
|
41
|
+
mode: TaskMode
|
|
42
|
+
prompt: str
|
|
43
|
+
cwd: str
|
|
44
|
+
sandbox: SandboxMode = SandboxMode.READ_ONLY
|
|
45
|
+
topic: str
|
|
46
|
+
tmux_session: str
|
|
47
|
+
log_file: str
|
|
48
|
+
prompt_file: str
|
|
49
|
+
start_time: str # ISO-8601
|
|
50
|
+
|
|
51
|
+
status: TaskStatus = TaskStatus.RUNNING
|
|
52
|
+
|
|
53
|
+
# Worktree isolation (None when not used)
|
|
54
|
+
worktree_dir: Optional[str] = None
|
|
55
|
+
agent_branch: Optional[str] = None
|
|
56
|
+
base_branch: Optional[str] = None
|
|
57
|
+
|
|
58
|
+
# Codex session (populated after completion, used for resume)
|
|
59
|
+
session_id: Optional[str] = None
|
|
60
|
+
|
|
61
|
+
# Completion fields (populated after task finishes)
|
|
62
|
+
end_time: Optional[str] = None
|
|
63
|
+
exit_code: Optional[int] = None
|
|
64
|
+
result: Optional[str] = None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass
|
|
68
|
+
class TaskEvent:
|
|
69
|
+
timestamp: datetime
|
|
70
|
+
type: EventType
|
|
71
|
+
text: Optional[str] = None
|
|
72
|
+
tool_name: Optional[str] = None
|
|
73
|
+
tool_input: Optional[str] = None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass
|
|
77
|
+
class TaskUsage:
|
|
78
|
+
input_tokens: int
|
|
79
|
+
output_tokens: int
|
|
80
|
+
cached_input_tokens: Optional[int] = None
|