Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

create_file

Create new files with specified content and encoding in your project directory. Set file paths, write content, and control overwrite behavior for organized file management.

Instructions

Create a new file with specified content

Input Schema

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

Implementation Reference

  • The handler function that implements the create_file tool logic: destructures args, resolves full path, checks if file exists and handles overwrite, ensures parent directory exists, writes the content to the file, and returns success message.
    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}`); } }
  • Input schema defining the parameters for the create_file tool: path (required), content (required), encoding (optional), overwrite (optional).
    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:179-205 (registration)
    Tool registration in the ListTools response: defines name, description, and input schema for client discovery.
    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'], }, },
  • server.js:473-474 (registration)
    Dispatcher registration in CallToolRequestSchema handler: switch case that routes 'create_file' calls to the handleCreateFile method.
    case 'create_file': return await this.handleCreateFile(args);

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