read_file
Read complete file contents from the file system to examine text before editing. Handles various text encodings and returns full file content.
Instructions
Read the complete contents of a file from the file system. Handles various text encodings and returns the full file content. Use this to examine file contents before editing.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The path to the file to read (absolute or relative) |
Implementation Reference
- src/index.ts:275-286 (handler)The handler function for the 'read_file' tool. It extracts the file path from arguments, reads the file content asynchronously using Node.js fs.promises.readFile, and returns the content wrapped in the MCP ToolResult format with type 'text'.case "read_file": { const filePath = args.path as string; const content = await fs.readFile(filePath, "utf-8"); return { content: [ { type: "text", text: content, }, ], }; }
- src/index.ts:23-32 (schema)The input schema for the 'read_file' tool, defining an object with a required 'path' string property.inputSchema: { type: "object", properties: { path: { type: "string", description: "The path to the file to read (absolute or relative)", }, }, required: ["path"], },
- src/index.ts:20-33 (registration)The Tool object registration for 'read_file' in the TOOLS array, which is returned by the listTools handler. Includes name, description, and inputSchema.{ name: "read_file", description: "Read the complete contents of a file from the file system. Handles various text encodings and returns the full file content. Use this to examine file contents before editing.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The path to the file to read (absolute or relative)", }, }, required: ["path"], }, },
- src/index.ts:261-263 (registration)The server request handler for ListToolsRequestSchema that returns the TOOLS array, effectively registering all tools including 'read_file'.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: TOOLS }; });