Skip to main content
Glama

read_file

Read file contents from a specified path with configurable encoding options to access and process text data within the Edit-MCP server environment.

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

  • src/index.ts:137-158 (registration)
    Registration of the 'read_file' tool, including its name, description, input schema (path required, optional encoding), and annotations (read-only).
    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
      }
    });
  • Input schema for the 'read_file' tool defining parameters: path (string, required), encoding (string, optional).
    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']
    },
  • Handler for tools/call requests, which executes the 'read_file' tool (and all others). Currently returns a placeholder response indicating execution with arguments; actual file reading logic not implemented.
    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
        ]
      };
    }
  • FileSystemManager.readFile method provides file reading functionality matching the tool's purpose, though not directly invoked by the tool handler.
    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}`);
      }
    }
  • Registration of the 'tools/call' request handler in MCPServer constructor, which is used to invoke the 'read_file' tool.
    this.registerRequestHandler('tools/call', this.handleToolsCall.bind(this));

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

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