writeFile
Store content in a specified file path for Expo-based React Native projects, enabling efficient file manipulation and project management within the Expo MCP Server environment.
Instructions
Write content to a file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The content to write to the file | |
| filePath | Yes | The path to the file to write |
Implementation Reference
- src/file.ts:36-59 (handler)The writeFile tool handler function. It normalizes the path, creates the directory if necessary, writes the file content using Node.js fs.promises.writeFile, handles errors, logs operations, and returns an MCP-formatted response.export async function writeFile(args: { filePath: string; content: string }, { log }: LogContext) { try { log.info(`Writing to file at path: ${args.filePath}`); const normalizedPath = path.normalize(args.filePath); const directory = path.dirname(normalizedPath); await fs.promises.mkdir(directory, { recursive: true }); await fs.promises.writeFile(normalizedPath, args.content); log.info(`Successfully wrote to file: ${normalizedPath}`); return { content: [ { type: "text", text: `Successfully wrote ${args.content.length} characters to ${normalizedPath}`, }, ], }; } catch (error: any) { log.error(`Error writing file: ${error.message}`); throw new Error(`Failed to write file: ${error.message}`); } }
- src/index.ts:27-35 (registration)Registration of the writeFile tool on the FastMCP server using addTool. Includes the tool name, description, Zod input schema for parameters, and binding to the execute handler.addTool({ name: "writeFile", description: "Write content to a file", parameters: z.object({ filePath: z.string().describe("The path to the file to write"), content: z.string().describe("The content to write to the file"), }), execute: writeFile, });
- src/index.ts:30-33 (schema)Zod schema definition for the writeFile tool input parameters: filePath (string) and content (string). Used for validation in the MCP tool registration.parameters: z.object({ filePath: z.string().describe("The path to the file to write"), content: z.string().describe("The content to write to the file"), }),