src / tools / readFileTool.ts

import { tool, Tool, ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import * as fs from "fs/promises";

export const getReadFileTool = (ctl: ToolsProviderController) => {
  return tool({
    name: "readFile",
    description: "Read and return the entire contents of a file.",
    parameters: { filepath: z.string() },
    implementation: async ({ filepath }) => {
      try {
        const data = await fs.readFile(filepath, "utf-8");
        return data;
      } catch (err) {
        return `Error reading file: ${err}`;
      }
    },
  });
};