Skip to main content
Glama

write_file

DestructiveIdempotent

Write content to files using specified paths and encoding options to manage file data.

Instructions

Write content to a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to write
contentYesContent to write to the file
encodingNoEncoding to use when writing the file (default: utf8)

Implementation Reference

  • Generic handler for all MCP tools/call requests. Validates tool name (including 'write_file'), retrieves tool metadata, and provides placeholder execution (to be replaced with actual logic).
    /**
     * Handles the tools/call request
     */
    private async handleToolsCall(params: { name: string, arguments?: any }): Promise<CallToolResult> {
      const { name, arguments: args } = params;
      
      if (!name) {
        throw new Error('Tool name is required');
      }
      
      const tool = this.tools.get(name);
      
      if (!tool) {
        throw new Error(`Tool not found: ${name}`);
      }
      
      // In a real implementation, we would execute the tool here
      // For now, we'll just return a placeholder
      
      return {
        content: [
          {
            type: 'text',
            text: `Executed tool ${name} with arguments: ${JSON.stringify(args)}`
          } as TextContent
        ]
      };
    }
  • src/index.ts:161-188 (registration)
    Registers the 'write_file' MCP tool on the server with full schema definition, description, and annotations.
    mcpServer.registerTool({
      name: 'write_file',
      description: 'Write content to a file',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to write'
          },
          content: {
            type: 'string',
            description: 'Content to write to the file'
          },
          encoding: {
            type: 'string',
            description: 'Encoding to use when writing the file (default: utf8)'
          }
        },
        required: ['path', 'content']
      },
      annotations: {
        readOnlyHint: false,
        destructiveHint: true,
        idempotentHint: true,
        openWorldHint: false
      }
    });
  • Input schema definition for the 'write_file' tool specifying path, content, and optional encoding.
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to write'
          },
          content: {
            type: 'string',
            description: 'Content to write to the file'
          },
          encoding: {
            type: 'string',
            description: 'Encoding to use when writing the file (default: utf8)'
          }
        },
        required: ['path', 'content']
      },
      annotations: {
        readOnlyHint: false,
        destructiveHint: true,
        idempotentHint: true,
        openWorldHint: false
      }
    });
  • FileSystemManager.writeFile method: core implementation for writing file content, ensuring directory exists, using promisified fs.writeFile, and emitting change events.
    public async writeFile(filePath: string, content: string, encoding: BufferEncoding = 'utf8'): Promise<void> {
      try {
        // Ensure the directory exists
        await this.ensureDirectoryExists(path.dirname(filePath));
        await writeFile(filePath, content, { encoding });
        this.emitChangeEvent('update', filePath);
      } catch (error: any) {
        throw new Error(`Failed to write file ${filePath}: ${error.message}`);
      }
    }
Behavior4/5

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

Annotations indicate this is a destructive, non-read-only, non-open-world, idempotent operation. The description adds value by specifying 'write content to a file', which implies mutation and potential overwriting, aligning with the destructive hint. However, it does not elaborate on details like file creation if non-existent or error handling, leaving some behavioral aspects uncovered.

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 a single, front-loaded sentence ('Write content to a file') that efficiently conveys the core action without unnecessary words. Every part earns its place, making it highly concise and well-structured for quick understanding.

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?

Given the tool's complexity as a destructive write operation with no output schema, the description is minimally adequate. It covers the basic action but lacks details on return values, error cases, or interactions with siblings, leaving gaps in completeness for safe agent 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?

With 100% schema description coverage, the input schema fully documents parameters like 'path', 'content', and 'encoding' with default values. The description does not add any semantic details beyond this, such as path format examples or encoding options, so it meets the baseline without compensating further.

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

Purpose4/5

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

The description 'Write content to a file' clearly states the verb ('write') and resource ('file'), making the purpose immediately understandable. However, it does not differentiate from sibling tools like 'backup_and_edit' or 'interactive_edit_session', which might also involve writing to files, so it lacks sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention scenarios like overwriting existing files, creating new ones, or when to prefer other tools like 'backup_and_edit' for safer edits, leaving usage context implied at best.

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/mixelpixx/edit-mcp'

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