Skip to main content
Glama

get_templates

Retrieve Laravel CRUD implementation templates to generate controllers, models, migrations, and other components for rapid development.

Instructions

Get implementation templates for CRUD operations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_typeNoTemplate type to get, or "all" for everything

Implementation Reference

  • index.js:193-238 (registration)
    Tool registration for 'get_templates' with input schema and handler function definition
    server.registerTool(
      'get_templates',
      {
        description: 'Get implementation templates for CRUD operations',
        inputSchema: {
          template_type: z.enum(['all', 'controller', 'service', 'service_interface', 'model', 'request', 'resource', 'migration']).optional().describe('Template type to get, or "all" for everything'),
        },
      },
      async ({ template_type = 'all' }) => {
        const templatesPath = path.join(DOCS_PATH, 'ai/templates.md');
    
        if (!fs.existsSync(templatesPath)) {
          throw new Error('Templates documentation not found');
        }
    
        let content = fs.readFileSync(templatesPath, 'utf-8');
    
        if (template_type !== 'all') {
          const sections = {
            controller: '1. Controller Template',
            service: '3. Service Implementation Template',
            service_interface: '2. Service Interface Template',
            model: '4. Model Template',
            request: '5. Index Request Template',
            resource: '7. Resource Template',
            migration: '9. Migration Template',
          };
    
          const sectionStart = content.indexOf(sections[template_type]);
          const sectionEnd = content.indexOf('\n---', sectionStart + 1);
    
          if (sectionStart === -1) {
            throw new Error(`Template type '${template_type}' not found`);
          }
    
          content = content.slice(sectionStart, sectionEnd === -1 ? content.length : sectionEnd);
        }
    
        return {
          content: [{
            type: 'text',
            text: content,
          }],
        };
      }
    );
  • Input schema validation using zod enum for template_type parameter with options: all, controller, service, service_interface, model, request, resource, migration
    {
      description: 'Get implementation templates for CRUD operations',
      inputSchema: {
        template_type: z.enum(['all', 'controller', 'service', 'service_interface', 'model', 'request', 'resource', 'migration']).optional().describe('Template type to get, or "all" for everything'),
      },
  • Handler function that reads templates from docs/ai/templates.md, optionally filters by section based on template_type parameter, and returns the content as text
    async ({ template_type = 'all' }) => {
      const templatesPath = path.join(DOCS_PATH, 'ai/templates.md');
    
      if (!fs.existsSync(templatesPath)) {
        throw new Error('Templates documentation not found');
      }
    
      let content = fs.readFileSync(templatesPath, 'utf-8');
    
      if (template_type !== 'all') {
        const sections = {
          controller: '1. Controller Template',
          service: '3. Service Implementation Template',
          service_interface: '2. Service Interface Template',
          model: '4. Model Template',
          request: '5. Index Request Template',
          resource: '7. Resource Template',
          migration: '9. Migration Template',
        };
    
        const sectionStart = content.indexOf(sections[template_type]);
        const sectionEnd = content.indexOf('\n---', sectionStart + 1);
    
        if (sectionStart === -1) {
          throw new Error(`Template type '${template_type}' not found`);
        }
    
        content = content.slice(sectionStart, sectionEnd === -1 ? content.length : sectionEnd);
      }
    
      return {
        content: [{
          type: 'text',
          text: content,
        }],
      };
    }
  • Section mapping object that defines the headings for each template type in the templates.md file for filtering purposes
    const sections = {
      controller: '1. Controller Template',
      service: '3. Service Implementation Template',
      service_interface: '2. Service Interface Template',
      model: '4. Model Template',
      request: '5. Index Request Template',
      resource: '7. Resource Template',
      migration: '9. Migration Template',
    };

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/pujandan/mcp-laravel'

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