Skip to main content
Glama

faf_read

Read content from files on your local filesystem by specifying the file path. This tool accesses and retrieves file data for processing or analysis.

Instructions

Read content from any file on the local filesystem

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute or relative file path to read

Implementation Reference

  • The core handler function `handleFafRead` which executes the file reading logic, including security and size validations.
    export async function handleFafRead(args: any): Promise<CallToolResult> {
      const startTime = Date.now();
      
      try {
        const { path: filePath } = args;
        
        // Validate path
        const pathValidation = PathValidator.validate(filePath);
        if (!pathValidation.valid) {
          return {
            content: [{
              type: 'text',
              text: `❌ Security error: ${pathValidation.error}`
            }],
            isError: true
          };
        }
        
        // Check file size
        const sizeValidation = await PathValidator.checkFileSize(filePath);
        if (!sizeValidation.valid) {
          return {
            content: [{
              type: 'text',
              text: `❌ ${sizeValidation.error}`
            }],
            isError: true
          };
        }
        
        // Read file with timeout
        const content = await Promise.race([
          fs.readFile(filePath, 'utf8'),
          new Promise<never>((_, reject) => 
            setTimeout(() => reject(new Error('Read timeout (30s)')), 30000)
          )
        ]);
        
        const duration = Date.now() - startTime;
        const stats = await fs.stat(filePath);
        
        return {
          content: [{
            type: 'text',
            text: content
          }],
          metadata: {
            duration_ms: duration,
            file_size: stats.size,
            file_path: path.resolve(filePath),
            message: `✅ Read ${stats.size} bytes in ${duration}ms`
          }
        };
        
      } catch (error: any) {
        return {
          content: [{
            type: 'text',
            text: `❌ Failed to read file: ${error.message}`
          }],
          isError: true
        };
      }
    }
  • The tool definition and input schema for `faf_read`.
    export const fafReadTool: Tool = {
      name: 'faf_read',
      description: 'Read content from any file on the local filesystem',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Absolute or relative file path to read'
          }
        },
        required: ['path']
      }
    };
  • The registration map for `faf_read` to the `handleFafRead` function.
    export const fileHandlers = {
      faf_read: handleFafRead,
      faf_write: handleFafWrite
    };

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