Skip to main content
Glama

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
NameRequiredDescriptionDefault
filePathNoPath to the file to read
pathNoPath to the file to read (alias for filePath)

Implementation Reference

  • Core handler logic for reading file contents using fs.readFile, with existence check, error handling, and metadata extraction
    export 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),
        };
      }
  • 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'],
      },
    });
  • 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 };

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/tosin2013/mcp-adr-analysis-server'

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