Skip to main content
Glama

write_file

Create or update files in the AICre8 project sandbox, automatically generating parent directories as needed for web development tasks.

Instructions

Write or update a file in the project sandbox. Creates parent directories automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID (UUID or url_id)
file_pathYesFile path relative to project root (e.g. "src/App.tsx")
contentYesFile content to write
encodingNoEncoding: "utf-8" (default) for text, "base64" for binary files

Implementation Reference

  • The handler function that executes the write_file tool logic. It calls client.writeFile() with the project_id, file_path, content, and encoding parameters, then returns a success message or error.
    async (params) => {
      try {
        const result = await client.writeFile(
          params.project_id,
          params.file_path,
          params.content,
          params.encoding,
        );
        return {
          content: [
            {
              type: 'text' as const,
              text: `Written: ${result.path}`,
            },
          ],
        };
      } catch (err: any) {
        return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true };
      }
    },
  • Zod schema definition for write_file tool inputs: project_id (string), file_path (string), content (string), and optional encoding (enum: 'utf-8' or 'base64').
    {
      project_id: z.string().describe('Project ID (UUID or url_id)'),
      file_path: z.string().describe('File path relative to project root (e.g. "src/App.tsx")'),
      content: z.string().describe('File content to write'),
      encoding: z
        .enum(['utf-8', 'base64'])
        .optional()
        .describe('Encoding: "utf-8" (default) for text, "base64" for binary files'),
  • src/index.ts:152-184 (registration)
    Registration of the write_file tool with the MCP server using server.tool(). Includes tool name, description, input schema, and handler function.
    server.tool(
      'write_file',
      'Write or update a file in the project sandbox. Creates parent directories automatically.',
      {
        project_id: z.string().describe('Project ID (UUID or url_id)'),
        file_path: z.string().describe('File path relative to project root (e.g. "src/App.tsx")'),
        content: z.string().describe('File content to write'),
        encoding: z
          .enum(['utf-8', 'base64'])
          .optional()
          .describe('Encoding: "utf-8" (default) for text, "base64" for binary files'),
      },
      async (params) => {
        try {
          const result = await client.writeFile(
            params.project_id,
            params.file_path,
            params.content,
            params.encoding,
          );
          return {
            content: [
              {
                type: 'text' as const,
                text: `Written: ${result.path}`,
              },
            ],
          };
        } catch (err: any) {
          return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true };
        }
      },
    );
  • The writeFile method in AICre8Client class that makes the actual HTTP PUT request to the API endpoint /projects/{projectId}/files/{filePath} with the file content and encoding.
    async writeFile(
      projectId: string,
      filePath: string,
      content: string,
      encoding?: 'utf-8' | 'base64',
    ): Promise<{ path: string; written: boolean }> {
      return this.request('PUT', `/projects/${projectId}/files/${filePath}`, {
        content,
        encoding,
      });
    }

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/AICre8dev/mcp-server'

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