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']
      }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: file creation if non-existent, overwriting if existent, and parent directory creation. However, it lacks details on permissions, error handling, or response format, which are important for a write operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise and front-loaded with the core functionality in the first sentence. Every sentence adds value: the first states the primary action, the second clarifies creation/overwrite behavior, and the third adds directory creation capability. Zero waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a file write tool with no annotations and no output schema, the description adequately covers basic behavior but lacks completeness. It doesn't address error conditions, permissions, return values, or encoding implications, which are important for proper tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, providing clear details for all parameters. The description adds minimal value beyond the schema, only implicitly referencing 'createDirs' through 'Can create parent directories'. No additional semantic context is provided for parameters like encoding options.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Write content to a file') and resource ('a file'), distinguishing it from sibling tools like fs_append_file (which appends) and fs_read_file (which reads). It also specifies the creation behavior for new files and overwriting for existing ones.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for writing file content, but does not explicitly state when to use this tool versus alternatives like fs_append_file (for appending) or fs_move_file (for moving). It mentions the ability to create parent directories, which provides some context for directory creation scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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