Skip to main content
Glama

create_model

Generate a database model for Webasyst framework applications to interact with database tables, enabling structured data operations.

Instructions

Создать модель для работы с БД

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
app_idYesID приложения
table_nameYesНазвание таблицы в БД

Implementation Reference

  • 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}` }] }; }
  • 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'] } },
  • The switch case in the CallToolRequestSchema handler that dispatches calls to the createModelTool function.
    case 'create_model': return await createModelTool(args);
  • 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'] } },

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/emmy-design/webasyst-mcp'

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