Skip to main content
Glama

Repair CAD Script

repair_script
Idempotent

Use this when evaluate_script reported an error and you want the fix applied rather than described. Takes the candidates why_did_this_fail derives for a diagnostic, applies them one at a time, re-evaluates after each, and keeps the first that clears the diagnostic without introducing new errors. Never edits outside the repair region (failing feature statement + its input statements + the param() lines it reads) — an out-of-region patch is refused with tool.repair.out-of-region. Returns the repaired source in new_code (the caller persists it), a unified diff, and before/after health maps. Pass { file? | code?, diagnostic?: ''|'first-error', strategy?: 'apply-first'|'try-all'|'dry-run', max_attempts?: number }.

Input Schema

NameRequiredDescriptionDefault
codeNoInline kernelCAD script source.
fileNoPath to a .kcad.ts script file. Hosted server: cannot read files from your machine — pass `code`, or `project:<slug>` for a saved project.
intentNoThe user's request in one sentence, in the user's own words and language (e.g. 'M4 bracket for a 25 mm tube, print on Bambu A1'). Helps kernelCAD improve; leave out personal data.
strategyNo'try-all' (default) walks candidates until one clears the diagnostic; 'apply-first' applies only the top candidate and reports what it did; 'dry-run' previews every candidate patch without evaluating.
diagnosticNoDiagnostic id from why_did_this_fail's `targetDiagnosticId` / `candidates[].diagnosticId`, or 'first-error' (default) for the first error-severity diagnostic.
max_attemptsNoUpper bound on candidates attempted (default 3). Ignored by apply-first and dry-run.

Output Schema

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changed
    • removedOutput schema / properties
      Removed value: -{
      -  "after": {
      -    "additionalProperties": true,
      -    "description": "Post-repair { ok, featureHealth, diagnostics }.",
      -    "type": "object"
      -  },
      -  "applied": {
      -    "description": "Candidate id that was accepted.",
      -    "type": "string"
      -  },
      -  "attempts": {
      -    "description": "Per-candidate outcome { candidateId, applied, ok?, clearedDiagnostic?, newErrorCodes?, accepted, diagnostic? }.",
      -    "items": {
      -      "additionalProperties": true,
      -      "type": "object"
      -    },
      -    "type": "array"
      -  },
      -  "before": {
      -    "additionalProperties": true,
      -    "description": "Pre-repair { ok, featureHealth, diagnostics }.",
      -    "type": "object"
      -  },
      -  "candidateReason": {
      -    "type": "string"
      -  },
      -  "candidateStatus": {
      -    "enum": [
      -      "candidates",
      -      "no-automatic-candidate"
      -    ],
      -    "type": "string"
      -  },
      -  "candidates": {
      -    "items": {
      -      "additionalProperties": true,
      -      "type": "object"
      -    },
      -    "type": "array"
      -  },
      -  "diagnostics": {
      -    "description": "tool.repair.* diagnostics when repair could not complete.",
      -    "items": {
      -      "additionalProperties": true,
      -      "type": "object"
      -    },
      -    "type": "array"
      -  },
      -  "diff": {
      -    "description": "Unified diff of the accepted patch (dry run: every candidate patch).",
      -    "type": "string"
      -  },
      -  "error": {
      -    "type": "string"
      -  },
      -  "errorCode": {
      -    "type": "string"
      -  },
      -  "new_code": {
      -    "description": "Repaired .kcad.ts source (present when a patch applied). Caller persists it.",
      -    "type": "string"
      -  },
      -  "ok": {
      -    "description": "Whether a candidate cleared the target diagnostic without new errors.",
      -    "type": "boolean"
      -  },
      -  "repairRegion": {
      -    "additionalProperties": true,
      -    "description": "The line ranges the repair was bound to.",
      -    "type": "object"
      -  },
      -  "strategy": {
      -    "enum": [
      -      "apply-first",
      -      "try-all",
      -      "dry-run"
      -    ],
      -    "type": "string"
      -  },
      -  "target": {
      -    "additionalProperties": true,
      -    "description": "The diagnostic this run targeted { id, code, featureId?, message }.",
      -    "type": "object"
      -  }
      -}
    • removedOutput schema / required
      Removed value: -[
      -  "ok",
      -  "strategy",
      -  "candidates",
      -  "attempts"
      -]
  2. Changed1 schema field changed
    • addedInput schema / properties / intent
      Added value: +{
      +  "description": "The user's request in one sentence, in the user's own words and language (e.g. 'M4 bracket for a 25 mm tube, print on Bambu A1'). Helps kernelCAD improve; leave out personal data.",
      +  "maxLength": 2000,
      +  "type": "string"
      +}
  3. Changed1 schema field changed
    • changedInput schema / properties / file / description
      Previous value: -"Path to a .kcad.ts script file."New value: +"Path to a .kcad.ts script file. Hosted server: cannot read files from your machine — pass `code`, or `project:<slug>` for a saved project."
  4. Added

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the annotations: it discloses the iteration policy (apply candidates one at a time, re-evaluate, keep the first that clears without new errors), the hard scope limit (never edits outside the failing statement + inputs + param() lines), a specific refusal signal (tool.repair.out-of-region), and the fact that the caller is responsible for persisting new_code. That last point resolves what readOnlyHint=false actually means here — the tool computes, it does not save.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the routing condition, then the mechanism, then constraints and return shape — good ordering. It is dense but every early sentence earns its place; the closing "Pass { file? | code?, ... }" list is the one redundant part given full schema coverage.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Even though an output schema exists, it summarizes the return (new_code, diff, before/after health maps) and states the persistence contract, which the schema alone would not convey. For a mutating, retry-driven tool with six optional parameters, nothing an agent needs to call it safely is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already carries all six parameters including the file/code alternatives, the strategy enum values, and diagnostic id format. The description's trailing brace-list largely restates the schema; its only increment is clarifying that `diagnostic` comes from why_did_this_fail's ids, which the schema also says. Baseline 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource (repair a CAD script) and immediately distinguishes itself from evaluate_script and why_did_this_fail by framing itself as the tool that applies a fix rather than describing one. An agent can route between the three without opening any schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

"Use this when evaluate_script reported an error and you want the fix applied rather than described" gives both the trigger condition and the exclusion (wanting a description instead routes to why_did_this_fail). It also names the upstream dependency whose output it consumes (candidates from why_did_this_fail), so the call ordering is explicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.