Skip to main content
Glama

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
NameRequiredDescriptionDefault
contentYesContent to write to the file
pathYesPath to the file to write

Implementation Reference

  • Schema definition (TypeScript interface) for the input arguments of the write_file MCP tool.
    export interface WriteFileArgs { filePath: string; content: string; encoding?: string; }
  • 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), }; } }
  • 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 }, }; }

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/tosin2013/mcp-adr-analysis-server'

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