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
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID (UUID or url_id) | |
| file_path | Yes | File path relative to project root (e.g. "src/App.tsx") | |
| content | Yes | File content to write | |
| encoding | No | Encoding: "utf-8" (default) for text, "base64" for binary files |
Implementation Reference
- src/index.ts:164-183 (handler)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 }; } }, - src/index.ts:155-162 (schema)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 }; } }, ); - src/client.ts:124-134 (helper)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, }); }