Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

append_to_file

Add content to the end of a file, with optional newline insertion, for file management operations within directory contexts.

Instructions

Append content to the end of a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesFile path relative to working directory
contentYesContent to append
newline_beforeNoAdd newline before appending

Implementation Reference

  • The main handler function for 'append_to_file' tool. Reads existing file content if it exists, optionally adds a newline before appending new content, writes the updated content back to the file, and returns a success message.
    async handleAppendToFile(args) {
      const { path: filePath, content, newline_before = true } = args;
      const fullPath = path.resolve(this.workingDirectory, filePath);
      
      try {
        // Check if file exists
        let existingContent = '';
        try {
          existingContent = await fs.readFile(fullPath, 'utf8');
        } catch (error) {
          // File doesn't exist, will be created
        }
        
        // Prepare content to append
        let finalContent = existingContent;
        if (existingContent && newline_before && !existingContent.endsWith('\n')) {
          finalContent += '\n';
        }
        finalContent += content;
        
        // Write file
        await fs.writeFile(fullPath, finalContent, 'utf8');
        
        return {
          content: [
            {
              type: 'text',
              text: `Content appended to file: ${filePath}`,
            },
          ],
        };
      } catch (error) {
        throw new McpError(ErrorCode.InternalError, `Failed to append to file: ${error.message}`);
      }
    }
  • Input schema definition for the 'append_to_file' tool, specifying parameters: path (required), content (required), and newline_before (optional boolean with default true).
    inputSchema: {
      type: 'object',
      properties: {
        path: {
          type: 'string',
          description: 'File path relative to working directory',
        },
        content: {
          type: 'string',
          description: 'Content to append',
        },
        newline_before: {
          type: 'boolean',
          description: 'Add newline before appending',
          default: true,
        },
      },
      required: ['path', 'content'],
    },
  • server.js:479-480 (registration)
    Switch case in the tool call handler that registers and dispatches 'append_to_file' calls to the handleAppendToFile method.
    case 'append_to_file':
      return await this.handleAppendToFile(args);
  • server.js:253-275 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for 'append_to_file'.
    {
      name: 'append_to_file',
      description: 'Append content to the end of a file',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'File path relative to working directory',
          },
          content: {
            type: 'string',
            description: 'Content to append',
          },
          newline_before: {
            type: 'boolean',
            description: 'Add newline before appending',
            default: true,
          },
        },
        required: ['path', 'content'],
      },
    },
  • Usage of handleAppendToFile in the batch_file_operations tool for 'append' operation.
    result = await this.handleAppendToFile(params);
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'append' implies a non-destructive write operation, it doesn't specify permissions needed, whether it creates files if they don't exist, encoding considerations, or what happens on failure. The description lacks crucial behavioral context for a file mutation tool.

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, clear sentence with zero wasted words. It's front-loaded with the core functionality and appropriately sized for the tool's complexity. Every word earns its place.

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

Completeness2/5

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

For a file mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what happens on success/failure, return values, error conditions, or how it differs from sibling tools. The description should provide more context given the tool's potential side effects.

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?

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline score of 3 reflects adequate schema coverage without description enhancement.

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 clearly states the action ('append content') and target ('to the end of a file'), which is specific and unambiguous. However, it doesn't distinguish this tool from its sibling 'update_file' or explain how appending differs from other file modification operations.

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 like 'update_file' or 'create_file'. There's no mention of prerequisites (e.g., file must exist), error conditions, or typical use cases for appending versus other file operations.

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/PWalaGov/File-Control-MCP'

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