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);
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. It states it creates a file but doesn't mention permissions needed, error conditions (e.g., if path is invalid), or what happens on failure. For a write operation, this leaves significant gaps in understanding its behavior.

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, efficient sentence that directly states the tool's function without unnecessary words. It's front-loaded and wastes no space, making it easy to parse quickly.

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 creation tool with no annotations and no output schema, the description is insufficient. It doesn't explain return values, error handling, or interaction with sibling tools like 'overwrite' behavior implications. Given the complexity of file operations, more context is needed.

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 parameters are fully documented in the schema. The description adds no additional semantic context beyond implying 'content' is written, which the schema already covers. This meets the baseline for high schema coverage.

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 ('Create') and resource ('a new file with specified content'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'update_file' or 'append_to_file' which also modify files, so it doesn't reach the highest score.

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 'append_to_file'. It doesn't mention prerequisites, constraints, or typical use cases, leaving the agent with no contextual decision-making help.

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