@cpujia/codex-mcp-server 2.0.1 → 2.1.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/dist/codex-client.d.ts +7 -2
- package/dist/codex-client.js +8 -2
- package/dist/index.js +341 -31
- package/dist/tools.d.ts +102 -0
- package/dist/tools.js +89 -0
- package/package.json +1 -1
package/dist/codex-client.d.ts
CHANGED
|
@@ -17,10 +17,15 @@ interface CodexRequestOptions {
|
|
|
17
17
|
jsonSchema?: JsonSchemaFormat;
|
|
18
18
|
reasoningEffort?: ReasoningEffort;
|
|
19
19
|
maxTokens?: number;
|
|
20
|
+
previousResponseId?: string;
|
|
21
|
+
}
|
|
22
|
+
interface CodexRequestResult {
|
|
23
|
+
text: string;
|
|
24
|
+
responseId: string;
|
|
20
25
|
}
|
|
21
26
|
export declare class CodexClient {
|
|
22
27
|
private config;
|
|
23
28
|
constructor(config: CodexClientConfig);
|
|
24
|
-
request(options: CodexRequestOptions): Promise<
|
|
29
|
+
request(options: CodexRequestOptions): Promise<CodexRequestResult>;
|
|
25
30
|
}
|
|
26
|
-
export type { CodexClientConfig, CodexRequestOptions, JsonSchemaFormat, ReasoningEffort, };
|
|
31
|
+
export type { CodexClientConfig, CodexRequestOptions, CodexRequestResult, JsonSchemaFormat, ReasoningEffort, };
|
package/dist/codex-client.js
CHANGED
|
@@ -17,8 +17,11 @@ export class CodexClient {
|
|
|
17
17
|
model: this.config.model,
|
|
18
18
|
input: [{ role: "user", content: userContent }],
|
|
19
19
|
max_output_tokens: maxTokens,
|
|
20
|
-
store:
|
|
20
|
+
store: true, // 启用存储以支持 previous_response_id
|
|
21
21
|
};
|
|
22
|
+
if (options.previousResponseId) {
|
|
23
|
+
requestBody.previous_response_id = options.previousResponseId;
|
|
24
|
+
}
|
|
22
25
|
if (effort) {
|
|
23
26
|
requestBody.reasoning = { effort };
|
|
24
27
|
}
|
|
@@ -56,7 +59,10 @@ export class CodexClient {
|
|
|
56
59
|
if (!textContent?.text) {
|
|
57
60
|
throw new Error("No text content in response");
|
|
58
61
|
}
|
|
59
|
-
return
|
|
62
|
+
return {
|
|
63
|
+
text: textContent.text,
|
|
64
|
+
responseId: data.id,
|
|
65
|
+
};
|
|
60
66
|
}
|
|
61
67
|
catch (error) {
|
|
62
68
|
clearTimeout(timeoutId);
|
package/dist/index.js
CHANGED
|
@@ -137,38 +137,271 @@ const TEST_SCHEMA = {
|
|
|
137
137
|
additionalProperties: false,
|
|
138
138
|
},
|
|
139
139
|
};
|
|
140
|
+
const CONVERT_SCHEMA = {
|
|
141
|
+
name: "convert_result",
|
|
142
|
+
schema: {
|
|
143
|
+
type: "object",
|
|
144
|
+
properties: {
|
|
145
|
+
converted_code: {
|
|
146
|
+
type: "string",
|
|
147
|
+
description: "Converted code in target language/framework",
|
|
148
|
+
},
|
|
149
|
+
target_language: {
|
|
150
|
+
type: "string",
|
|
151
|
+
description: "Target language/framework",
|
|
152
|
+
},
|
|
153
|
+
conversion_notes: {
|
|
154
|
+
type: "string",
|
|
155
|
+
description: "Key decisions and idioms used in conversion",
|
|
156
|
+
},
|
|
157
|
+
breaking_changes: {
|
|
158
|
+
type: "array",
|
|
159
|
+
items: { type: "string" },
|
|
160
|
+
description: "List of breaking changes or manual steps required",
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
required: [
|
|
164
|
+
"converted_code",
|
|
165
|
+
"target_language",
|
|
166
|
+
"conversion_notes",
|
|
167
|
+
"breaking_changes",
|
|
168
|
+
],
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const ARCHITECT_SCHEMA = {
|
|
173
|
+
name: "architect_result",
|
|
174
|
+
schema: {
|
|
175
|
+
type: "object",
|
|
176
|
+
properties: {
|
|
177
|
+
design: {
|
|
178
|
+
type: "string",
|
|
179
|
+
description: "Proposed system design or architecture",
|
|
180
|
+
},
|
|
181
|
+
rationale: {
|
|
182
|
+
type: "string",
|
|
183
|
+
description: "Why this design was chosen",
|
|
184
|
+
},
|
|
185
|
+
tradeoffs: {
|
|
186
|
+
type: "array",
|
|
187
|
+
items: {
|
|
188
|
+
type: "object",
|
|
189
|
+
properties: {
|
|
190
|
+
aspect: { type: "string", description: "What is being traded off" },
|
|
191
|
+
chosen: { type: "string", description: "What was chosen" },
|
|
192
|
+
alternative: { type: "string", description: "What was rejected" },
|
|
193
|
+
reason: { type: "string", description: "Why this tradeoff" },
|
|
194
|
+
},
|
|
195
|
+
required: ["aspect", "chosen", "alternative", "reason"],
|
|
196
|
+
additionalProperties: false,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
implementation_steps: {
|
|
200
|
+
type: "array",
|
|
201
|
+
items: { type: "string" },
|
|
202
|
+
description: "High-level implementation roadmap",
|
|
203
|
+
},
|
|
204
|
+
risks: {
|
|
205
|
+
type: "array",
|
|
206
|
+
items: {
|
|
207
|
+
type: "object",
|
|
208
|
+
properties: {
|
|
209
|
+
risk: { type: "string", description: "What could go wrong" },
|
|
210
|
+
severity: {
|
|
211
|
+
type: "string",
|
|
212
|
+
enum: ["critical", "high", "medium", "low"],
|
|
213
|
+
},
|
|
214
|
+
mitigation: { type: "string", description: "How to address it" },
|
|
215
|
+
},
|
|
216
|
+
required: ["risk", "severity", "mitigation"],
|
|
217
|
+
additionalProperties: false,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
required: [
|
|
222
|
+
"design",
|
|
223
|
+
"rationale",
|
|
224
|
+
"tradeoffs",
|
|
225
|
+
"implementation_steps",
|
|
226
|
+
"risks",
|
|
227
|
+
],
|
|
228
|
+
additionalProperties: false,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
140
231
|
// --- Developer 指令(per-tool) ---
|
|
141
232
|
const INSTRUCTIONS = {
|
|
142
233
|
generate: [
|
|
143
|
-
"You are
|
|
234
|
+
"You are an expert software engineer with deep knowledge across multiple programming languages and paradigms.",
|
|
235
|
+
"",
|
|
236
|
+
"# Your Task",
|
|
237
|
+
"Generate production-ready, complete, and runnable code based on the user's requirements.",
|
|
144
238
|
"",
|
|
145
|
-
"
|
|
146
|
-
"-
|
|
147
|
-
"- Include necessary imports
|
|
148
|
-
"- Follow language
|
|
149
|
-
"- If project context is provided,
|
|
150
|
-
"
|
|
239
|
+
"# Critical Requirements",
|
|
240
|
+
"- Output ONLY valid, executable code with NO placeholders, TODOs, or comments like '// rest of implementation'",
|
|
241
|
+
"- Include ALL necessary imports, type definitions, and dependencies",
|
|
242
|
+
"- Follow the target language's idioms, conventions, and best practices",
|
|
243
|
+
"- If project context is provided, strictly adhere to its conventions and patterns",
|
|
244
|
+
"",
|
|
245
|
+
"# Code Quality Standards",
|
|
246
|
+
"- Prioritize: correctness > readability > performance",
|
|
247
|
+
"- Use descriptive variable/function names that reveal intent",
|
|
248
|
+
"- Handle edge cases and error conditions explicitly",
|
|
249
|
+
"- Prefer composition over inheritance, immutability over mutation",
|
|
250
|
+
"- Write self-documenting code; add comments ONLY for non-obvious logic",
|
|
251
|
+
"",
|
|
252
|
+
"# Output Format",
|
|
253
|
+
"Return a JSON object with these exact fields:",
|
|
254
|
+
"- code: Complete, runnable implementation",
|
|
255
|
+
"- language: Programming language used",
|
|
256
|
+
"- explanation: Brief rationale for key design decisions (2-3 sentences)",
|
|
257
|
+
"- dependencies: Array of required packages/imports (empty array if none)",
|
|
151
258
|
].join("\n"),
|
|
152
259
|
review: [
|
|
153
|
-
"You are a security
|
|
260
|
+
"You are a senior security engineer and code reviewer with expertise in identifying vulnerabilities, performance issues, and maintainability problems.",
|
|
261
|
+
"",
|
|
262
|
+
"# Your Task",
|
|
263
|
+
"Perform an independent, critical code review. Your goal is to find real issues that could cause problems in production.",
|
|
154
264
|
"",
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
"
|
|
265
|
+
"# Review Focus Areas",
|
|
266
|
+
"1. **Security**: SQL injection, XSS, CSRF, auth bypasses, insecure crypto, input validation",
|
|
267
|
+
"2. **Performance**: N+1 queries, memory leaks, inefficient algorithms, blocking operations",
|
|
268
|
+
"3. **Correctness**: Race conditions, off-by-one errors, null/undefined handling, edge cases",
|
|
269
|
+
"4. **Maintainability**: Code smells, tight coupling, poor naming, missing error handling",
|
|
270
|
+
"",
|
|
271
|
+
"# Severity Guidelines",
|
|
272
|
+
"- **critical**: Exploitable security vulnerability or data loss risk",
|
|
273
|
+
"- **high**: Likely production failure, significant performance degradation, or security weakness",
|
|
274
|
+
"- **medium**: Code smell that will cause maintenance burden or minor performance issue",
|
|
275
|
+
"- **low**: Style inconsistency or minor improvement opportunity",
|
|
276
|
+
"- **info**: Suggestion for enhancement, no actual problem",
|
|
277
|
+
"",
|
|
278
|
+
"# Scoring Rubric (0-100)",
|
|
279
|
+
"- 90-100: Production-ready, minimal issues",
|
|
280
|
+
"- 70-89: Good quality, minor improvements needed",
|
|
281
|
+
"- 50-69: Significant issues, needs refactoring before production",
|
|
282
|
+
"- 0-49: Critical flaws, unsafe for production",
|
|
283
|
+
"",
|
|
284
|
+
"# Critical Instructions",
|
|
285
|
+
"- Reference EXACT locations: line numbers, function names, or code snippets",
|
|
286
|
+
"- For each finding, provide a CONCRETE, actionable fix (not vague advice)",
|
|
287
|
+
"- Be honest: if code is clean, return empty findings array and high score",
|
|
288
|
+
"- Do NOT inflate scores or find issues that don't exist",
|
|
289
|
+
"- Prioritize findings by severity (critical first)",
|
|
290
|
+
"",
|
|
291
|
+
"# Output Format",
|
|
292
|
+
"Return a JSON object with these exact fields:",
|
|
293
|
+
"- findings: Array of {severity, category, location, issue, suggestion}",
|
|
294
|
+
"- summary: 1-2 sentence overall assessment",
|
|
295
|
+
"- score: Integer 0-100",
|
|
161
296
|
].join("\n"),
|
|
162
297
|
test: [
|
|
163
|
-
"You are a testing expert
|
|
298
|
+
"You are a testing expert who writes comprehensive test suites that catch real bugs before they reach production.",
|
|
299
|
+
"",
|
|
300
|
+
"# Your Task",
|
|
301
|
+
"Generate a complete, runnable test file that thoroughly validates the provided code.",
|
|
302
|
+
"",
|
|
303
|
+
"# Test Coverage Requirements",
|
|
304
|
+
"1. **Happy path**: Normal inputs, expected behavior",
|
|
305
|
+
"2. **Edge cases**: Boundary values (0, -1, MAX_INT, empty arrays, null/undefined)",
|
|
306
|
+
"3. **Error handling**: Invalid inputs, exceptions, network failures",
|
|
307
|
+
"4. **Integration**: Interactions with dependencies, side effects",
|
|
308
|
+
"",
|
|
309
|
+
"# Test Quality Standards",
|
|
310
|
+
"- Each test should verify ONE specific behavior",
|
|
311
|
+
"- Test names must clearly describe what is being tested and expected outcome",
|
|
312
|
+
"- Use the specified framework's idioms (describe/it, test(), etc.)",
|
|
313
|
+
"- Mock external dependencies (APIs, databases, file system)",
|
|
314
|
+
"- Include setup/teardown if needed for test isolation",
|
|
315
|
+
"- Think: 'What would break in production?' and test that",
|
|
316
|
+
"",
|
|
317
|
+
"# Critical Instructions",
|
|
318
|
+
"- Generate a COMPLETE test file that can be run immediately",
|
|
319
|
+
"- Include ALL necessary imports and setup",
|
|
320
|
+
"- Follow the project's testing conventions if provided",
|
|
321
|
+
"- Cover at least 80% of code paths",
|
|
322
|
+
"- Identify any gaps in coverage explicitly",
|
|
164
323
|
"",
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"-
|
|
168
|
-
"-
|
|
169
|
-
"-
|
|
170
|
-
"-
|
|
171
|
-
"-
|
|
324
|
+
"# Output Format",
|
|
325
|
+
"Return a JSON object with these exact fields:",
|
|
326
|
+
"- test_code: Complete, runnable test file",
|
|
327
|
+
"- language: Programming language",
|
|
328
|
+
"- framework: Test framework used",
|
|
329
|
+
"- test_cases: Array of {name, description, type} for each test",
|
|
330
|
+
"- coverage_notes: What is covered and what gaps remain (be honest)",
|
|
331
|
+
].join("\n"),
|
|
332
|
+
convert: [
|
|
333
|
+
"You are a polyglot engineer expert in cross-language/framework migrations, with deep knowledge of idioms and best practices across ecosystems.",
|
|
334
|
+
"",
|
|
335
|
+
"# Your Task",
|
|
336
|
+
"Convert code from source to target language/framework while preserving semantics and following target idioms.",
|
|
337
|
+
"",
|
|
338
|
+
"# Conversion Principles",
|
|
339
|
+
"1. **Semantic equivalence**: Preserve ALL functionality, edge cases, and error handling",
|
|
340
|
+
"2. **Idiomatic target code**: Use target language's standard library, patterns, and conventions",
|
|
341
|
+
"3. **No direct translation**: Don't just transliterate syntax; rethink using target paradigms",
|
|
342
|
+
"4. **Explicit tradeoffs**: If conversion goal conflicts with idioms, prioritize the goal",
|
|
343
|
+
"",
|
|
344
|
+
"# Common Pitfalls to Avoid",
|
|
345
|
+
"- Bringing source language patterns to target (e.g., Java-style classes in Python)",
|
|
346
|
+
"- Missing target language features (e.g., pattern matching, async/await)",
|
|
347
|
+
"- Ignoring target ecosystem conventions (e.g., PEP 8, Go error handling)",
|
|
348
|
+
"- Incomplete error handling translation",
|
|
349
|
+
"",
|
|
350
|
+
"# Breaking Changes",
|
|
351
|
+
"Document ANY changes that require manual intervention:",
|
|
352
|
+
"- API signature changes",
|
|
353
|
+
"- Dependency updates needed",
|
|
354
|
+
"- Configuration changes",
|
|
355
|
+
"- Data migration steps",
|
|
356
|
+
"",
|
|
357
|
+
"# Output Format",
|
|
358
|
+
"Return a JSON object with these exact fields:",
|
|
359
|
+
"- converted_code: Complete, idiomatic implementation in target language",
|
|
360
|
+
"- target_language: Target language/framework",
|
|
361
|
+
"- conversion_notes: Key decisions, idioms used, tradeoffs made (2-4 sentences)",
|
|
362
|
+
"- breaking_changes: Array of manual steps required (empty if none)",
|
|
363
|
+
].join("\n"),
|
|
364
|
+
architect: [
|
|
365
|
+
"You are a principal architect with 15+ years designing large-scale distributed systems. You make pragmatic decisions based on real-world constraints.",
|
|
366
|
+
"",
|
|
367
|
+
"# Your Task",
|
|
368
|
+
"Design a system architecture that balances competing requirements: scalability, reliability, cost, maintainability, and team capabilities.",
|
|
369
|
+
"",
|
|
370
|
+
"# Design Principles",
|
|
371
|
+
"1. **Start simple**: Choose the simplest design that meets requirements; add complexity only when justified",
|
|
372
|
+
"2. **Explicit tradeoffs**: Every architectural decision sacrifices something; state what you're optimizing for and what you're giving up",
|
|
373
|
+
"3. **Concrete over abstract**: Provide specific technologies, patterns, and implementation approaches",
|
|
374
|
+
"4. **Risk-aware**: Identify what could go wrong and how to mitigate it",
|
|
375
|
+
"5. **Implementable**: Design must be achievable by the team with stated constraints",
|
|
376
|
+
"",
|
|
377
|
+
"# Tradeoff Analysis Framework",
|
|
378
|
+
"For each major decision, explicitly state:",
|
|
379
|
+
"- What you chose and why",
|
|
380
|
+
"- What you rejected and why",
|
|
381
|
+
"- What you're optimizing for (e.g., developer velocity, cost, reliability)",
|
|
382
|
+
"- What you're sacrificing (e.g., consistency, simplicity, performance)",
|
|
383
|
+
"",
|
|
384
|
+
"# Risk Assessment",
|
|
385
|
+
"Identify risks with:",
|
|
386
|
+
"- **critical**: System failure, data loss, security breach",
|
|
387
|
+
"- **high**: Significant downtime, performance degradation, cost overrun",
|
|
388
|
+
"- **medium**: Maintenance burden, technical debt, team friction",
|
|
389
|
+
"- **low**: Minor inconvenience, future refactoring needed",
|
|
390
|
+
"",
|
|
391
|
+
"# Critical Instructions",
|
|
392
|
+
"- Provide CONCRETE design: specific technologies, not 'use a database'",
|
|
393
|
+
"- Break implementation into logical phases (MVP → iteration)",
|
|
394
|
+
"- Consider team size, budget, and existing infrastructure",
|
|
395
|
+
"- If requirements conflict, state which takes priority and why",
|
|
396
|
+
"- Be honest about limitations and unknowns",
|
|
397
|
+
"",
|
|
398
|
+
"# Output Format",
|
|
399
|
+
"Return a JSON object with these exact fields:",
|
|
400
|
+
"- design: Detailed system architecture (components, data flow, technologies)",
|
|
401
|
+
"- rationale: Why this design over alternatives (2-4 sentences)",
|
|
402
|
+
"- tradeoffs: Array of {aspect, chosen, alternative, reason}",
|
|
403
|
+
"- implementation_steps: Ordered list of phases/milestones",
|
|
404
|
+
"- risks: Array of {risk, severity, mitigation}",
|
|
172
405
|
].join("\n"),
|
|
173
406
|
};
|
|
174
407
|
// --- 输入构建 ---
|
|
@@ -211,6 +444,26 @@ function formatTestOutput(parsed) {
|
|
|
211
444
|
.join("\n");
|
|
212
445
|
return `\`\`\`${parsed.language}\n${parsed.test_code}\n\`\`\`\n\n**Framework:** ${parsed.framework}\n**Test Cases (${parsed.test_cases.length}):**\n${cases}\n\n**Coverage:** ${parsed.coverage_notes}`;
|
|
213
446
|
}
|
|
447
|
+
function formatConvertOutput(parsed) {
|
|
448
|
+
let text = `\`\`\`${parsed.target_language}\n${parsed.converted_code}\n\`\`\``;
|
|
449
|
+
text += `\n\n**Conversion Notes:** ${parsed.conversion_notes}`;
|
|
450
|
+
if (parsed.breaking_changes.length > 0) {
|
|
451
|
+
text += `\n\n**Breaking Changes:**\n${parsed.breaking_changes.map((c) => `- ${c}`).join("\n")}`;
|
|
452
|
+
}
|
|
453
|
+
return text;
|
|
454
|
+
}
|
|
455
|
+
function formatArchitectOutput(parsed) {
|
|
456
|
+
const tradeoffs = parsed.tradeoffs
|
|
457
|
+
.map((t) => `**${t.aspect}:** Chose "${t.chosen}" over "${t.alternative}"\n Reason: ${t.reason}`)
|
|
458
|
+
.join("\n\n");
|
|
459
|
+
const steps = parsed.implementation_steps
|
|
460
|
+
.map((s, i) => `${i + 1}. ${s}`)
|
|
461
|
+
.join("\n");
|
|
462
|
+
const risks = parsed.risks
|
|
463
|
+
.map((r) => `- **[${r.severity.toUpperCase()}]** ${r.risk}\n Mitigation: ${r.mitigation}`)
|
|
464
|
+
.join("\n\n");
|
|
465
|
+
return `## Design\n\n${parsed.design}\n\n## Rationale\n\n${parsed.rationale}\n\n## Tradeoffs\n\n${tradeoffs}\n\n## Implementation Steps\n\n${steps}\n\n## Risks\n\n${risks}`;
|
|
466
|
+
}
|
|
214
467
|
// --- MCP Server ---
|
|
215
468
|
const server = new Server({ name: "codex-mcp-server", version: "2.0.0" }, { capabilities: { tools: {} } });
|
|
216
469
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
@@ -229,12 +482,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
229
482
|
"Reference Files": files,
|
|
230
483
|
"Conversation Context": conversation_context,
|
|
231
484
|
});
|
|
232
|
-
const
|
|
485
|
+
const result = await codexClient.request({
|
|
233
486
|
instructions: INSTRUCTIONS.generate,
|
|
234
487
|
input,
|
|
235
488
|
jsonSchema: GENERATE_SCHEMA,
|
|
236
489
|
});
|
|
237
|
-
const parsed = safeJsonParse(
|
|
490
|
+
const parsed = safeJsonParse(result.text);
|
|
238
491
|
if (parsed && typeof parsed.code === "string") {
|
|
239
492
|
return {
|
|
240
493
|
content: [
|
|
@@ -246,7 +499,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
246
499
|
};
|
|
247
500
|
}
|
|
248
501
|
// Fallback:API 不支持结构化输出时直接返回原文
|
|
249
|
-
return { content: [{ type: "text", text:
|
|
502
|
+
return { content: [{ type: "text", text: result.text }] };
|
|
250
503
|
}
|
|
251
504
|
case "codex_review": {
|
|
252
505
|
const { code, language, focus, project_context, conversation_context } = args;
|
|
@@ -257,13 +510,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
257
510
|
"Project Context": project_context,
|
|
258
511
|
"Review Context": conversation_context,
|
|
259
512
|
});
|
|
260
|
-
const
|
|
513
|
+
const result = await codexClient.request({
|
|
261
514
|
instructions: INSTRUCTIONS.review,
|
|
262
515
|
input,
|
|
263
516
|
jsonSchema: REVIEW_SCHEMA,
|
|
264
517
|
reasoningEffort: "high",
|
|
265
518
|
});
|
|
266
|
-
const parsed = safeJsonParse(
|
|
519
|
+
const parsed = safeJsonParse(result.text);
|
|
267
520
|
if (parsed && Array.isArray(parsed.findings)) {
|
|
268
521
|
return {
|
|
269
522
|
content: [
|
|
@@ -274,7 +527,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
274
527
|
],
|
|
275
528
|
};
|
|
276
529
|
}
|
|
277
|
-
return { content: [{ type: "text", text:
|
|
530
|
+
return { content: [{ type: "text", text: result.text }] };
|
|
278
531
|
}
|
|
279
532
|
case "codex_test": {
|
|
280
533
|
const { code, language, framework, project_context, conversation_context, } = args;
|
|
@@ -285,13 +538,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
285
538
|
"Project Context": project_context,
|
|
286
539
|
Context: conversation_context,
|
|
287
540
|
});
|
|
288
|
-
const
|
|
541
|
+
const result = await codexClient.request({
|
|
289
542
|
instructions: INSTRUCTIONS.test,
|
|
290
543
|
input,
|
|
291
544
|
jsonSchema: TEST_SCHEMA,
|
|
292
545
|
reasoningEffort: "high",
|
|
293
546
|
});
|
|
294
|
-
const parsed = safeJsonParse(
|
|
547
|
+
const parsed = safeJsonParse(result.text);
|
|
295
548
|
if (parsed && typeof parsed.test_code === "string") {
|
|
296
549
|
return {
|
|
297
550
|
content: [
|
|
@@ -302,7 +555,64 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
302
555
|
],
|
|
303
556
|
};
|
|
304
557
|
}
|
|
305
|
-
return { content: [{ type: "text", text:
|
|
558
|
+
return { content: [{ type: "text", text: result.text }] };
|
|
559
|
+
}
|
|
560
|
+
case "codex_convert": {
|
|
561
|
+
const { code, source_language, target_language, conversion_goal, project_context, conversation_context, } = args;
|
|
562
|
+
const input = buildInput({
|
|
563
|
+
"Source Code": `\`\`\`${source_language}\n${code}\n\`\`\``,
|
|
564
|
+
"Source Language": source_language,
|
|
565
|
+
"Target Language": target_language,
|
|
566
|
+
"Conversion Goal": conversion_goal,
|
|
567
|
+
"Project Context": project_context,
|
|
568
|
+
"Conversion Context": conversation_context,
|
|
569
|
+
});
|
|
570
|
+
const result = await codexClient.request({
|
|
571
|
+
instructions: INSTRUCTIONS.convert,
|
|
572
|
+
input,
|
|
573
|
+
jsonSchema: CONVERT_SCHEMA,
|
|
574
|
+
reasoningEffort: "high",
|
|
575
|
+
});
|
|
576
|
+
const parsed = safeJsonParse(result.text);
|
|
577
|
+
if (parsed && typeof parsed.converted_code === "string") {
|
|
578
|
+
return {
|
|
579
|
+
content: [
|
|
580
|
+
{
|
|
581
|
+
type: "text",
|
|
582
|
+
text: formatConvertOutput(parsed),
|
|
583
|
+
},
|
|
584
|
+
],
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
return { content: [{ type: "text", text: result.text }] };
|
|
588
|
+
}
|
|
589
|
+
case "codex_architect": {
|
|
590
|
+
const { requirements, constraints, design_question, existing_system, conversation_context, } = args;
|
|
591
|
+
const input = buildInput({
|
|
592
|
+
Requirements: requirements,
|
|
593
|
+
Constraints: constraints,
|
|
594
|
+
"Design Question": design_question,
|
|
595
|
+
"Existing System": existing_system,
|
|
596
|
+
Context: conversation_context,
|
|
597
|
+
});
|
|
598
|
+
const result = await codexClient.request({
|
|
599
|
+
instructions: INSTRUCTIONS.architect,
|
|
600
|
+
input,
|
|
601
|
+
jsonSchema: ARCHITECT_SCHEMA,
|
|
602
|
+
reasoningEffort: "xhigh",
|
|
603
|
+
});
|
|
604
|
+
const parsed = safeJsonParse(result.text);
|
|
605
|
+
if (parsed && typeof parsed.design === "string") {
|
|
606
|
+
return {
|
|
607
|
+
content: [
|
|
608
|
+
{
|
|
609
|
+
type: "text",
|
|
610
|
+
text: formatArchitectOutput(parsed),
|
|
611
|
+
},
|
|
612
|
+
],
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
return { content: [{ type: "text", text: result.text }] };
|
|
306
616
|
}
|
|
307
617
|
default:
|
|
308
618
|
throw new Error(`Unknown tool: ${name}`);
|
package/dist/tools.d.ts
CHANGED
|
@@ -27,6 +27,13 @@ export declare const tools: ({
|
|
|
27
27
|
code?: undefined;
|
|
28
28
|
focus?: undefined;
|
|
29
29
|
framework?: undefined;
|
|
30
|
+
source_language?: undefined;
|
|
31
|
+
target_language?: undefined;
|
|
32
|
+
conversion_goal?: undefined;
|
|
33
|
+
requirements?: undefined;
|
|
34
|
+
constraints?: undefined;
|
|
35
|
+
design_question?: undefined;
|
|
36
|
+
existing_system?: undefined;
|
|
30
37
|
};
|
|
31
38
|
required: string[];
|
|
32
39
|
};
|
|
@@ -60,6 +67,13 @@ export declare const tools: ({
|
|
|
60
67
|
prompt?: undefined;
|
|
61
68
|
files?: undefined;
|
|
62
69
|
framework?: undefined;
|
|
70
|
+
source_language?: undefined;
|
|
71
|
+
target_language?: undefined;
|
|
72
|
+
conversion_goal?: undefined;
|
|
73
|
+
requirements?: undefined;
|
|
74
|
+
constraints?: undefined;
|
|
75
|
+
design_question?: undefined;
|
|
76
|
+
existing_system?: undefined;
|
|
63
77
|
};
|
|
64
78
|
required: string[];
|
|
65
79
|
};
|
|
@@ -92,6 +106,94 @@ export declare const tools: ({
|
|
|
92
106
|
prompt?: undefined;
|
|
93
107
|
files?: undefined;
|
|
94
108
|
focus?: undefined;
|
|
109
|
+
source_language?: undefined;
|
|
110
|
+
target_language?: undefined;
|
|
111
|
+
conversion_goal?: undefined;
|
|
112
|
+
requirements?: undefined;
|
|
113
|
+
constraints?: undefined;
|
|
114
|
+
design_question?: undefined;
|
|
115
|
+
existing_system?: undefined;
|
|
116
|
+
};
|
|
117
|
+
required: string[];
|
|
118
|
+
};
|
|
119
|
+
} | {
|
|
120
|
+
name: string;
|
|
121
|
+
description: string;
|
|
122
|
+
inputSchema: {
|
|
123
|
+
type: "object";
|
|
124
|
+
properties: {
|
|
125
|
+
code: {
|
|
126
|
+
type: string;
|
|
127
|
+
description: string;
|
|
128
|
+
};
|
|
129
|
+
source_language: {
|
|
130
|
+
type: string;
|
|
131
|
+
description: string;
|
|
132
|
+
};
|
|
133
|
+
target_language: {
|
|
134
|
+
type: string;
|
|
135
|
+
description: string;
|
|
136
|
+
};
|
|
137
|
+
conversion_goal: {
|
|
138
|
+
type: string;
|
|
139
|
+
description: string;
|
|
140
|
+
};
|
|
141
|
+
project_context: {
|
|
142
|
+
type: string;
|
|
143
|
+
description: string;
|
|
144
|
+
};
|
|
145
|
+
conversation_context: {
|
|
146
|
+
type: string;
|
|
147
|
+
description: string;
|
|
148
|
+
};
|
|
149
|
+
prompt?: undefined;
|
|
150
|
+
language?: undefined;
|
|
151
|
+
files?: undefined;
|
|
152
|
+
focus?: undefined;
|
|
153
|
+
framework?: undefined;
|
|
154
|
+
requirements?: undefined;
|
|
155
|
+
constraints?: undefined;
|
|
156
|
+
design_question?: undefined;
|
|
157
|
+
existing_system?: undefined;
|
|
158
|
+
};
|
|
159
|
+
required: string[];
|
|
160
|
+
};
|
|
161
|
+
} | {
|
|
162
|
+
name: string;
|
|
163
|
+
description: string;
|
|
164
|
+
inputSchema: {
|
|
165
|
+
type: "object";
|
|
166
|
+
properties: {
|
|
167
|
+
requirements: {
|
|
168
|
+
type: string;
|
|
169
|
+
description: string;
|
|
170
|
+
};
|
|
171
|
+
constraints: {
|
|
172
|
+
type: string;
|
|
173
|
+
description: string;
|
|
174
|
+
};
|
|
175
|
+
design_question: {
|
|
176
|
+
type: string;
|
|
177
|
+
description: string;
|
|
178
|
+
};
|
|
179
|
+
existing_system: {
|
|
180
|
+
type: string;
|
|
181
|
+
description: string;
|
|
182
|
+
};
|
|
183
|
+
conversation_context: {
|
|
184
|
+
type: string;
|
|
185
|
+
description: string;
|
|
186
|
+
};
|
|
187
|
+
prompt?: undefined;
|
|
188
|
+
language?: undefined;
|
|
189
|
+
project_context?: undefined;
|
|
190
|
+
files?: undefined;
|
|
191
|
+
code?: undefined;
|
|
192
|
+
focus?: undefined;
|
|
193
|
+
framework?: undefined;
|
|
194
|
+
source_language?: undefined;
|
|
195
|
+
target_language?: undefined;
|
|
196
|
+
conversion_goal?: undefined;
|
|
95
197
|
};
|
|
96
198
|
required: string[];
|
|
97
199
|
};
|
package/dist/tools.js
CHANGED
|
@@ -127,4 +127,93 @@ export const tools = [
|
|
|
127
127
|
required: ["code"],
|
|
128
128
|
},
|
|
129
129
|
},
|
|
130
|
+
{
|
|
131
|
+
name: "codex_convert",
|
|
132
|
+
description: [
|
|
133
|
+
"Convert code between languages, frameworks, or architectural patterns using deep reasoning.",
|
|
134
|
+
"",
|
|
135
|
+
"Returns structured JSON: { converted_code, target_language, conversion_notes, breaking_changes }",
|
|
136
|
+
"",
|
|
137
|
+
"When to use:",
|
|
138
|
+
"- Language migration (Python→Rust, JavaScript→TypeScript, Go→Zig)",
|
|
139
|
+
"- Framework migration (REST→GraphQL, React→Vue, Express→Fastify)",
|
|
140
|
+
"- Pattern migration (callbacks→async/await, class→functional)",
|
|
141
|
+
"- API version upgrades with breaking changes",
|
|
142
|
+
"",
|
|
143
|
+
"Do NOT use for simple syntax translation — use native tools or simple prompts.",
|
|
144
|
+
].join("\n"),
|
|
145
|
+
inputSchema: {
|
|
146
|
+
type: "object",
|
|
147
|
+
properties: {
|
|
148
|
+
code: {
|
|
149
|
+
type: "string",
|
|
150
|
+
description: "Source code to convert.",
|
|
151
|
+
},
|
|
152
|
+
source_language: {
|
|
153
|
+
type: "string",
|
|
154
|
+
description: "Source language/framework (e.g., python, react, rest-api).",
|
|
155
|
+
},
|
|
156
|
+
target_language: {
|
|
157
|
+
type: "string",
|
|
158
|
+
description: "Target language/framework (e.g., rust, vue, graphql).",
|
|
159
|
+
},
|
|
160
|
+
conversion_goal: {
|
|
161
|
+
type: "string",
|
|
162
|
+
description: "What to preserve/optimize during conversion (e.g., 'maintain API compatibility', 'optimize for performance', 'idiomatic target language').",
|
|
163
|
+
},
|
|
164
|
+
project_context: {
|
|
165
|
+
type: "string",
|
|
166
|
+
description: "Target project conventions, dependencies, constraints.",
|
|
167
|
+
},
|
|
168
|
+
conversation_context: {
|
|
169
|
+
type: "string",
|
|
170
|
+
description: "Why this conversion is needed, migration strategy.",
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
required: ["code", "source_language", "target_language"],
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "codex_architect",
|
|
178
|
+
description: [
|
|
179
|
+
"System design and architectural decision-making with deep reasoning.",
|
|
180
|
+
"",
|
|
181
|
+
"Returns structured JSON: { design, rationale, tradeoffs, implementation_steps, risks }",
|
|
182
|
+
"",
|
|
183
|
+
"When to use:",
|
|
184
|
+
"- Designing system architecture from requirements",
|
|
185
|
+
"- Choosing between architectural patterns (microservices vs monolith, event-driven vs request-response)",
|
|
186
|
+
"- Data modeling and schema design",
|
|
187
|
+
"- Technology stack selection with tradeoff analysis",
|
|
188
|
+
"- Scalability and performance architecture",
|
|
189
|
+
"",
|
|
190
|
+
"Do NOT use for implementation details — use codex_generate for that.",
|
|
191
|
+
].join("\n"),
|
|
192
|
+
inputSchema: {
|
|
193
|
+
type: "object",
|
|
194
|
+
properties: {
|
|
195
|
+
requirements: {
|
|
196
|
+
type: "string",
|
|
197
|
+
description: "System requirements: functional requirements, non-functional requirements (scale, performance, reliability).",
|
|
198
|
+
},
|
|
199
|
+
constraints: {
|
|
200
|
+
type: "string",
|
|
201
|
+
description: "Technical constraints: budget, team size, existing infrastructure, compliance requirements.",
|
|
202
|
+
},
|
|
203
|
+
design_question: {
|
|
204
|
+
type: "string",
|
|
205
|
+
description: "Specific architectural question or decision to make (e.g., 'Should we use microservices?', 'How to handle real-time updates?').",
|
|
206
|
+
},
|
|
207
|
+
existing_system: {
|
|
208
|
+
type: "string",
|
|
209
|
+
description: "Current system architecture if this is a migration or evolution.",
|
|
210
|
+
},
|
|
211
|
+
conversation_context: {
|
|
212
|
+
type: "string",
|
|
213
|
+
description: "Previous architectural discussions, decisions made, options considered.",
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
required: ["requirements"],
|
|
217
|
+
},
|
|
218
|
+
},
|
|
130
219
|
];
|