apply_all_fixes
Apply all fixes from the last security audit in a single transaction, rolling back on any failure. Optionally filter by minimum severity and preview before confirming.
Instructions
Bulk-apply all SQL fixes from last audit, optionally filtered by severity. Wraps everything in a single transaction — if any statement fails, everything rolls back. Always preview the count and list before confirming.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_ref | Yes | ||
| severity_min | No | Minimum severity to apply (default 'high'). Use 'critical' for safest. | high |
| confirm | Yes | Must be true to actually apply. |
Implementation Reference
- src/server.js:169-178 (registration)Registration of the 'apply_all_fixes' tool as an MCP tool via server.registerTool(). The tool is called 'apply_all_fixes' and accepts three parameters: project_ref (string), severity_min (enum with default 'high'), and confirm (boolean).
server.registerTool( "apply_all_fixes", { description: "Bulk-apply all SQL fixes from last audit, optionally filtered by severity. Wraps everything in a single transaction — if any statement fails, everything rolls back. Always preview the count and list before confirming.", inputSchema: { project_ref: z.string(), severity_min: z.enum(["critical", "high", "medium", "low", "info"]).default("high").describe("Minimum severity to apply (default 'high'). Use 'critical' for safest."), confirm: z.boolean().describe("Must be true to actually apply."), }, }, - src/server.js:172-178 (schema)Input schema (Zod) for apply_all_fixes: project_ref (string), severity_min (enum with default 'high'), confirm (boolean).
description: "Bulk-apply all SQL fixes from last audit, optionally filtered by severity. Wraps everything in a single transaction — if any statement fails, everything rolls back. Always preview the count and list before confirming.", inputSchema: { project_ref: z.string(), severity_min: z.enum(["critical", "high", "medium", "low", "info"]).default("high").describe("Minimum severity to apply (default 'high'). Use 'critical' for safest."), confirm: z.boolean().describe("Must be true to actually apply."), }, }, - src/server.js:179-217 (handler)Handler function for apply_all_fixes. Retrieves cached audit results, filters findings by severity_min (excluding Dashboard-only fixes without SQL), and if confirm=true, runs all eligible fix SQLs in a single BEGIN/COMMIT transaction. On failure, the transaction is rolled back. After success, re-audits the project and updates the cache.
async ({ project_ref, severity_min, confirm }) => { const c = cache.get(project_ref); if (!c) return { content: [{ type: "text", text: `No cached audit. Run audit_project first.` }], isError: true }; const order = { critical: 0, high: 1, medium: 2, low: 3, info: 4 }; const minLevel = order[severity_min]; const eligible = c.result.findings.filter( (f) => order[f.severity] <= minLevel && f.fix_sql.split("\n").some((l) => l.trim() && !l.trim().startsWith("--")) ); if (eligible.length === 0) { return { content: [{ type: "text", text: `No SQL-applicable findings at severity ${severity_min} or higher.` }] }; } if (!confirm) { return { content: [ { type: "text", text: `${eligible.length} fix(es) eligible at severity >= ${severity_min}. Set confirm=true to apply.` }, { type: "text", text: eligible.map((f, i) => `${i + 1}. [${f.severity.toUpperCase()}] ${f.title} — ${f.target}`).join("\n") }, ], }; } const allSql = eligible.map((f) => `-- ${f.title} (${f.target})\n${f.fix_sql}`).join("\n\n"); try { await sql(c.token, project_ref, `BEGIN;\n${allSql}\nCOMMIT;`); const fresh = await audit(c.token, project_ref); cache.set(project_ref, { result: fresh, ts: Date.now(), token: c.token }); return { content: [ { type: "text", text: `Applied ${eligible.length} fix(es) in one transaction. New summary: ${shortSummary(fresh)}` }, ], }; } catch (e) { return { content: [{ type: "text", text: `Bulk apply FAILED: ${e.message}\n\nTransaction rolled back. Project state unchanged.` }], isError: true }; } } );