read_file
Read files from project sandboxes to access code and content for web development tasks. Use this tool to retrieve text or binary files from active AICre8 platform projects.
Instructions
Read a file from the project sandbox. Requires an active sandbox (run generate_code first to boot it).
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") | |
| encoding | No | Encoding: "utf-8" (default) for text, "base64" for binary files |
Implementation Reference
- src/index.ts:116-148 (registration)Tool registration: Registers the 'read_file' tool with the MCP server using server.tool(), including the tool name, description, schema, and handler function.
server.tool( 'read_file', 'Read a file from the project sandbox. Requires an active sandbox (run generate_code first to boot it).', { 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")'), 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.readFile( params.project_id, params.file_path, params.encoding, ); return { content: [ { type: 'text' as const, text: params.encoding === 'base64' ? `File: ${result.path} (base64, ${result.content.length} chars)` : result.content, }, ], }; } catch (err: any) { return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true }; } }, ); - src/index.ts:127-147 (handler)Tool handler: Async function that executes the read_file tool logic. It calls client.readFile() with project_id, file_path, and encoding parameters, then formats the response based on encoding type (base64 vs text) and handles errors.
async (params) => { try { const result = await client.readFile( params.project_id, params.file_path, params.encoding, ); return { content: [ { type: 'text' as const, text: params.encoding === 'base64' ? `File: ${result.path} (base64, ${result.content.length} chars)` : result.content, }, ], }; } catch (err: any) { return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true }; } }, - src/index.ts:119-126 (schema)Schema definition: Zod schema defining the input parameters for read_file tool - project_id (required string), file_path (required string), and encoding (optional enum of '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")'), encoding: z .enum(['utf-8', 'base64']) .optional() .describe('Encoding: "utf-8" (default) for text, "base64" for binary files'), }, - src/client.ts:115-122 (helper)Client helper method: Implements the actual HTTP request to the AICre8 API endpoint '/projects/{projectId}/files/{filePath}' with optional encoding query parameter. Returns an object with path, content, and encoding.
async readFile( projectId: string, filePath: string, encoding?: 'utf-8' | 'base64', ): Promise<{ path: string; content: string; encoding: string }> { const query = encoding ? `?encoding=${encoding}` : ''; return this.request('GET', `/projects/${projectId}/files/${filePath}${query}`); }