Skip to main content
Glama

read_file

Read-only

Read file contents from a specified path using Edit MCP server. Specify encoding to access text or data files directly.

Instructions

Read the contents of a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to read
encodingNoEncoding to use when reading the file (default: utf8)

Implementation Reference

  • Generic handler for all MCP 'tools/call' requests. Validates tool existence and returns a placeholder response for 'read_file' and other tools, as actual execution is not implemented.
    /**
     * Handles the tools/call request
     */
    private async handleToolsCall(params: { name: string, arguments?: any }): Promise<CallToolResult> {
      const { name, arguments: args } = params;
      
      if (!name) {
        throw new Error('Tool name is required');
      }
      
      const tool = this.tools.get(name);
      
      if (!tool) {
        throw new Error(`Tool not found: ${name}`);
      }
      
      // In a real implementation, we would execute the tool here
      // For now, we'll just return a placeholder
      
      return {
        content: [
          {
            type: 'text',
            text: `Executed tool ${name} with arguments: ${JSON.stringify(args)}`
          } as TextContent
        ]
      };
    }
  • Input schema and metadata for the 'read_file' tool, defining parameters path (required) and encoding (optional).
    mcpServer.registerTool({
      name: 'read_file',
      description: 'Read the contents of a file',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to read'
          },
          encoding: {
            type: 'string',
            description: 'Encoding to use when reading the file (default: utf8)'
          }
        },
        required: ['path']
      },
      annotations: {
        readOnlyHint: true,
        openWorldHint: false
      }
    });
  • src/index.ts:137-158 (registration)
    Registers the 'read_file' tool with the MCP server using registerTool method.
    mcpServer.registerTool({
      name: 'read_file',
      description: 'Read the contents of a file',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to read'
          },
          encoding: {
            type: 'string',
            description: 'Encoding to use when reading the file (default: utf8)'
          }
        },
        required: ['path']
      },
      annotations: {
        readOnlyHint: true,
        openWorldHint: false
      }
    });
  • Supporting method in FileSystemManager that reads file contents given path and encoding, directly corresponding to read_file tool logic.
    public async readFile(filePath: string, encoding: BufferEncoding = 'utf8'): Promise<string> {
      try {
        return await readFile(filePath, { encoding });
      } catch (error: any) {
        throw new Error(`Failed to read file ${filePath}: ${error.message}`);
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.3/5.0
Behavior3/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, so the agent knows this is a safe read operation with deterministic behavior. The description adds no additional behavioral context about permissions, file size limits, error conditions, or return format. With annotations covering the safety profile, a baseline 3 is appropriate as the description doesn't contradict annotations but adds minimal value.

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 that directly states the tool's function without any wasted words. It's appropriately sized and front-loaded with the essential information.

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

Completeness3/5

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

For a simple read operation with good annotations (readOnlyHint, openWorldHint) and 100% schema coverage, the description is minimally adequate. However, without an output schema and with multiple sibling tools that could cause confusion, the description should ideally provide more context about what exactly gets returned and when to choose this tool over alternatives.

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. The description adds no parameter-specific information beyond what's already in the structured schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

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 clearly states the action ('Read') and resource ('contents of a file'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'find_in_file' or 'list_files' which also involve file 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. With siblings like 'find_in_file' for searching within files and 'list_files' for directory listing, there's no indication of when 'read_file' is the appropriate choice versus these other file-related tools.

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