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}`);
      }
    }
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 limited scope. The description adds no behavioral context beyond what annotations provide - no information about permissions needed, error handling, file size limitations, or return format. With annotations covering the safety profile, a baseline 3 is appropriate.

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 states the core functionality without any wasted words. It's appropriately sized for a simple read operation and gets straight to the point with no unnecessary elaboration.

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 complete schema coverage, the description is minimally adequate. However, without an output schema and with multiple sibling file tools, more context about return format and differentiation from alternatives would be helpful. The description meets basic requirements but leaves gaps.

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 ('path' and 'encoding') fully documented in the schema. The description adds no additional parameter information beyond what the schema already provides. When schema coverage is this complete, the baseline score is 3 even without parameter details 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' that 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 simple file reading is appropriate versus these other file-related operations.

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/mixelpixx/edit-mcp'

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