Skip to main content
Glama
koopatroopa787

MCP PC Control Server

write_file

Create new files or replace existing ones by writing text content to specified paths. This tool handles file creation and overwriting with proper text encoding for PC file management.

Instructions

Create a new file or completely overwrite an existing file with new content. Use with caution as it will overwrite existing files without warning. Handles text content with proper encoding.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe path where the file should be written
contentYesThe content to write to the file

Implementation Reference

  • Handler for the 'write_file' tool. Parses arguments for file path and content, ensures the parent directory exists using fs.mkdir, writes the content to the file with UTF-8 encoding using fs.writeFile, and returns a success confirmation message.
    case "write_file": {
      const filePath = args.path as string;
      const content = args.content as string;
    
      // Ensure directory exists
      const dir = path.dirname(filePath);
      await fs.mkdir(dir, { recursive: true });
    
      await fs.writeFile(filePath, content, "utf-8");
      return {
        content: [
          {
            type: "text",
            text: `Successfully wrote to ${filePath}`,
          },
        ],
      };
    }
  • Input schema for the 'write_file' tool defining required string parameters 'path' (file location) and 'content' (text to write). Used for validation in tool calls.
    inputSchema: {
      type: "object",
      properties: {
        path: {
          type: "string",
          description: "The path where the file should be written",
        },
        content: {
          type: "string",
          description: "The content to write to the file",
        },
      },
      required: ["path", "content"],
    },
  • src/index.ts:34-51 (registration)
    Registration of the 'write_file' tool in the TOOLS array. This Tool object (name, description, inputSchema) is returned by the ListTools handler, making the tool discoverable to MCP clients.
    {
      name: "write_file",
      description: "Create a new file or completely overwrite an existing file with new content. Use with caution as it will overwrite existing files without warning. Handles text content with proper encoding.",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "The path where the file should be written",
          },
          content: {
            type: "string",
            description: "The content to write to the file",
          },
        },
        required: ["path", "content"],
      },
    },
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing critical behavioral traits: it's destructive ('overwrite existing files without warning'), handles text content with encoding, and implies mutation. It lacks details on permissions, error handling, or response format, but covers the core safety concern adequately.

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 front-loaded with the core purpose, followed by a warning and technical detail. Every sentence earns its place: the first defines the action, the second warns of risks, and the third adds encoding context. It's appropriately sized with zero waste.

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

Completeness4/5

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

Given the tool's complexity (destructive write operation) and lack of annotations or output schema, the description is mostly complete: it covers purpose, risks, and content handling. It could improve by mentioning response format or error cases, but it provides sufficient context for safe use.

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 both parameters (path and content). The description adds no additional meaning beyond what the schema provides, such as path format examples or content constraints. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('create a new file or completely overwrite an existing file') and resource ('file'), distinguishing it from siblings like edit_file (partial updates) and read_file (read-only). It precisely defines the tool's scope and behavior.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context with 'Use with caution as it will overwrite existing files without warning,' indicating when to be careful. However, it does not explicitly mention alternatives like edit_file for partial updates or when to choose this over create_directory for directories, leaving some sibling differentiation implicit.

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/koopatroopa787/first_mcp'

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