read_file
Extract file contents to analyze codebase architecture and generate professional decision records using AI analysis.
Instructions
Read contents of a file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | No | Path to the file to read | |
| path | No | Path to the file to read (alias for filePath) |
Implementation Reference
- src/utils/file-system.ts:254-299 (handler)Core handler logic for reading file contents using fs.readFile, with existence check, error handling, and metadata extractionexport async function readFileContent(filePath: string): Promise<{ success: boolean; filePath: string; content?: string; error?: string; metadata?: { size: number; encoding: string; lastModified: string; }; }> { try { const resolvedPath = path.resolve(filePath); // Check if file exists try { await fs.access(resolvedPath); } catch { return { success: false, filePath, error: 'File not found', }; } // Read file content const content = await fs.readFile(resolvedPath, 'utf-8'); const stats = await fs.stat(resolvedPath); return { success: true, filePath, content, metadata: { size: stats.size, encoding: 'utf-8', lastModified: stats.mtime.toISOString(), }, }; } catch (error) { return { success: false, filePath, error: error instanceof Error ? error.message : String(error), }; }
- src/tools/tool-catalog.ts:1004-1022 (schema)Defines the tool metadata including name, description, input schema {path: string}, and category 'file-system'TOOL_CATALOG.set('read_file', { name: 'read_file', shortDescription: 'Read file contents', fullDescription: 'Reads the contents of a file.', category: 'file-system', complexity: 'simple', tokenCost: { min: 100, max: 5000 }, hasCEMCPDirective: true, // Phase 4.3: Simple tool - file read operation relatedTools: ['write_file', 'read_directory'], keywords: ['file', 'read', 'contents'], requiresAI: false, inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to file' }, }, required: ['path'], }, });
- src/tools/tool-dispatcher.ts:222-229 (registration)Registers the read_file tool (and all catalog tools) in the MCP ListTools response using the catalog metadata// Full mode - return all tools with schemas from catalog const tools: Tool[] = [getSearchToolsDefinition()]; for (const [, metadata] of TOOL_CATALOG) { tools.push(toMCPTool(metadata)); } return { tools };