Skip to main content
Glama

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"], }, },

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