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 };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Read contents' implies a read-only operation, it doesn't specify file size limits, encoding considerations, error handling for missing files, or what format the contents are returned in. This leaves significant behavioral gaps for a file I/O tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just four words, front-loading the core functionality without any wasted words. Every element earns its place, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a file reading tool with no annotations and no output schema, the description is insufficient. It doesn't address return format, error conditions, file type support, or performance considerations. Given the complexity of file I/O operations and lack of structured documentation, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters clearly documented in the schema itself. The description doesn't add any parameter-specific information beyond what's already in the schema, so it meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Read contents of a file' clearly states the action (read) and resource (file contents), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'read_directory' or 'search_codebase' which also involve file system operations, so it doesn't fully distinguish from alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'read_directory' (for listing files) or 'search_codebase' (for searching within files). There's no mention of prerequisites, limitations, or appropriate contexts for use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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