Skip to main content
Glama

file_read

Read file contents from local storage to access documents, notes, or operational data for AI-assisted analysis and task management.

Instructions

Читать содержимое файла

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesПуть к файлу

Implementation Reference

  • Core handler function for the 'file_read' tool. Sanitizes the file path to prevent directory traversal, reads the file content using Node.js fs.promises.readFile, logs the operation, and returns the content as a string. Handles errors appropriately.
    async readFile(filePath: string): Promise<string> {
      try {
        // Проверяем безопасность пути
        const safePath = this.sanitizePath(filePath);
        
        console.log(`📖 Чтение файла: ${safePath}`);
        
        const content = await fs.readFile(safePath, 'utf-8');
        
        console.log(`✅ Файл прочитан: ${safePath} (${content.length} символов)`);
        
        return content;
      } catch (error) {
        console.error('Ошибка чтения файла:', error);
        throw new Error(`Ошибка чтения файла: ${error}`);
      }
  • Input schema definition for the 'file_read' tool, requiring a 'path' string parameter. Part of the tool list returned by ListToolsRequestSchema handler.
    {
      name: 'file_read',
      description: 'Читать содержимое файла',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Путь к файлу',
          },
        },
        required: ['path'],
      },
    },
  • src/server.ts:196-199 (registration)
    Registration of the 'file_read' tool handler in the main CallToolRequestSchema switch statement in the stdio server transport. Delegates execution to FileService.readFile.
    case 'file_read':
      return {
        content: await this.fileService.readFile(args.path as string)
      };
  • Helper method used by readFile to sanitize the file path, preventing path traversal attacks by restricting to the notes directory and removing dangerous characters.
    private sanitizePath(filePath: string): string {
      // Убираем потенциально опасные символы
      const cleanPath = filePath.replace(/[<>:"|?*]/g, '');
      
      // Разрешаем только относительные пути
      if (path.isAbsolute(cleanPath)) {
        throw new Error('Абсолютные пути не разрешены');
      }
      
      // Разрешаем только файлы в notes директории
      const resolvedPath = path.resolve(this.notesDir, cleanPath);
      const notesDirResolved = path.resolve(this.notesDir);
      
      if (!resolvedPath.startsWith(notesDirResolved)) {
        throw new Error('Доступ к файлу вне notes директории запрещен');
      }
      
      return resolvedPath;
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. It states the action (read) but doesn't describe traits like whether it requires specific permissions, handles errors (e.g., missing files), returns content format (text/binary), or has rate limits. This is a significant gap for a tool with zero annotation coverage.

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 a single, efficient sentence in Russian that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, 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 incomplete. It doesn't explain what the tool returns (e.g., text content, error messages) or behavioral aspects like file size limits or encoding. Given the complexity and lack of structured data, more context is needed for effective use.

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?

The input schema has 100% description coverage, with the 'path' parameter documented as 'Путь к файлу' (Path to the file). The description doesn't add any meaning beyond this, such as path format examples or constraints. Given the high schema coverage, the baseline score of 3 is appropriate, as the schema does the heavy lifting.

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 file contents) clearly states the verb (read) and resource (file contents), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'rag_search' or 'web_fetch' which might also involve reading operations, so it doesn't reach the highest score.

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. It doesn't mention when to choose 'file_read' over 'rag_search' for document access or 'web_fetch' for external content, nor does it specify prerequisites like file existence or permissions. This leaves the agent with minimal usage context.

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/Galiusbro/MCP'

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