Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

refactor(mcp): reuse parsed artifact tool inputs (#1224)

mldangelo-oaif870200d6de5
diff --git a/plugins/codex-security/mcp-app/src/server/compact-artifact-tools.ts b/plugins/codex-security/mcp-app/src/server/compact-artifact-tools.ts
index 121359c1c..4e1902a8f 100644
--- a/plugins/codex-security/mcp-app/src/server/compact-artifact-tools.ts
+++ b/plugins/codex-security/mcp-app/src/server/compact-artifact-tools.ts
@@ -41,7 +41,6 @@ import {
recordCodexSecurityScanDraftViaWorkbench,
recordCodexSecurityWorkerScanDraft,
scanDraftInputSchema,
- type ScanDraftInput,
} from "../artifact-scan-draft.js";
import {
@@ -92,8 +91,7 @@ export function registerReviewItemTools(
description: "Generate the changed-file inventory for a diff scan.",
inputSchema: prepareReviewItemsInputSchema,
readOnly: false,
- handler: async (value, requestContext) => {
- const input = prepareReviewItemsInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return prepareCodexSecurityReviewItems(
await phaseScanContext(input, options, requestContext, "diff"),
);
@@ -106,8 +104,7 @@ export function registerReviewItemTools(
description: "Read one page of the diff or Deep scan discovery inventory.",
inputSchema: reviewItemsReaderInputSchema,
readOnly: true,
- handler: async (value, requestContext) => {
- const input = reviewItemsReaderInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return listCodexSecurityReviewItems(
await phaseScanContext(input, options, requestContext),
input,
@@ -130,8 +127,7 @@ export function registerDiscoveryCandidateTools(
description: "Normalize and replace the selected diff scan's candidates.",
inputSchema: writerSchema,
readOnly: false,
- handler: async (value, requestContext) => {
- const input = writerSchema.parse(value);
+ handler: async (input, requestContext) => {
return recordCodexSecurityDiscoveryCandidates(
{ candidates: input.candidates },
await phaseScanContext(input, options, requestContext, "diff"),
@@ -145,8 +141,7 @@ export function registerDiscoveryCandidateTools(
description: "Read one page of diff or Deep scan discovery candidates.",
inputSchema: readerSchema,
readOnly: true,
- handler: async (value, requestContext) => {
- const input = readerSchema.parse(value);
+ handler: async (input, requestContext) => {
return listCodexSecurityCandidates(
{
...(input.cursor === undefined ? {} : { cursor: input.cursor }),
@@ -169,8 +164,7 @@ export function registerCandidateValidationTools(
description: "Record the diff or Deep scan candidate validation results.",
inputSchema: candidateValidationsInputSchema,
readOnly: false,
- handler: async (value, requestContext) => {
- const input = candidateValidationsInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return recordCodexSecurityCandidateValidations(
await phaseScanContext(input, options, requestContext),
{ validations: input.validations },
@@ -190,8 +184,7 @@ export function registerCandidateAttackPathTools(
description: "Record the diff or Deep scan candidate attack-path results.",
inputSchema: candidateAttackPathsInputSchema,
readOnly: false,
- handler: async (value, requestContext) => {
- const input = candidateAttackPathsInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return recordCodexSecurityCandidateAttackPaths(
await phaseScanContext(input, options, requestContext),
{ attackPaths: input.attackPaths },
@@ -212,8 +205,7 @@ export function registerScanDraftTools(
"Save the canonical threat model, findings and coverage as an unsealed draft. Use complete:false as soon as a model is available, even with empty findings and partial coverage, then for progress checkpoints; use complete:true for the final result. The host derives threatmodel.md. Keep unvalidated candidates in coverage.deferred. On terminal Standard or diff drafts, close generic review tasks with coverage.resolvedDeferred:[{id,reason}], copying IDs from the returned coverage. Update linked surfaces by their saved IDs.",
inputSchema: scanDraftInputSchema,
readOnly: false,
- handler: async (value, requestContext) => {
- const input = scanDraftInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return recordCodexSecurityScanDraftViaWorkbench(
await scanContext(input, options, true, requestContext),
input,
@@ -230,8 +222,7 @@ export function registerScanDraftTools(
"Read the selected scan's existing completed, sealed canonical documents.",
inputSchema: completedScanInputSchema,
readOnly: true,
- handler: async (value, requestContext) => {
- const input = completedScanInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return getCodexSecurityCompletedScan(
await scanContext(input, options, false, requestContext),
input,
@@ -265,8 +256,7 @@ export function registerCompactArtifactTools(
"Save a supplemental document or evidence file with temporary or persistent storage. Use scanId for a running scan, or targetPath for standalone documents and shared threat models. Omit path/content/sourcePath to prepare and return the selected directory. Otherwise provide a portable relative path under artifacts/, findings/ or hardening/ (or threatmodel.md for a standalone model) and either exact text content or a sourcePath inside the returned temporary directory. Scan threatmodel.md is host-generated from semantic drafts; canonical scan files and recovery checkpoints use the existing typed scan tools. Does not edit completed scans or source/configuration files.",
inputSchema: saveArtifactInputSchema,
readOnly: false,
- handler: async (value, requestContext) => {
- const input = saveArtifactInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return saveCodexSecurityArtifact(
await supplementalContext(input, options, true, requestContext),
input,
@@ -281,8 +271,7 @@ export function registerCompactArtifactTools(
"Read a saved supplemental artifact from temporary or persistent storage, including after an MCP restart. Use the same scanId or standalone targetPath, storage and relative path used to save it. A scan's host-generated model is threatmodel.md; standalone legacy threat_model.md remains readable.",
inputSchema: readArtifactInputSchema,
readOnly: true,
- handler: async (value, requestContext) => {
- const input = readArtifactInputSchema.parse(value);
+ handler: async (input, requestContext) => {
return readCodexSecurityArtifact(
await supplementalContext(input, options, false, requestContext),
input,
@@ -334,7 +323,7 @@ export function registerCompactWorkerArtifactTools(
inputSchema: scanDraftInputSchema,
readOnly: false,
handler: async (value) =>
- recordCodexSecurityWorkerScanDraft(context, value as ScanDraftInput),
+ recordCodexSecurityWorkerScanDraft(context, value),
});
return;
}
@@ -373,18 +362,18 @@ export function registerCompactWorkerArtifactTools(
});
}
-interface CompactToolRegistration {
+interface CompactToolRegistration<Input> {
name: string;
title: string;
description: string;
- inputSchema: ZodType;
+ inputSchema: ZodType<Input>;
readOnly: boolean;
- handler: (value: unknown, requestContext: unknown) => Promise<object>;
+ handler: (value: Input, requestContext: unknown) => Promise<object>;
}
-function registerCompactTool(
+function registerCompactTool<Input>(
server: McpServer,
- registration: CompactToolRegistration,
+ registration: CompactToolRegistration<Input>,
): void {
server.registerTool(
registration.name,
@@ -397,7 +386,7 @@ function registerCompactTool(
: writingAnnotations,
_meta: modelOnlyMeta,
},
- async (input: unknown, requestContext: unknown) => {
+ async (input, requestContext) => {
const value = await registration.handler(input, requestContext);
return {
content: [{ type: "text" as const, text: JSON.stringify(value) }],