write_file
Create or overwrite a file by specifying the file path and content using the Filesystem MCP Server, enabling secure file management and modification.
Instructions
Create new file or overwrite existing
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content to write to the file | |
| path | Yes | Path to the file to write |
Implementation Reference
- src/index.ts:280-299 (handler)Handler for the 'write_file' tool. Extracts path and content, validates path, ensures parent directory exists, writes file using fs.writeFile, returns success message.case 'write_file': { const { path: filePath, content } = request.params.arguments as { path: string; content: string }; validatePath(filePath); // Ensure parent directory exists await fs.ensureDir(path.dirname(filePath)); await fs.writeFile(filePath, content, 'utf8'); return { content: [ { type: 'text', text: `File written successfully: ${filePath}`, }, ], }; }
- src/index.ts:126-143 (registration)Tool registration in listTools handler, defining name, description, and input schema for 'write_file'.{ name: 'write_file', description: 'Create new file or overwrite existing', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file to write', }, content: { type: 'string', description: 'Content to write to the file', }, }, required: ['path', 'content'], }, },