Skip to main content
Glama

Enhanced Directory Context MCP Server

by PWalaGov

append_to_file

Add specified content to the end of a file, optionally inserting a newline before appending. Supports file management within the Enhanced Directory Context MCP Server.

Instructions

Append content to the end of a file

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "content": { "description": "Content to append", "type": "string" }, "newline_before": { "default": true, "description": "Add newline before appending", "type": "boolean" }, "path": { "description": "File path relative to working directory", "type": "string" } }, "required": [ "path", "content" ], "type": "object" }

Implementation Reference

  • The core handler function for the 'append_to_file' tool. It resolves the file path, reads existing content if any, conditionally adds a newline, appends the new content, writes 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)
    Dispatcher case in the CallToolRequestSchema handler that routes '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 ListToolsRequestSchema response, including name, description, and full input schema.
    { 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 within the batch_file_operations tool handler for 'append' operations.
    result = await this.handleAppendToFile(params);

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