write_file
Store content in a specified file by providing the path and content as input, enabling structured data storage for architectural decision records.
Instructions
Write content to a file
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/types/tool-arguments.ts:183-187 (schema)Schema definition (TypeScript interface) for the input arguments of the write_file MCP tool.export interface WriteFileArgs { filePath: string; content: string; encoding?: string; }
- src/utils/file-system.ts:406-446 (helper)Core helper function that performs the actual file writing operation, ensuring parent directory exists, handling errors, and returning structured result. Matches WriteFileArgs signature (encoding optional not used). Used internally by other MCP tools.export async function writeFile( filePath: string, content: string ): Promise<{ success: boolean; filePath: string; written: boolean; error?: string; metadata?: { size: number; directoryCreated: boolean; }; }> { try { const resolvedPath = path.resolve(filePath); const dir = path.dirname(resolvedPath); // Ensure directory exists const dirResult = await ensureDirectory(dir); // Write file await fs.writeFile(resolvedPath, content, 'utf-8'); return { success: true, filePath, written: true, metadata: { size: Buffer.byteLength(content, 'utf-8'), directoryCreated: dirResult.created, }, }; } catch (error) { return { success: false, filePath, written: false, error: error instanceof Error ? error.message : String(error), }; } }
- src/utils/file-system.ts:900-914 (helper)Compatibility wrapper for writeFile that returns MCP-style response (prompt, instructions, context) for backward compatibility with prompt-based tools.export async function writeFileCompat(filePath: string, content: string): Promise<any> { const result = await writeFile(filePath, content); const prompt = `File write operation: ${filePath} Result: ${result.written ? 'File written successfully' : 'File write failed'} Size: ${result.metadata?.size || 0} bytes`; const instructions = 'File was written using Node.js fs.writeFile'; return { ...result, prompt, instructions, context: { filePath, contentSize: content.length }, }; }