heal_code
Apply AI-suggested fixes to code issues by loading source files and generating repair prompts for automated correction.
Instructions
Load a file's source code and prepare a repair prompt for the AI agent. The agent (you) should then apply the fix based on the issue description and suggestion. Returns the file content along with the repair context.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path to heal | |
| issue | Yes | Issue description to fix | |
| suggestion | No | Suggested fix from OCR scan |
Implementation Reference
- The main logic for the heal_code tool, which reads the specified file and constructs a prompt for an AI agent to fix the identified issue.
export async function handleHealCode(args: z.infer<typeof healCodeSchema>) { const filePath = resolve(args.path); let content: string; try { content = await readFile(filePath, "utf-8"); } catch { return { content: [ { type: "text" as const, text: JSON.stringify({ error: `Cannot read file: ${filePath}`, suggestion: "Check the file path and ensure it exists.", }, null, 2), }, ], isError: true, }; } return { content: [ { type: "text" as const, text: JSON.stringify({ file: filePath, issue: args.issue, suggestion: args.suggestion ?? null, code: content, instructions: `You are an expert code repair assistant. The file "${args.path}" contains the following issue detected by Open Code Review:\n\n**Issue:** ${args.issue}\n${args.suggestion ? `**Suggestion:** ${args.suggestion}\n` : ""}\n\nPlease analyze the code below and provide the fixed version. Only output the corrected code, preserving the original structure and style.`, }, null, 2), }, ], }; } - Zod schema definition for the arguments accepted by the heal_code tool.
export const healCodeSchema = z.object({ path: z.string().describe("File path to heal"), issue: z.string().describe("Issue description to fix"), suggestion: z.string().optional().describe("Suggested fix from OCR scan"), }); - packages/mcp-server/src/server.ts:143-146 (registration)Tool execution registration in the MCP server's request handler, mapping the "heal_code" name to the handleHealCode function.
case "heal_code": { const parsed = healCodeSchema.parse(args); return handleHealCode(parsed); }