Skip to main content
Glama
mattlemmone

Expo MCP Server

by mattlemmone

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
NameRequiredDescriptionDefault
contentYesThe content to write to the file
filePathYesThe path to the file to write

Implementation Reference

  • 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,
    });
  • 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"),
    }),
Install Server

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/mattlemmone/expo-mcp'

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