Skip to main content
Glama

editFile

Create or modify files by specifying a path and content, enabling direct file operations through the Claude Code MCP server.

Instructions

Create or edit a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesThe absolute path to the file to edit
contentYesThe new content for the file

Implementation Reference

  • The handler function for the 'editFile' tool that takes file_path and content, writes the content to the file using writeFile utility, and returns a success or error response.
    async ({ file_path, content }) => {
      try {
        await writeFile(file_path, content);
        return {
          content: [{ 
            type: "text", 
            text: `File ${file_path} has been updated.`
          }]
        };
      } catch (error) {
        return {
          content: [{ 
            type: "text", 
            text: error instanceof Error ? error.message : String(error)
          }],
          isError: true
        };
      }
    }
  • Zod input schema defining parameters for the 'editFile' tool: file_path (string) and content (string).
    {
      file_path: z.string().describe("The absolute path to the file to edit"),
      content: z.string().describe("The new content for the file")
    },
  • Registration of the 'editFile' tool on the MCP server using server.tool(), including description, schema, and inline handler.
    server.tool(
      "editFile",
      "Create or edit a file",
      {
        file_path: z.string().describe("The absolute path to the file to edit"),
        content: z.string().describe("The new content for the file")
      },
      async ({ file_path, content }) => {
        try {
          await writeFile(file_path, content);
          return {
            content: [{ 
              type: "text", 
              text: `File ${file_path} has been updated.`
            }]
          };
        } catch (error) {
          return {
            content: [{ 
              type: "text", 
              text: error instanceof Error ? error.message : String(error)
            }],
            isError: true
          };
        }
      }
    );
  • Supporting utility function writeFile that performs the file system write operation using Node.js fs.promises.writeFile.
    export async function writeFile(
      filePath: string,
      content: string
    ): Promise<void> {
      try {
        await fs.writeFile(filePath, content, 'utf-8');
      } catch (error) {
        throw error;
      }
    }
Behavior2/5

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

With no annotations, the description carries full burden but only states the operation without behavioral details. It doesn't disclose whether this overwrites existing files, requires specific permissions, handles errors, or has side effects like creating directories. The vague 'create or edit' leaves critical behavior ambiguous.

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

Conciseness5/5

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

The description is extremely concise with just three words, front-loaded and zero waste. Every word earns its place by conveying the core action and resource efficiently.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavior, error handling, or output format, leaving significant gaps for an agent to use it correctly in context with siblings.

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 fully documents both parameters ('file_path' and 'content'). The description adds no additional meaning beyond implying these parameters are used for the operation, meeting the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose with specific verbs ('create or edit') and resource ('a file'), making it immediately understandable. However, it doesn't differentiate from sibling tools like 'readFile' or 'listFiles' beyond the basic operation type.

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?

No guidance is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., file permissions), when editing is preferred over creating, or how it relates to siblings like 'readFile' for viewing or 'bash' for file operations.

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

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

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