Skip to main content
Glama
falahgs

3D Cartoon Generator & File System MCP Server

by falahgs

write_file

Write content to a specific file path. Provide the file path and content to create or overwrite a file on the local system.

Instructions

Write content to a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to write
contentYesContent to write to the file

Implementation Reference

  • The handler function for the 'write_file' tool. It validates the path using validatePath(), writes the file content to disk using fsPromises.writeFile() with UTF-8 encoding, and returns a success result.
    case "write_file": {
      const validPath = await validatePath(args.path);
      await fsPromises.writeFile(validPath, args.content, "utf-8");
      return {
        toolResult: {
          success: true,
          content: [{ type: "text", text: `File written successfully to: ${args.path}` }],
          message: `File saved to: ${args.path}`
        }
      };
  • src/index.ts:315-330 (registration)
    Registration of the 'write_file' tool in the ListToolsRequestSchema handler. Defines the tool name, description, and inputSchema with 'path' and 'content' string properties, both required.
    name: "write_file",
    description: "Write content to a file",
    inputSchema: {
      type: "object",
      properties: {
        path: {
          type: "string",
          description: "Path to the file to write"
        },
        content: {
          type: "string",
          description: "Content to write to the file"
        }
      },
      required: ["path", "content"]
    }
  • The validatePath() async function used by the write_file handler to ensure the requested path is within allowed directories and handles symlink security.
    async function validatePath(requestedPath: string): Promise<string> {
      const expandedPath = expandHome(requestedPath);
      const absolute = path.isAbsolute(expandedPath)
        ? path.resolve(expandedPath)
        : path.resolve(process.cwd(), expandedPath);
    
      const normalizedRequested = normalizePath(absolute);
    
      // Check if path is within allowed directories
      const isAllowed = allowedDirectories.some(dir => normalizedRequested.startsWith(dir));
      if (!isAllowed) {
        throw new Error(`Access denied - path outside allowed directories: ${absolute} not in ${allowedDirectories.join(', ')}`);
      }
    
      // Handle symlinks by checking their real path
      try {
        const realPath = await fsPromises.realpath(absolute);
        const normalizedReal = normalizePath(realPath);
        const isRealPathAllowed = allowedDirectories.some(dir => normalizedReal.startsWith(dir));
        if (!isRealPathAllowed) {
          throw new Error("Access denied - symlink target outside allowed directories");
        }
        return realPath;
      } catch (error) {
        // For new files that don't exist yet, verify parent directory
        const parentDir = path.dirname(absolute);
        try {
          const realParentPath = await fsPromises.realpath(parentDir);
          const normalizedParent = normalizePath(realParentPath);
          const isParentAllowed = allowedDirectories.some(dir => normalizedParent.startsWith(dir));
          if (!isParentAllowed) {
            throw new Error("Access denied - parent directory outside allowed directories");
          }
          return absolute;
        } catch {
          throw new Error(`Parent directory does not exist: ${parentDir}`);
        }
      }
    }
  • The input schema for write_file is defined at lines 317-330 as part of the tool registration — it requires 'path' (string) and 'content' (string). The handler case at line 560-569 is the execution logic.
    case "write_file": {
      const validPath = await validatePath(args.path);
      await fsPromises.writeFile(validPath, args.content, "utf-8");
      return {
        toolResult: {
          success: true,
          content: [{ type: "text", text: `File written successfully to: ${args.path}` }],
          message: `File saved to: ${args.path}`
        }
      };
Behavior2/5

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

No annotations provided, and the description lacks details on behavior: whether it overwrites or appends, permission requirements, or side effects. The word 'write' implies mutation but no further elaboration.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single short sentence, but it is under-informative, lacking crucial details that would aid an AI agent.

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?

Given no output schema and no annotations, the description should cover more context (e.g., overwrite behavior, file path validation). It is incomplete.

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 coverage is 100%, and the description does not add extra meaning beyond the parameter descriptions in the schema. The baseline of 3 is appropriate.

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

Purpose3/5

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

The description 'Write content to a file' clearly states the action and target, but it is very minimal and does not distinguish from sibling tools like 'read_file' or 'create_directory'.

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?

No guidance on when to use this tool versus alternatives, no prerequisites, and no context for appropriate use.

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/falahgs/mcp-3d-style-cartoon-gen-server'

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