@trishchuk/codex-mcp-tool 1.0.6 → 1.2.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/README.md +10 -11
- package/dist/constants.d.ts +55 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +74 -31
- package/dist/constants.js.map +1 -1
- package/dist/index.js +28 -26
- package/dist/index.js.map +1 -1
- package/dist/tools/apply-diff.tool.d.ts +3 -0
- package/dist/tools/apply-diff.tool.d.ts.map +1 -0
- package/dist/tools/apply-diff.tool.js +52 -0
- package/dist/tools/apply-diff.tool.js.map +1 -0
- package/dist/tools/ask-codex.tool.d.ts.map +1 -1
- package/dist/tools/ask-codex.tool.js +158 -33
- package/dist/tools/ask-codex.tool.js.map +1 -1
- package/dist/tools/batch-codex.tool.d.ts +3 -0
- package/dist/tools/batch-codex.tool.d.ts.map +1 -0
- package/dist/tools/batch-codex.tool.js +134 -0
- package/dist/tools/batch-codex.tool.js.map +1 -0
- package/dist/tools/brainstorm.tool.d.ts.map +1 -1
- package/dist/tools/brainstorm.tool.js +62 -29
- package/dist/tools/brainstorm.tool.js.map +1 -1
- package/dist/tools/exec-codex.tool.d.ts +3 -0
- package/dist/tools/exec-codex.tool.d.ts.map +1 -0
- package/dist/tools/exec-codex.tool.js +46 -0
- package/dist/tools/exec-codex.tool.js.map +1 -0
- package/dist/tools/fetch-chunk.tool.d.ts.map +1 -1
- package/dist/tools/fetch-chunk.tool.js +12 -8
- package/dist/tools/fetch-chunk.tool.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +6 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/registry.d.ts +3 -3
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +9 -5
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/review-codex.tool.d.ts +3 -0
- package/dist/tools/review-codex.tool.d.ts.map +1 -0
- package/dist/tools/review-codex.tool.js +91 -0
- package/dist/tools/review-codex.tool.js.map +1 -0
- package/dist/tools/simple-tools.d.ts +1 -0
- package/dist/tools/simple-tools.d.ts.map +1 -1
- package/dist/tools/simple-tools.js +42 -11
- package/dist/tools/simple-tools.js.map +1 -1
- package/dist/tools/test-tool.example.d.ts.map +1 -1
- package/dist/tools/test-tool.example.js +12 -10
- package/dist/tools/test-tool.example.js.map +1 -1
- package/dist/tools/timeout-test.tool.js +5 -5
- package/dist/tools/timeout-test.tool.js.map +1 -1
- package/dist/utils/changeModeChunker.d.ts.map +1 -1
- package/dist/utils/changeModeChunker.js +10 -6
- package/dist/utils/changeModeChunker.js.map +1 -1
- package/dist/utils/changeModeParser.d.ts.map +1 -1
- package/dist/utils/changeModeParser.js.map +1 -1
- package/dist/utils/changeModeRunner.d.ts.map +1 -1
- package/dist/utils/changeModeRunner.js +17 -11
- package/dist/utils/changeModeRunner.js.map +1 -1
- package/dist/utils/changeModeTranslator.d.ts.map +1 -1
- package/dist/utils/changeModeTranslator.js +5 -2
- package/dist/utils/changeModeTranslator.js.map +1 -1
- package/dist/utils/chunkCache.d.ts.map +1 -1
- package/dist/utils/chunkCache.js +6 -4
- package/dist/utils/chunkCache.js.map +1 -1
- package/dist/utils/codexExecutor.d.ts +17 -0
- package/dist/utils/codexExecutor.d.ts.map +1 -1
- package/dist/utils/codexExecutor.js +163 -4
- package/dist/utils/codexExecutor.js.map +1 -1
- package/dist/utils/commandExecutor.d.ts.map +1 -1
- package/dist/utils/commandExecutor.js +25 -17
- package/dist/utils/commandExecutor.js.map +1 -1
- package/dist/utils/fibonacci.d.ts +2 -0
- package/dist/utils/fibonacci.d.ts.map +1 -0
- package/dist/utils/fibonacci.js +17 -0
- package/dist/utils/fibonacci.js.map +1 -0
- package/dist/utils/gitHelper.d.ts +20 -0
- package/dist/utils/gitHelper.d.ts.map +1 -0
- package/dist/utils/gitHelper.js +66 -0
- package/dist/utils/gitHelper.js.map +1 -0
- package/dist/utils/logger.d.ts +2 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +21 -15
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/outputParser.d.ts +26 -0
- package/dist/utils/outputParser.d.ts.map +1 -0
- package/dist/utils/outputParser.js +174 -0
- package/dist/utils/outputParser.js.map +1 -0
- package/dist/utils/reviewParser.d.ts +28 -0
- package/dist/utils/reviewParser.d.ts.map +1 -0
- package/dist/utils/reviewParser.js +87 -0
- package/dist/utils/reviewParser.js.map +1 -0
- package/dist/utils/workingDirResolver.d.ts +47 -0
- package/dist/utils/workingDirResolver.d.ts.map +1 -0
- package/dist/utils/workingDirResolver.js +199 -0
- package/dist/utils/workingDirResolver.js.map +1 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# Codex MCP Tool
|
|
3
2
|
|
|
4
3
|
<div align="center">
|
|
@@ -11,7 +10,6 @@
|
|
|
11
10
|
|
|
12
11
|
</div>
|
|
13
12
|
|
|
14
|
-
|
|
15
13
|
Codex MCP Tool is an open‑source Model Context Protocol (MCP) server that connects your IDE or AI assistant (Claude, Cursor, etc.) to the Codex CLI. It enables non‑interactive automation with `codex exec`, safe sandboxed edits with approvals, and large‑scale code analysis via `@` file references. Built for reliability and speed, it streams progress updates, supports structured change mode (OLD/NEW patch output), and integrates cleanly with standard MCP clients for code review, refactoring, documentation, and CI automation.
|
|
16
14
|
|
|
17
15
|
- Ask Codex questions from your MCP client, or brainstorm ideas programmatically.
|
|
@@ -31,7 +29,6 @@ Before using this tool, ensure you have:
|
|
|
31
29
|
1. **[Node.js](https://nodejs.org/)** (v18.0.0 or higher)
|
|
32
30
|
2. **[Codex CLI](https://github.com/openai/codex)** installed and authenticated
|
|
33
31
|
|
|
34
|
-
|
|
35
32
|
### One-Line Setup
|
|
36
33
|
|
|
37
34
|
```bash
|
|
@@ -49,6 +46,7 @@ Type `/mcp` inside Claude Code to verify the Codex MCP is active.
|
|
|
49
46
|
If you already have it configured in Claude Desktop:
|
|
50
47
|
|
|
51
48
|
1. Add to your Claude Desktop config:
|
|
49
|
+
|
|
52
50
|
```json
|
|
53
51
|
"codex-cli": {
|
|
54
52
|
"command": "npx",
|
|
@@ -57,6 +55,7 @@ If you already have it configured in Claude Desktop:
|
|
|
57
55
|
```
|
|
58
56
|
|
|
59
57
|
2. Import to Claude Code:
|
|
58
|
+
|
|
60
59
|
```bash
|
|
61
60
|
claude mcp add-from-claude-desktop
|
|
62
61
|
```
|
|
@@ -114,19 +113,19 @@ After updating the configuration, restart your terminal session.
|
|
|
114
113
|
|
|
115
114
|
```javascript
|
|
116
115
|
// Use the default gpt-5-codex model
|
|
117
|
-
|
|
116
|
+
'explain the architecture of @src/';
|
|
118
117
|
|
|
119
118
|
// Use gpt-5 for fast general purpose reasoning
|
|
120
|
-
|
|
119
|
+
'use codex with model gpt-5 to analyze @config.json';
|
|
121
120
|
|
|
122
121
|
// Use o3 for deep reasoning tasks
|
|
123
|
-
|
|
122
|
+
'use codex with model o3 to analyze complex algorithm in @algorithm.py';
|
|
124
123
|
|
|
125
124
|
// Use o4-mini for quick tasks
|
|
126
|
-
|
|
125
|
+
'use codex with model o4-mini to add comments to @utils.js';
|
|
127
126
|
|
|
128
127
|
// Use codex-1 for software engineering
|
|
129
|
-
|
|
128
|
+
'use codex with model codex-1 to refactor @legacy-code.js';
|
|
130
129
|
```
|
|
131
130
|
|
|
132
131
|
### With File References (using @ syntax)
|
|
@@ -157,13 +156,13 @@ Codex supports approval/sandbox modes. This server uses `codex exec` and can opt
|
|
|
157
156
|
|
|
158
157
|
```javascript
|
|
159
158
|
// Using ask-codex with specific model
|
|
160
|
-
|
|
159
|
+
'ask codex using gpt-5 to refactor @utils/database.js for better performance';
|
|
161
160
|
|
|
162
161
|
// Brainstorming with constraints
|
|
163
|
-
"brainstorm solutions for reducing API latency with constraints: 'must use existing infrastructure, budget under $5k'"
|
|
162
|
+
"brainstorm solutions for reducing API latency with constraints: 'must use existing infrastructure, budget under $5k'";
|
|
164
163
|
|
|
165
164
|
// Change mode for structured edits
|
|
166
|
-
|
|
165
|
+
'use codex in change mode to update all console.log to use winston logger in @src/';
|
|
167
166
|
```
|
|
168
167
|
|
|
169
168
|
### Tools (for the AI)
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,14 +2,40 @@ export declare const LOG_PREFIX = "[CODEX-MCP]";
|
|
|
2
2
|
export declare const ERROR_MESSAGES: {
|
|
3
3
|
readonly TOOL_NOT_FOUND: "not found in registry";
|
|
4
4
|
readonly NO_PROMPT_PROVIDED: "Please provide a prompt for analysis. Use @ syntax to include files (e.g., '@largefile.js explain what this does') or ask general questions";
|
|
5
|
+
readonly QUOTA_EXCEEDED: "Rate limit exceeded";
|
|
6
|
+
readonly AUTHENTICATION_FAILED: "Authentication failed - please check your OpenAI API key or login status";
|
|
7
|
+
readonly CODEX_NOT_FOUND: "Codex CLI not found - please install with 'npm install -g @openai/codex'";
|
|
8
|
+
readonly SANDBOX_VIOLATION: "Operation blocked by sandbox policy";
|
|
9
|
+
readonly UNSAFE_COMMAND: "Command requires approval or elevated permissions";
|
|
5
10
|
};
|
|
6
11
|
export declare const STATUS_MESSAGES: {
|
|
7
12
|
readonly SANDBOX_EXECUTING: "🔒 Executing CLI command in sandbox/auto mode...";
|
|
8
13
|
readonly CODEX_RESPONSE: "Codex response:";
|
|
14
|
+
readonly AUTHENTICATION_SUCCESS: "✅ Authentication successful";
|
|
9
15
|
readonly PROCESSING_START: "🔍 Starting analysis (may take 5-15 minutes for large codebases)";
|
|
10
16
|
readonly PROCESSING_CONTINUE: "⏳ Still processing...";
|
|
11
17
|
readonly PROCESSING_COMPLETE: "✅ Analysis completed successfully";
|
|
12
18
|
};
|
|
19
|
+
export declare const MODELS: {
|
|
20
|
+
readonly GPT5_CODEX: "gpt-5-codex";
|
|
21
|
+
readonly GPT5: "gpt-5";
|
|
22
|
+
readonly O3: "o3";
|
|
23
|
+
readonly O4_MINI: "o4-mini";
|
|
24
|
+
readonly CODEX_1: "codex-1";
|
|
25
|
+
readonly CODEX_MINI_LATEST: "codex-mini-latest";
|
|
26
|
+
readonly GPT_4_1: "gpt-4.1";
|
|
27
|
+
};
|
|
28
|
+
export declare const SANDBOX_MODES: {
|
|
29
|
+
readonly READ_ONLY: "read-only";
|
|
30
|
+
readonly WORKSPACE_WRITE: "workspace-write";
|
|
31
|
+
readonly DANGER_FULL_ACCESS: "danger-full-access";
|
|
32
|
+
};
|
|
33
|
+
export declare const APPROVAL_POLICIES: {
|
|
34
|
+
readonly UNTRUSTED: "untrusted";
|
|
35
|
+
readonly ON_FAILURE: "on-failure";
|
|
36
|
+
readonly ON_REQUEST: "on-request";
|
|
37
|
+
readonly NEVER: "never";
|
|
38
|
+
};
|
|
13
39
|
export declare const PROTOCOL: {
|
|
14
40
|
readonly ROLES: {
|
|
15
41
|
readonly USER: "user";
|
|
@@ -32,6 +58,7 @@ export declare const PROTOCOL: {
|
|
|
32
58
|
export declare const CLI: {
|
|
33
59
|
readonly COMMANDS: {
|
|
34
60
|
readonly CODEX: "codex";
|
|
61
|
+
readonly CODEX_EXEC: "codex exec";
|
|
35
62
|
readonly ECHO: "echo";
|
|
36
63
|
};
|
|
37
64
|
readonly FLAGS: {
|
|
@@ -40,37 +67,63 @@ export declare const CLI: {
|
|
|
40
67
|
readonly FULL_AUTO: "--full-auto";
|
|
41
68
|
readonly ASK_FOR_APPROVAL: "--ask-for-approval";
|
|
42
69
|
readonly SANDBOX_MODE: "--sandbox";
|
|
70
|
+
readonly APPROVAL: "-a";
|
|
43
71
|
readonly YOLO: "--dangerously-bypass-approvals-and-sandbox";
|
|
44
72
|
readonly CD: "--cd";
|
|
45
|
-
readonly SKIP_GIT_REPO_CHECK: "--skip-git-repo-check";
|
|
46
73
|
readonly PROMPT: "-p";
|
|
47
74
|
readonly HELP: "-help";
|
|
75
|
+
readonly IMAGE: "-i";
|
|
76
|
+
readonly PROFILE: "--profile";
|
|
77
|
+
readonly CONFIG: "-c";
|
|
78
|
+
readonly VERSION: "--version";
|
|
79
|
+
readonly WORKING_DIR: "-C";
|
|
80
|
+
readonly OSS: "--oss";
|
|
81
|
+
readonly ENABLE: "--enable";
|
|
82
|
+
readonly DISABLE: "--disable";
|
|
48
83
|
};
|
|
49
84
|
readonly DEFAULTS: {
|
|
50
85
|
readonly MODEL: "default";
|
|
51
86
|
readonly BOOLEAN_TRUE: "true";
|
|
52
87
|
readonly BOOLEAN_FALSE: "false";
|
|
53
88
|
};
|
|
89
|
+
readonly ENV_VARS: {
|
|
90
|
+
readonly CODEX_MCP_CWD: "CODEX_MCP_CWD";
|
|
91
|
+
readonly PWD: "PWD";
|
|
92
|
+
readonly INIT_CWD: "INIT_CWD";
|
|
93
|
+
};
|
|
54
94
|
};
|
|
55
95
|
export interface ToolArguments {
|
|
56
96
|
prompt?: string;
|
|
57
97
|
model?: string;
|
|
58
98
|
sandbox?: boolean | string;
|
|
59
99
|
approvalPolicy?: 'never' | 'on-request' | 'on-failure' | 'untrusted';
|
|
100
|
+
approval?: string;
|
|
60
101
|
sandboxMode?: 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
61
102
|
fullAuto?: boolean | string;
|
|
62
103
|
yolo?: boolean | string;
|
|
63
104
|
cd?: string;
|
|
105
|
+
workingDir?: string;
|
|
64
106
|
changeMode?: boolean | string;
|
|
65
107
|
chunkIndex?: number | string;
|
|
66
108
|
chunkCacheKey?: string;
|
|
67
109
|
message?: string;
|
|
110
|
+
image?: string | string[];
|
|
111
|
+
config?: string | Record<string, any>;
|
|
112
|
+
profile?: string;
|
|
113
|
+
timeout?: number;
|
|
114
|
+
useExec?: boolean;
|
|
115
|
+
includeThinking?: boolean;
|
|
116
|
+
includeMetadata?: boolean;
|
|
117
|
+
search?: boolean;
|
|
118
|
+
oss?: boolean;
|
|
119
|
+
enableFeatures?: string[];
|
|
120
|
+
disableFeatures?: string[];
|
|
68
121
|
methodology?: string;
|
|
69
122
|
domain?: string;
|
|
70
123
|
constraints?: string;
|
|
71
124
|
existingContext?: string;
|
|
72
125
|
ideaCount?: number;
|
|
73
126
|
includeAnalysis?: boolean;
|
|
74
|
-
[key: string]: string | boolean | number | undefined;
|
|
127
|
+
[key: string]: string | boolean | number | string[] | Record<string, any> | undefined;
|
|
75
128
|
}
|
|
76
129
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,gBAAgB,CAAC;AAGxC,eAAO,MAAM,cAAc;;;;;;;;CASjB,CAAC;AAGX,eAAO,MAAM,eAAe;;;;;;;CAQlB,CAAC;AAGX,eAAO,MAAM,MAAM;;;;;;;;CAQT,CAAC;AAGX,eAAO,MAAM,aAAa;;;;CAIhB,CAAC;AAGX,eAAO,MAAM,iBAAiB;;;;;CAKpB,CAAC;AAGX,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;CAuBX,CAAC;AAGX,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCN,CAAC;AAGX,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAE3B,cAAc,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;IACrE,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,EAAE,CAAC,EAA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export const ERROR_MESSAGES = {
|
|
5
|
-
TOOL_NOT_FOUND:
|
|
5
|
+
TOOL_NOT_FOUND: 'not found in registry',
|
|
6
6
|
NO_PROMPT_PROVIDED: "Please provide a prompt for analysis. Use @ syntax to include files (e.g., '@largefile.js explain what this does') or ask general questions",
|
|
7
|
+
QUOTA_EXCEEDED: 'Rate limit exceeded',
|
|
8
|
+
AUTHENTICATION_FAILED: 'Authentication failed - please check your OpenAI API key or login status',
|
|
9
|
+
CODEX_NOT_FOUND: "Codex CLI not found - please install with 'npm install -g @openai/codex'",
|
|
10
|
+
SANDBOX_VIOLATION: 'Operation blocked by sandbox policy',
|
|
11
|
+
UNSAFE_COMMAND: 'Command requires approval or elevated permissions',
|
|
7
12
|
};
|
|
8
13
|
// Status messages
|
|
9
14
|
export const STATUS_MESSAGES = {
|
|
10
|
-
SANDBOX_EXECUTING:
|
|
11
|
-
CODEX_RESPONSE:
|
|
15
|
+
SANDBOX_EXECUTING: '🔒 Executing CLI command in sandbox/auto mode...',
|
|
16
|
+
CODEX_RESPONSE: 'Codex response:',
|
|
17
|
+
AUTHENTICATION_SUCCESS: '✅ Authentication successful',
|
|
12
18
|
// Timeout prevention messages
|
|
13
|
-
PROCESSING_START:
|
|
14
|
-
PROCESSING_CONTINUE:
|
|
15
|
-
PROCESSING_COMPLETE:
|
|
19
|
+
PROCESSING_START: '🔍 Starting analysis (may take 5-15 minutes for large codebases)',
|
|
20
|
+
PROCESSING_CONTINUE: '⏳ Still processing...',
|
|
21
|
+
PROCESSING_COMPLETE: '✅ Analysis completed successfully',
|
|
22
|
+
};
|
|
23
|
+
// Models
|
|
24
|
+
export const MODELS = {
|
|
25
|
+
GPT5_CODEX: 'gpt-5-codex',
|
|
26
|
+
GPT5: 'gpt-5',
|
|
27
|
+
O3: 'o3',
|
|
28
|
+
O4_MINI: 'o4-mini',
|
|
29
|
+
CODEX_1: 'codex-1',
|
|
30
|
+
CODEX_MINI_LATEST: 'codex-mini-latest',
|
|
31
|
+
GPT_4_1: 'gpt-4.1',
|
|
32
|
+
};
|
|
33
|
+
// Sandbox modes
|
|
34
|
+
export const SANDBOX_MODES = {
|
|
35
|
+
READ_ONLY: 'read-only',
|
|
36
|
+
WORKSPACE_WRITE: 'workspace-write',
|
|
37
|
+
DANGER_FULL_ACCESS: 'danger-full-access',
|
|
38
|
+
};
|
|
39
|
+
// Approval policies
|
|
40
|
+
export const APPROVAL_POLICIES = {
|
|
41
|
+
UNTRUSTED: 'untrusted',
|
|
42
|
+
ON_FAILURE: 'on-failure',
|
|
43
|
+
ON_REQUEST: 'on-request',
|
|
44
|
+
NEVER: 'never',
|
|
16
45
|
};
|
|
17
|
-
// Models: pass-through via Codex CLI
|
|
18
46
|
// MCP Protocol Constants
|
|
19
47
|
export const PROTOCOL = {
|
|
20
48
|
// Message roles
|
|
21
49
|
ROLES: {
|
|
22
|
-
USER:
|
|
23
|
-
ASSISTANT:
|
|
50
|
+
USER: 'user',
|
|
51
|
+
ASSISTANT: 'assistant',
|
|
24
52
|
},
|
|
25
53
|
// Content types
|
|
26
54
|
CONTENT_TYPES: {
|
|
27
|
-
TEXT:
|
|
55
|
+
TEXT: 'text',
|
|
28
56
|
},
|
|
29
57
|
// Status codes
|
|
30
58
|
STATUS: {
|
|
31
|
-
SUCCESS:
|
|
32
|
-
ERROR:
|
|
33
|
-
FAILED:
|
|
34
|
-
REPORT:
|
|
59
|
+
SUCCESS: 'success',
|
|
60
|
+
ERROR: 'error',
|
|
61
|
+
FAILED: 'failed',
|
|
62
|
+
REPORT: 'report',
|
|
35
63
|
},
|
|
36
64
|
// Notification methods
|
|
37
65
|
NOTIFICATIONS: {
|
|
38
|
-
PROGRESS:
|
|
66
|
+
PROGRESS: 'notifications/progress',
|
|
39
67
|
},
|
|
40
68
|
// Timeout prevention
|
|
41
69
|
KEEPALIVE_INTERVAL: 25000, // 25 seconds
|
|
@@ -44,27 +72,42 @@ export const PROTOCOL = {
|
|
|
44
72
|
export const CLI = {
|
|
45
73
|
// Command names
|
|
46
74
|
COMMANDS: {
|
|
47
|
-
CODEX:
|
|
48
|
-
|
|
75
|
+
CODEX: 'codex',
|
|
76
|
+
CODEX_EXEC: 'codex exec',
|
|
77
|
+
ECHO: 'echo',
|
|
49
78
|
},
|
|
50
79
|
// Command flags
|
|
51
80
|
FLAGS: {
|
|
52
|
-
MODEL:
|
|
53
|
-
SANDBOX:
|
|
54
|
-
FULL_AUTO:
|
|
55
|
-
ASK_FOR_APPROVAL:
|
|
56
|
-
SANDBOX_MODE:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
PROMPT:
|
|
61
|
-
HELP:
|
|
81
|
+
MODEL: '-m',
|
|
82
|
+
SANDBOX: '-s', // legacy flag. For Codex prefer FULL_AUTO or SANDBOX/APPROVAL flags.
|
|
83
|
+
FULL_AUTO: '--full-auto',
|
|
84
|
+
ASK_FOR_APPROVAL: '--ask-for-approval',
|
|
85
|
+
SANDBOX_MODE: '--sandbox',
|
|
86
|
+
APPROVAL: '-a',
|
|
87
|
+
YOLO: '--dangerously-bypass-approvals-and-sandbox',
|
|
88
|
+
CD: '--cd',
|
|
89
|
+
PROMPT: '-p',
|
|
90
|
+
HELP: '-help',
|
|
91
|
+
IMAGE: '-i',
|
|
92
|
+
PROFILE: '--profile',
|
|
93
|
+
CONFIG: '-c',
|
|
94
|
+
VERSION: '--version',
|
|
95
|
+
WORKING_DIR: '-C',
|
|
96
|
+
OSS: '--oss',
|
|
97
|
+
ENABLE: '--enable',
|
|
98
|
+
DISABLE: '--disable',
|
|
62
99
|
},
|
|
63
100
|
// Default values
|
|
64
101
|
DEFAULTS: {
|
|
65
|
-
MODEL:
|
|
66
|
-
BOOLEAN_TRUE:
|
|
67
|
-
BOOLEAN_FALSE:
|
|
102
|
+
MODEL: 'default', // Fallback model used when no specific model is provided
|
|
103
|
+
BOOLEAN_TRUE: 'true',
|
|
104
|
+
BOOLEAN_FALSE: 'false',
|
|
105
|
+
},
|
|
106
|
+
// Environment variables for working directory resolution
|
|
107
|
+
ENV_VARS: {
|
|
108
|
+
CODEX_MCP_CWD: 'CODEX_MCP_CWD', // Primary: Set in MCP client configuration
|
|
109
|
+
PWD: 'PWD', // Secondary: Standard Unix variable
|
|
110
|
+
INIT_CWD: 'INIT_CWD', // Tertiary: Node.js initial directory
|
|
68
111
|
},
|
|
69
112
|
};
|
|
70
113
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AAExC,iBAAiB;AACjB,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,cAAc,EAAE,uBAAuB;IACvC,kBAAkB,EAChB,6IAA6I;IAC/I,cAAc,EAAE,qBAAqB;IACrC,qBAAqB,EAAE,0EAA0E;IACjG,eAAe,EAAE,0EAA0E;IAC3F,iBAAiB,EAAE,qCAAqC;IACxD,cAAc,EAAE,mDAAmD;CAC3D,CAAC;AAEX,kBAAkB;AAClB,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,iBAAiB,EAAE,kDAAkD;IACrE,cAAc,EAAE,iBAAiB;IACjC,sBAAsB,EAAE,6BAA6B;IACrD,8BAA8B;IAC9B,gBAAgB,EAAE,kEAAkE;IACpF,mBAAmB,EAAE,uBAAuB;IAC5C,mBAAmB,EAAE,mCAAmC;CAChD,CAAC;AAEX,SAAS;AACT,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,UAAU,EAAE,aAAa;IACzB,IAAI,EAAE,OAAO;IACb,EAAE,EAAE,IAAI;IACR,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,iBAAiB,EAAE,mBAAmB;IACtC,OAAO,EAAE,SAAS;CACV,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AI;QACX,OAAO,EAAE,WAAW;QACpB,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,WAAW;QACpB,WAAW,EAAE,IAAI;QACjB,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,WAAW;KACrB;IACD,iBAAiB;IACjB,QAAQ,EAAE;QACR,KAAK,EAAE,SAAS,EAAE,yDAAyD;QAC3E,YAAY,EAAE,MAAM;QACpB,aAAa,EAAE,OAAO;KACvB;IACD,yDAAyD;IACzD,QAAQ,EAAE;QACR,aAAa,EAAE,eAAe,EAAE,2CAA2C;QAC3E,GAAG,EAAE,KAAK,EAAE,oCAAoC;QAChD,QAAQ,EAAE,UAAU,EAAE,sCAAsC;KAC7D;CACO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Server } from
|
|
3
|
-
import { StdioServerTransport } from
|
|
4
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, SetLevelRequestSchema, } from
|
|
5
|
-
import { Logger } from
|
|
6
|
-
import { PROTOCOL } from
|
|
7
|
-
import { getToolDefinitions, getPromptDefinitions, executeTool, toolExists, getPromptMessage } from
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, SetLevelRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { Logger } from './utils/logger.js';
|
|
6
|
+
import { PROTOCOL } from './constants.js';
|
|
7
|
+
import { getToolDefinitions, getPromptDefinitions, executeTool, toolExists, getPromptMessage, } from './tools/index.js';
|
|
8
8
|
const server = new Server({
|
|
9
|
-
name:
|
|
10
|
-
version:
|
|
9
|
+
name: 'codex-cli-mcp',
|
|
10
|
+
version: '1.2.0',
|
|
11
11
|
}, {
|
|
12
12
|
capabilities: {
|
|
13
13
|
tools: {},
|
|
@@ -29,7 +29,7 @@ async function sendProgressNotification(progressToken, progress, total, message)
|
|
|
29
29
|
try {
|
|
30
30
|
const params = {
|
|
31
31
|
progressToken,
|
|
32
|
-
progress
|
|
32
|
+
progress,
|
|
33
33
|
};
|
|
34
34
|
if (total !== undefined)
|
|
35
35
|
params.total = total; // future cache progress
|
|
@@ -37,11 +37,11 @@ async function sendProgressNotification(progressToken, progress, total, message)
|
|
|
37
37
|
params.message = message;
|
|
38
38
|
await server.notification({
|
|
39
39
|
method: PROTOCOL.NOTIFICATIONS.PROGRESS,
|
|
40
|
-
params
|
|
40
|
+
params,
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
|
-
Logger.error(
|
|
44
|
+
Logger.error('Failed to send progress notification:', error);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
function startProgressUpdates(operationName, progressToken) {
|
|
@@ -49,7 +49,7 @@ function startProgressUpdates(operationName, progressToken) {
|
|
|
49
49
|
const state = {
|
|
50
50
|
isProcessing: true,
|
|
51
51
|
currentOperationName: operationName,
|
|
52
|
-
latestOutput:
|
|
52
|
+
latestOutput: '',
|
|
53
53
|
};
|
|
54
54
|
const progressMessages = [
|
|
55
55
|
`🧠 ${operationName} - Codex is analyzing your request...`,
|
|
@@ -87,7 +87,7 @@ function startProgressUpdates(operationName, progressToken) {
|
|
|
87
87
|
return { interval: progressInterval, progressToken, state };
|
|
88
88
|
}
|
|
89
89
|
function stopProgressUpdates(progressData, success = true) {
|
|
90
|
-
const operationName = progressData.state?.currentOperationName ||
|
|
90
|
+
const operationName = progressData.state?.currentOperationName || ''; // Get from state
|
|
91
91
|
if (progressData.state) {
|
|
92
92
|
progressData.state.isProcessing = false;
|
|
93
93
|
}
|
|
@@ -120,7 +120,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
120
120
|
const args = request.params.arguments || {};
|
|
121
121
|
Logger.toolInvocation(toolName, request.params.arguments);
|
|
122
122
|
// Execute the tool using the unified registry with progress callback
|
|
123
|
-
const result = await executeTool(toolName, args,
|
|
123
|
+
const result = await executeTool(toolName, args, newOutput => {
|
|
124
124
|
if (progressData.state) {
|
|
125
125
|
progressData.state.latestOutput = newOutput;
|
|
126
126
|
}
|
|
@@ -130,7 +130,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
130
130
|
return {
|
|
131
131
|
content: [
|
|
132
132
|
{
|
|
133
|
-
type:
|
|
133
|
+
type: 'text',
|
|
134
134
|
text: result,
|
|
135
135
|
},
|
|
136
136
|
],
|
|
@@ -145,7 +145,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
145
145
|
return {
|
|
146
146
|
content: [
|
|
147
147
|
{
|
|
148
|
-
type:
|
|
148
|
+
type: 'text',
|
|
149
149
|
text: `Error executing ${toolName}: ${errorMessage}`,
|
|
150
150
|
},
|
|
151
151
|
],
|
|
@@ -170,24 +170,26 @@ server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
|
170
170
|
throw new Error(`Unknown prompt: ${promptName}`);
|
|
171
171
|
}
|
|
172
172
|
return {
|
|
173
|
-
messages: [
|
|
174
|
-
|
|
173
|
+
messages: [
|
|
174
|
+
{
|
|
175
|
+
role: 'user',
|
|
175
176
|
content: {
|
|
176
|
-
type:
|
|
177
|
-
text: promptMessage
|
|
178
|
-
}
|
|
179
|
-
}
|
|
177
|
+
type: 'text',
|
|
178
|
+
text: promptMessage,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
180
182
|
};
|
|
181
183
|
});
|
|
182
184
|
// Start the server
|
|
183
185
|
async function main() {
|
|
184
|
-
Logger.debug(
|
|
186
|
+
Logger.debug('init codex-mcp-tool');
|
|
185
187
|
const transport = new StdioServerTransport();
|
|
186
188
|
await server.connect(transport);
|
|
187
|
-
Logger.debug(
|
|
189
|
+
Logger.debug('codex-mcp-tool listening on stdio');
|
|
188
190
|
}
|
|
189
|
-
main().catch(
|
|
190
|
-
Logger.error(
|
|
191
|
+
main().catch(error => {
|
|
192
|
+
Logger.error('Fatal error:', error);
|
|
191
193
|
process.exit(1);
|
|
192
194
|
});
|
|
193
195
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,GAUtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAiB,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;IACE,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,OAAO;CACjB,EACD;IACE,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;QACX,aAAa,EAAE,EAAE;QACjB,OAAO,EAAE,EAAE;KACZ;CACF,CACF,CAAC;AAEF,yDAAyD;AAEzD;;;;;GAKG;AACH,KAAK,UAAU,wBAAwB,CACrC,aAA0C,EAC1C,QAAgB,EAChB,KAAc,EACd,OAAgB;IAEhB,IAAI,CAAC,aAAa;QAAE,OAAO,CAAC,yCAAyC;IAErE,IA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,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;IAE5C,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAEzD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO;QACL,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,MAAe;gBACrB,OAAO,EAAE;oBACP,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,aAAa;iBACpB;aACF;SACF;KACF,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,mBAAmB;AACnB,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;AACpD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-diff.tool.d.ts","sourceRoot":"","sources":["../../src/tools/apply-diff.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAS5C,eAAO,MAAM,aAAa,EAAE,WAsD3B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { executeCodexApply } from '../utils/codexExecutor.js';
|
|
3
|
+
import { STATUS_MESSAGES } from '../constants.js';
|
|
4
|
+
const applyDiffArgsSchema = z.object({
|
|
5
|
+
dryRun: z.boolean().default(false).describe("Preview changes without applying them"),
|
|
6
|
+
validate: z.boolean().default(true).describe("Validate changes before applying"),
|
|
7
|
+
});
|
|
8
|
+
export const applyDiffTool = {
|
|
9
|
+
name: "apply-diff",
|
|
10
|
+
description: "Apply the latest diff produced by Codex agent to the local git repository",
|
|
11
|
+
zodSchema: applyDiffArgsSchema,
|
|
12
|
+
prompt: {
|
|
13
|
+
description: "Apply Codex-generated code changes to your git repository",
|
|
14
|
+
},
|
|
15
|
+
category: 'codex',
|
|
16
|
+
execute: async (args, onProgress) => {
|
|
17
|
+
const { dryRun, validate } = args;
|
|
18
|
+
try {
|
|
19
|
+
if (onProgress) {
|
|
20
|
+
onProgress(STATUS_MESSAGES.APPLYING_DIFF);
|
|
21
|
+
}
|
|
22
|
+
const result = await executeCodexApply({
|
|
23
|
+
dryRun: dryRun,
|
|
24
|
+
validate: validate,
|
|
25
|
+
}, onProgress);
|
|
26
|
+
let response = STATUS_MESSAGES.APPLYING_DIFF + '\n\n';
|
|
27
|
+
if (dryRun) {
|
|
28
|
+
response += '**Dry Run Mode - No changes applied:**\n';
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
response += '**Changes Applied:**\n';
|
|
32
|
+
}
|
|
33
|
+
response += '```\n' + result + '\n```';
|
|
34
|
+
if (!dryRun) {
|
|
35
|
+
response += '\n\n✅ Git diff has been successfully applied to your working tree.';
|
|
36
|
+
response += '\n\n*Note: Review the changes and commit them when ready.*';
|
|
37
|
+
}
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
42
|
+
if (errorMessage.includes('No diff found') || errorMessage.includes('no changes')) {
|
|
43
|
+
return '⚠️ **No Diff Available**: No recent Codex-generated diff found to apply.\n\nTo generate a diff:\n1. Use `ask-codex` with a code modification request\n2. Then use `apply-diff` to apply the changes';
|
|
44
|
+
}
|
|
45
|
+
if (errorMessage.includes('not a git repository')) {
|
|
46
|
+
return '❌ **Git Repository Required**: This command must be run within a git repository.\n\n```bash\ngit init # Initialize a new repository\n```';
|
|
47
|
+
}
|
|
48
|
+
return `❌ **Apply Diff Failed**: ${errorMessage}\n\n**Troubleshooting:**\n- Ensure you're in a git repository\n- Check that Codex has generated a recent diff\n- Verify working tree is clean or conflicts are resolved`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=apply-diff.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-diff.tool.js","sourceRoot":"","sources":["../../src/tools/apply-diff.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,uCAAuC,CAAC;IACpF,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,kCAAkC,CAAC;CACjF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAgB;IACxC,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,2EAA2E;IACxF,SAAS,EAAE,mBAAmB;IAC9B,MAAM,EAAE;QACN,WAAW,EAAE,2DAA2D;KACzE;IACD,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;QAClC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAElC,IAAI,CAAC;YACH,IAAI,UAAU,EAAE,CAAC;gBACf,UAAU,CAAC,eAA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"version":3,"file":"ask-codex.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ask-codex.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAyF5C,eAAO,MAAM,YAAY,EAAE,WAgJ1B,CAAC"}
|