Skip to main content
Glama

editFile

Modify or create files by specifying the file path and new content using Claude Code MCP's file editing tool.

Instructions

Create or edit a file

Input Schema

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

Implementation Reference

  • Registers the 'editFile' tool on the MCP server, including input schema (file_path and content), description, and inline handler that uses writeFile utility to update the file and returns appropriate response.
    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 }; } } );
  • Inline handler function for the editFile tool. It writes the provided content to the specified file path using the writeFile helper and returns a success message 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 schema defining the input parameters for the editFile tool: absolute 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") },
  • Helper function that implements the core file editing logic by writing the given content to the specified file path 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; } }

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

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