Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

fs_write_file

Write content to files with automatic directory creation and file overwriting capabilities for development workflows.

Instructions

Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Can create parent directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute or relative path to the file to write
contentYesContent to write to the file
encodingNoFile encodingutf8
createDirsNoCreate parent directories if they don't exist

Implementation Reference

  • The handler function that executes the fs_write_file tool: validates args with writeFileSchema, creates parent dirs if specified, writes content to file using fs.promises.writeFile, returns success/error JSON.
    export async function writeFile(args: z.infer<typeof writeFileSchema>): Promise<ToolResponse> { try { // Create parent directories if needed if (args.createDirs) { const dir = path.dirname(args.path); await fs.mkdir(dir, { recursive: true }); } await fs.writeFile(args.path, args.content, args.encoding as BufferEncoding); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, path: args.path, bytesWritten: args.content.length }, null, 2) } ] }; } catch (error) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }, null, 2) } ], isError: true }; } }
  • Zod input schema for fs_write_file tool used for validation in handler and dispatch.
    export const writeFileSchema = z.object({ path: z.string().describe('Absolute or relative path to the file to write'), content: z.string().describe('Content to write to the file'), encoding: z.enum(['utf8', 'binary', 'base64']).default('utf8').describe('File encoding'), createDirs: z.boolean().default(true).describe('Create parent directories if they don\'t exist')
  • src/index.ts:309-311 (registration)
    Registration and dispatch logic in the main MCP server request handler: parses args with writeFileSchema and calls the writeFile handler.
    if (name === 'fs_write_file') { const validated = writeFileSchema.parse(args); return await writeFile(validated);
  • MCP tool definition including name, description, and inline inputSchema for fs_write_file.
    { name: 'fs_write_file', description: 'Write content to a file. Creates the file if it doesn\'t exist, overwrites if it does. Can create parent directories.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Absolute or relative path to the file to write' }, content: { type: 'string', description: 'Content to write to the file' }, encoding: { type: 'string', enum: ['utf8', 'binary', 'base64'], default: 'utf8', description: 'File encoding' }, createDirs: { type: 'boolean', default: true, description: 'Create parent directories if they don\'t exist' } }, required: ['path', 'content'] }

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/ConnorBoetig-dev/mcp2'

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