Skip to main content
Glama

read-file

Extract file contents by specifying the file path within React applications. Simplifies file reading in the react-mcp server to enhance app development workflows.

Instructions

Read the contents of a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the file to read

Implementation Reference

  • The main execution handler for the 'read-file' tool. Validates input, checks file existence, reads content with fs.readFileSync, and returns file details.
    async function handleReadFile(params) { try { const { filePath } = params; if (!filePath) { throw new Error("File path is required"); } // Check if file exists if (!fs.existsSync(filePath)) { throw new Error(`File ${filePath} does not exist`); } // Read file content const content = fs.readFileSync(filePath, "utf8"); return { filePath: filePath, content: content, size: Buffer.byteLength(content, "utf8"), }; } catch (error) { return { error: `Error reading file: ${error.message}`, }; } }
  • Zod schema defining the input parameters for the 'read-file' tool: requires 'filePath' as string.
    const ReadFileSchema = z.object({ filePath: z.string(), });
  • index.js:582-595 (registration)
    Tool registration in the listTools handler, providing name, description, and input schema for 'read-file'.
    { name: "read-file", description: "Read the contents of a file", inputSchema: { type: "object", properties: { filePath: { type: "string", description: "Path to the file to read", }, }, required: ["filePath"], }, },
  • index.js:669-672 (registration)
    Dispatch case in the CallToolRequestSchema handler that parses arguments with ReadFileSchema and invokes the handleReadFile function.
    case "read-file": const readArgs = ReadFileSchema.parse(args); result = await handleReadFile(readArgs); break;

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kalivaraprasad-gonapa/react-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server