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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file to read | |
| encoding | No | Encoding 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 } });
- src/index.ts:140-153 (schema)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'] },
- src/core/mcp-server.ts:400-424 (handler)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}`); } }
- src/core/mcp-server.ts:93-93 (registration)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));