generate_code
Generate or modify code in AICre8 projects using AI. Write files, install packages, and update projects based on prompts.
Instructions
Send a prompt to generate or modify code in an AICre8 project using AI. The AI will write files, install packages, and update the project. Costs 1 credit per call.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID (UUID or url_id) | |
| prompt | Yes | What to build or change | |
| chat_mode | No | Mode: "build" generates code (default), "discuss" for conversation only |
Implementation Reference
- src/client.ts:73-113 (handler)The generateCode method in AICre8Client class handles the core logic: makes a POST request to /projects/{projectId}/generate endpoint, handles SSE stream response by reading chunks and returning the full accumulated result text.
async generateCode( projectId: string, params: { prompt: string; chat_mode?: 'build' | 'discuss' }, ): Promise<string> { const url = `${this.baseUrl}/projects/${projectId}/generate`; const res = await fetch(url, { method: 'POST', headers: this.headers, body: JSON.stringify(params), }); if (!res.ok) { const error = await res.json().catch(() => ({ error: res.statusText })); throw new Error( `AICre8 API error ${res.status}: ${(error as any).error || res.statusText}`, ); } // The response is an SSE stream — consume it and return the full text const reader = res.body?.getReader(); if (!reader) { throw new Error('No response body'); } const decoder = new TextDecoder(); let result = ''; while (true) { const { done, value } = await reader.read(); if (done) { break; } result += decoder.decode(value, { stream: true }); } return result; } - src/index.ts:86-112 (registration)Tool registration with MCP server using server.tool(). Registers 'generate_code' with description, Zod schema for inputs (project_id, prompt, chat_mode), and async handler that calls client.generateCode() and returns the result as text content.
// ── Tool: generate_code ── server.tool( 'generate_code', 'Send a prompt to generate or modify code in an AICre8 project using AI. The AI will write files, install packages, and update the project. Costs 1 credit per call.', { project_id: z.string().describe('Project ID (UUID or url_id)'), prompt: z.string().describe('What to build or change'), chat_mode: z .enum(['build', 'discuss']) .optional() .describe('Mode: "build" generates code (default), "discuss" for conversation only'), }, async (params) => { try { const result = await client.generateCode(params.project_id, { prompt: params.prompt, chat_mode: params.chat_mode, }); return { content: [{ type: 'text' as const, text: result }], }; } catch (err: any) { return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true }; } }, ); - src/index.ts:91-98 (schema)Zod schema defining the input parameters for generate_code tool: project_id (required string), prompt (required string), and chat_mode (optional enum of 'build' or 'discuss').
{ project_id: z.string().describe('Project ID (UUID or url_id)'), prompt: z.string().describe('What to build or change'), chat_mode: z .enum(['build', 'discuss']) .optional() .describe('Mode: "build" generates code (default), "discuss" for conversation only'), },