read_file
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
| 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/core/mcp-server.ts:397-424 (handler)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 ] }; }
- src/index.ts:137-158 (schema)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}`); } }