Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesFile path to heal
issueYesIssue description to fix
suggestionNoSuggested 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"),
    });
  • 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);
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/raye-deng/open-code-review'

If you have feedback or need assistance with the MCP directory API, please join our Discord server