Skip to main content
Glama

Enhanced Directory Context MCP Server

by PWalaGov

create_file

Generates a new file at a specified path with given content, supporting customizable encoding and optional overwrite functionality on the Enhanced Directory Context MCP Server.

Instructions

Create a new file with specified content

Input Schema

NameRequiredDescriptionDefault
contentYesContent to write to the file
encodingNoFile encoding (default: utf8)utf8
overwriteNoOverwrite if file already exists
pathYesFile path relative to working directory

Input Schema (JSON Schema)

{ "properties": { "content": { "description": "Content to write to the file", "type": "string" }, "encoding": { "default": "utf8", "description": "File encoding (default: utf8)", "type": "string" }, "overwrite": { "default": false, "description": "Overwrite if file already exists", "type": "boolean" }, "path": { "description": "File path relative to working directory", "type": "string" } }, "required": [ "path", "content" ], "type": "object" }

Implementation Reference

  • Main execution logic for the 'create_file' tool: destructures args, resolves full path, checks existence and overwrite flag, creates parent directory if needed, writes content using fs.writeFile, returns success message or throws McpError.
    async handleCreateFile(args) { const { path: filePath, content, encoding = 'utf8', overwrite = false } = args; const fullPath = path.resolve(this.workingDirectory, filePath); try { // Check if file exists try { await fs.access(fullPath); if (!overwrite) { throw new Error('File already exists. Set overwrite=true to replace it.'); } } catch (error) { // File doesn't exist, which is what we want } // Ensure directory exists const dir = path.dirname(fullPath); await fs.mkdir(dir, { recursive: true }); // Write file await fs.writeFile(fullPath, content, encoding); return { content: [ { type: 'text', text: `File created successfully: ${filePath}`, }, ], }; } catch (error) { throw new McpError(ErrorCode.InternalError, `Failed to create file: ${error.message}`); } }
  • JSON Schema defining input parameters for create_file tool: path (string, required), content (string, required), encoding (string, default 'utf8'), overwrite (boolean, default false).
    inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'File path relative to working directory', }, content: { type: 'string', description: 'Content to write to the file', }, encoding: { type: 'string', description: 'File encoding (default: utf8)', default: 'utf8', }, overwrite: { type: 'boolean', description: 'Overwrite if file already exists', default: false, }, }, required: ['path', 'content'], },
  • server.js:473-474 (registration)
    Tool dispatch/registration in the CallToolRequestSchema switch statement: maps 'create_file' tool name to this.handleCreateFile handler.
    case 'create_file': return await this.handleCreateFile(args);
  • server.js:178-205 (registration)
    Tool metadata registration: name, description, and full inputSchema included in the tools list returned by ListToolsRequestHandler.
    { name: 'create_file', description: 'Create a new file with specified content', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'File path relative to working directory', }, content: { type: 'string', description: 'Content to write to the file', }, encoding: { type: 'string', description: 'File encoding (default: utf8)', default: 'utf8', }, overwrite: { type: 'boolean', description: 'Overwrite if file already exists', default: false, }, }, required: ['path', 'content'], }, },

Other Tools

Related 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