readFile
Retrieve file contents by specifying the file path using this tool, designed for managing Expo-based React Native applications in the Expo MCP Server environment.
Instructions
Read the contents of a file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | The path to the file to read |
Implementation Reference
- src/file.ts:10-31 (handler)The readFile tool handler function that reads and returns the content of the specified file.export async function readFile(args: { filePath: string }, { log }: LogContext) { try { log.info(`Reading file at path: ${args.filePath}`); const normalizedPath = path.normalize(args.filePath); const fileContent = await fs.promises.readFile(normalizedPath, "utf8"); log.info(`Successfully read file: ${normalizedPath}`); return { content: [ { type: "text", text: fileContent, }, ], }; } catch (error: any) { log.error(`Error reading file: ${error.message}`); throw new Error(`Failed to read file: ${error.message}`); } }
- src/index.ts:18-25 (registration)Registration of the readFile tool on the MCP server, including schema definition and handler reference.addTool({ name: "readFile", description: "Read the contents of a file", parameters: z.object({ filePath: z.string().describe("The path to the file to read"), }), execute: readFile, });