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
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | The absolute path to the file to edit | |
| content | Yes | The new content for the file |
Implementation Reference
- src/server/tools.ts:213-231 (handler)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 }; } }
- src/server/tools.ts:209-212 (schema)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") },
- src/server/tools.ts:206-232 (registration)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 }; } } );
- src/utils/file.ts:112-121 (helper)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; } }