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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute or relative file path to read |
Implementation Reference
- src/handlers/fileHandler.ts:95-158 (handler)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 }; } } - src/handlers/fileHandler.ts:55-68 (schema)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'] } }; - src/handlers/fileHandler.ts:232-235 (registration)The registration map for `faf_read` to the `handleFafRead` function.
export const fileHandlers = { faf_read: handleFafRead, faf_write: handleFafWrite };