Skip to main content
Glama

faf_write

Write content to files on your local filesystem using this tool. Specify the file path and content to create or update files directly.

Instructions

Write content to any file on the local filesystem

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute or relative file path to write
contentYesContent to write to the file

Implementation Reference

  • The handleFafWrite function implements the logic for the faf_write tool, including path validation, size checking, directory creation, and writing the file.
    export async function handleFafWrite(args: any): Promise<CallToolResult> {
      const startTime = Date.now();
      
      try {
        const { path: filePath, content } = args;
        
        // Validate path
        const pathValidation = PathValidator.validate(filePath);
        if (!pathValidation.valid) {
          return {
            content: [{
              type: 'text',
              text: `❌ Security error: ${pathValidation.error}`
            }],
            isError: true
          };
        }
        
        // Check content size
        const contentSize = Buffer.byteLength(content, 'utf8');
        if (contentSize > 50 * 1024 * 1024) {
          return {
            content: [{
              type: 'text',
              text: `❌ Content too large: ${(contentSize / 1024 / 1024).toFixed(2)}MB (max: 50MB)`
            }],
            isError: true
          };
        }
        
        // Create directory if needed
        const dir = path.dirname(filePath);
        await fs.mkdir(dir, { recursive: true });
        
        // Write file with timeout
        await Promise.race([
          fs.writeFile(filePath, content, 'utf8'),
          new Promise<never>((_, reject) => 
            setTimeout(() => reject(new Error('Write timeout (30s)')), 30000)
          )
        ]);
        
        const duration = Date.now() - startTime;
        
        return {
          content: [{
            type: 'text',
            text: `✅ Successfully wrote ${contentSize} bytes to ${path.resolve(filePath)}`
          }],
          metadata: {
            duration_ms: duration,
            bytes_written: contentSize,
            file_path: path.resolve(filePath),
            message: `✅ Write completed in ${duration}ms`
          }
        };
        
      } catch (error: any) {
        return {
          content: [{
            type: 'text',
            text: `❌ Failed to write file: ${error.message}`
          }],
          isError: true
        };
      }
    }
  • The fafWriteTool object defines the MCP tool schema for 'faf_write', specifying the input requirements.
    export const fafWriteTool: Tool = {
      name: 'faf_write',
      description: 'Write content to any file on the local filesystem',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Absolute or relative file path to write'
          },
          content: {
            type: 'string',
            description: '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/Wolfe-Jam/grok-faf-mcp'

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