Back to course

Daily Repetition 1: The 'File Reader' Tool

Model Context Protocol (MCP) Server Engineering

Daily Repetition: Tool #1

Today, we build a tool that reads a file from the disk. This is a "write" action because the LLM is explicitly requesting a specific path access not listed in resources.

Implementation Tip

Always use fs.promises for asynchronous file reading in Node.js.

typescript import fs from "fs/promises"; // Inside tool handler: const content = await fs.readFile(path, "utf-8"); return { content: [{ type: "text", text: content }] };

Assignment: Implement this tool and test it by asking the LLM to read your package.json file.