create_model
Generate a database model for Webasyst framework applications to interact with database tables, enabling structured data operations.
Instructions
Создать модель для работы с БД
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| app_id | Yes | ID приложения | |
| table_name | Yes | Название таблицы в БД |
Implementation Reference
- webasyst-mcp.js:505-538 (handler)The main handler function for the 'create_model' tool. It creates a PHP model class extending waModel in the appropriate directory (lib/model or lib/models) for the given app_id and table_name, generating the class name by camel-casing.async function createModelTool({ app_id, table_name }) { const rootPath = await findWebasystRoot(); const appPath = path.join(rootPath, 'wa-apps', app_id); if (!(await fileExists(appPath))) throw new Error(`Приложение ${app_id} не найдено`); // Determine model directory (some apps use 'model', others 'models') let modelsDir = path.join(appPath, 'lib', 'model'); if (!(await fileExists(modelsDir))) { modelsDir = path.join(appPath, 'lib', 'models'); } await ensureDir(modelsDir); // Generate class name from table name with app prefix const camelize = (str) => str.split('_').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join(''); const appPrefix = camelize(app_id); const tableWithoutApp = table_name.replace(new RegExp(`^${app_id}_`, 'i'), '') || table_name; const tableCamel = camelize(tableWithoutApp); const className = `${appPrefix}${tableCamel}Model`; const fileName = `${app_id}${tableCamel}.model.php`; const filePath = path.join(modelsDir, fileName); const code = `<?php class ${className} extends waModel { protected \$table = '${table_name}'; } `; await fs.writeFile(filePath, code); return { content: [{ type: 'text', text: `Модель ${className} создана:\n${filePath}` }] }; }
- webasyst-mcp.js:1713-1713 (registration)The tool registration entry in the list of tools provided by the MCP server, including the input schema definition.{ name: 'create_model', description: 'Создать модель для работы с БД', inputSchema: { type: 'object', properties: { app_id: { type: 'string', description: 'ID приложения' }, table_name: { type: 'string', description: 'Название таблицы в БД' } }, required: ['app_id', 'table_name'] } },
- webasyst-mcp.js:1775-1775 (registration)The switch case in the CallToolRequestSchema handler that dispatches calls to the createModelTool function.case 'create_model': return await createModelTool(args);
- webasyst-mcp.js:1713-1713 (schema)The inline input schema for the 'create_model' tool, defining required parameters app_id and table_name.{ name: 'create_model', description: 'Создать модель для работы с БД', inputSchema: { type: 'object', properties: { app_id: { type: 'string', description: 'ID приложения' }, table_name: { type: 'string', description: 'Название таблицы в БД' } }, required: ['app_id', 'table_name'] } },