Skip to main content
Glama
KunihiroS

claude-code-mcp

edit_code

Modifies existing code according to specific instructions, enabling developers to adapt and refine scripts efficiently. Use this tool to implement changes directly based on clear, actionable guidance.

Instructions

Edits the given code based on instructions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesCode to edit
instructionsYesEditing instructions

Implementation Reference

  • The main handler function for the 'edit_code' tool. It destructures the input arguments (code and instructions), encodes the code to base64 using a helper, truncates if too long, constructs a specific prompt for Claude to edit the code, calls the shared runClaudeCommand helper to execute Claude CLI, and returns the generated output as text content.
    case 'edit_code': {
      const { code, instructions } = args;
      logger.debug(`Processing edit_code request, code length: ${code.length}`);
      const encodedCode = encodeText(truncateIfNeeded(code));
      logger.debug(`Code encoded to base64, length: ${encodedCode.length}`);
      const prompt = `You are super professional engineer. Please edit the following Base64 encoded code according to the instructions provided:\n\nCode:\n${encodedCode}\n\nInstructions:\n${instructions ?? 'No specific instructions provided.'}`;
      logger.debug('Calling Claude CLI with prompt');
      const output = await runClaudeCommand(['--print'], prompt);
      logger.debug(`Received response from Claude, length: ${output.length}`);
      return { content: [{ type: 'text', text: output }] };
    }
  • Registration of the 'edit_code' tool in the ListTools response, including its name, description, and input schema definition.
    {
      name: 'edit_code',
      description: 'Edits the given code based on instructions.',
      inputSchema: {
        type: 'object',
        properties: {
          code: { type: 'string', description: 'Code to edit' },
          instructions: { type: 'string', description: 'Editing instructions' }
        },
        required: ['code', 'instructions']
      }
    },
  • Input schema for the 'edit_code' tool, defining the expected parameters: code (string) and instructions (string), both required.
      inputSchema: {
        type: 'object',
        properties: {
          code: { type: 'string', description: 'Code to edit' },
          instructions: { type: 'string', description: 'Editing instructions' }
        },
        required: ['code', 'instructions']
      }
    },
  • Helper functions for base64 encoding/decoding of text, used in the edit_code handler to encode the input code before passing to Claude.
    function encodeText(text: string): string {
        return Buffer.from(text, 'utf8').toString('base64');
    }
    
    function decodeText(encoded: string): string {
        return Buffer.from(encoded, 'base64').toString('utf8');
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool edits code but doesn't explain how—whether it's a direct mutation, requires permissions, has side effects, or what the output looks like. For a tool that modifies code without annotations, this leaves critical behavioral traits unspecified.

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?

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized for a simple tool, though it could be more front-loaded with key details. There's no wasted language, making it concise.

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

Completeness2/5

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

Given the complexity of editing code, lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like mutation safety, error handling, or result format, which are essential for an agent to use this tool correctly. The description fails to compensate for the missing structured data.

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?

The input schema has 100% description coverage, with clear documentation for both parameters ('code' and 'instructions'). The description adds no additional meaning beyond what the schema provides, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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

Purpose3/5

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

The description states the tool's purpose as editing code based on instructions, which is clear but vague. It specifies the verb ('edits') and resource ('code'), but doesn't distinguish it from sibling tools like 'fix_code' or 'review_code' that might also modify code. The purpose is understandable but lacks specificity about what type of editing it performs.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'fix_code', 'review_code', and 'explain_code', there's no indication whether this is for general code modifications, bug fixes, or something else. No prerequisites, exclusions, or comparative context are mentioned.

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

Install Server

Other Tools

Related Tools

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/KunihiroS/claude-code-mcp'

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