Skip to main content
Glama

create_site_plugin

Create a plugin for the Site application in Webasyst framework to add custom functionality, settings, or interfaces to websites.

Instructions

Создать плагин для приложения Site

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
plugin_typeNo
plugin_nameYes
plugin_titleYes
descriptionNo
settingsNo
frontend_assetsNo
admin_interfaceNo
webasyst_pathYes

Implementation Reference

  • Main handler function implementing the create_site_plugin tool. Creates complete Site plugin structure: directories, plugin.php config, PHP class with frontend hook, settings.php, frontend assets (CSS/JS/template), and .htaccess protections.
    async function createSitePluginTool(args) { const { plugin_type = 'widget', plugin_name, plugin_title, description = '', settings = [], frontend_assets = true, admin_interface = true, webasyst_path } = args; const pluginPath = path.join(webasyst_path, 'wa-apps', 'site', 'plugins', plugin_name); await ensureDir(pluginPath); for (const d of ['lib', 'lib/config', 'templates', 'css', 'js', 'img', 'locale', path.join('locale', 'ru_RU')]) await ensureDir(pluginPath, d); // Конфигурация плагина в plugin.php const pluginConfig = `<?php return array( 'name' => /*_wp*/('${plugin_title}'), 'description' => /*_wp*/('${description}'), 'img' => 'img/${plugin_name}.png', 'version' => '1.0.0', 'vendor' => 'custom', 'frontend' => ${frontend_assets ? 'true' : 'false'}, 'handlers' => array( ${frontend_assets ? "'frontend_footer' => 'frontendFooter'," : ''} ), ); `; await fs.writeFile(path.join(pluginPath, 'lib', 'config', 'plugin.php'), pluginConfig); // Класс плагина const classPhp = `<?php class site${toCamelCase(plugin_name)}Plugin extends sitePlugin { ${frontend_assets ? `/** * Хук frontend_footer — вставка контента в footer фронтенда. * @param array &\$params * @return string */ public function frontendFooter(&\$params) { return \$this->display(); } /** * Отрисовка шаблона плагина. * @return string */ protected function display() { \$view = wa('site')->getView(); return \$view->fetch(\$this->path.'/templates/frontend_footer.html'); }` : '// TODO: implement plugin methods'} } `; await fs.writeFile(path.join(pluginPath, 'lib', `site${toCamelCase(plugin_name)}Plugin.class.php`), classPhp); // Настройки плагина const settingsArray = settings.length ? settings : []; const st = `<?php return array( 'enabled' => array( 'title' => /*_wp*/('Включить'), 'value' => 1, 'control_type' => waHtmlControl::CHECKBOX, ), ${settingsArray.map(s => ` '${s.name}' => array( 'title' => /*_wp*/('${s.title}'), 'value' => '${s.default_value || ''}', 'control_type' => waHtmlControl::${(s.type || 'INPUT').toUpperCase()}, ),`).join('\n')} ); `; await fs.writeFile(path.join(pluginPath, 'lib', 'config', 'settings.php'), st); if (frontend_assets) { await fs.writeFile(path.join(pluginPath, 'css', 'frontend.css'), `/* ${plugin_title} */\n.${plugin_name}-container { padding: 16px; border-radius: 8px; background: var(--background-color-blank); }\n`); await fs.writeFile(path.join(pluginPath, 'js', 'frontend.js'), `document.addEventListener('DOMContentLoaded', function() { console.log('${plugin_title} ready'); });\n`); await fs.writeFile(path.join(pluginPath, 'templates', 'frontend_footer.html'), `{* ${plugin_title} *}\n<div class="${plugin_name}-container">\n {\$_wp('${plugin_title}')}\n</div>\n`); } // .htaccess для защиты await fs.writeFile(path.join(pluginPath, 'lib', '.htaccess'), 'Deny from all\n'); await fs.writeFile(path.join(pluginPath, 'templates', '.htaccess'), 'Deny from all\n'); return { content: [{ type: 'text', text: `Плагин Site "${plugin_title}" создан: ${pluginPath}` }] }; }
  • Tool registration in the CallToolRequestSchema switch statement, mapping the tool name to its handler function.
    case 'create_site_plugin': return await createSitePluginTool(args);
  • Tool schema definition including input parameters and requirements, registered in ListToolsRequestSchema response.
    { name: 'create_site_plugin', description: 'Создать плагин для приложения Site', inputSchema: { type: 'object', properties: { plugin_type: { type: 'string' }, plugin_name: { type: 'string' }, plugin_title: { type: 'string' }, description: { type: 'string' }, settings: { type: 'array', items: { type: 'object' } }, frontend_assets: { type: 'boolean' }, admin_interface: { type: 'boolean' }, webasyst_path: { type: 'string' } }, required: ['plugin_name', 'plugin_title', 'webasyst_path'] } }, { name: 'create_site_widget', description: 'Создать виджет для Site', inputSchema: { type: 'object', properties: { widget_name: { type: 'string' }, widget_title: { type: 'string' }, widget_type: { type: 'string' }, has_settings: { type: 'boolean' }, is_cacheable: { type: 'boolean' }, responsive: { type: 'boolean' }, ajax_support: { type: 'boolean' }, webasyst_path: { type: 'string' } }, required: ['widget_name', 'widget_title', 'webasyst_path'] } },
  • Tool listed/registered in the tools array returned by ListToolsRequestSchema handler.
    { name: 'create_site_plugin', description: 'Создать плагин для приложения Site', inputSchema: { type: 'object', properties: { plugin_type: { type: 'string' }, plugin_name: { type: 'string' }, plugin_title: { type: 'string' }, description: { type: 'string' }, settings: { type: 'array', items: { type: 'object' } }, frontend_assets: { type: 'boolean' }, admin_interface: { type: 'boolean' }, webasyst_path: { type: 'string' } }, required: ['plugin_name', 'plugin_title', 'webasyst_path'] } }, { name: 'create_site_widget', description: 'Создать виджет для Site', inputSchema: { type: 'object', properties: { widget_name: { type: 'string' }, widget_title: { type: 'string' }, widget_type: { type: 'string' }, has_settings: { type: 'boolean' }, is_cacheable: { type: 'boolean' }, responsive: { type: 'boolean' }, ajax_support: { type: 'boolean' }, webasyst_path: { type: 'string' } }, required: ['widget_name', 'widget_title', 'webasyst_path'] } },
  • Utility function toCamelCase used in createSitePluginTool to generate class names from plugin_name.
    const toCamelCase = (s) => s.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^./, (m) => m.toUpperCase());

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