Skip to main content
Glama

read_file

Read and retrieve the contents of a file using a specified path and optional encoding with Edit-MCP. Ideal for accessing file data directly within your workflow.

Instructions

Read the contents of a file

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "encoding": { "description": "Encoding to use when reading the file (default: utf8)", "type": "string" }, "path": { "description": "Path to the file to read", "type": "string" } }, "required": [ "path" ], "type": "object" }

Implementation Reference

  • Generic handler for all 'tools/call' requests, including 'read_file'. Validates tool existence and currently returns a placeholder response. This is the entry point for executing the tool logic.
    /** * 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 ] }; }
  • Defines the input schema and annotations for the 'read_file' tool and registers it with the MCP server.
    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 } });
  • Implements the core file reading functionality using promisified fs.readFile, matching the tool's parameters (path and encoding).
    /** * Reads a file and returns its content */ 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}`); } }

Other Tools

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

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