Skip to main content
Glama

write_file

Create new files or overwrite existing files with specified content at designated file paths. Handles text content with proper encoding for file management operations.

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

  • The handler logic for the 'write_file' tool. It parses the path and content from the request arguments, ensures the parent directory exists by creating it if necessary, writes the content to the file using fs.writeFile, and returns a success 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}`, }, ], }; }
  • The schema definition for the 'write_file' tool, including name, description, and input schema specifying required 'path' and 'content' string parameters.
    { 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"], }, },
  • src/index.ts:261-263 (registration)
    Registration of the tool list handler, which returns the TOOLS array containing the 'write_file' tool definition to clients querying available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: 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