Skip to main content
Glama

template_apply

Apply a template to generate tasks in an epic by replacing variable placeholders with specific values for structured project tracking.

Instructions

Apply a template to create tasks in an epic. Replaces {variable} placeholders with provided values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_idYesTemplate ID to apply
epic_idYesEpic to create tasks in
variablesNoKey-value pairs for {variable} substitution (e.g., {"feature": "auth"})

Implementation Reference

  • The handleTemplateApply function implements the logic for the template_apply tool, including fetching the template and epic, performing variable substitution, and inserting new tasks into the database.
    function handleTemplateApply(args: Record<string, unknown>) {
      const db = getDb();
      const templateId = args.template_id as number;
      const epicId = args.epic_id as number;
      const variables = (args.variables as Record<string, string>) ?? {};
    
      const template = db.prepare('SELECT * FROM templates WHERE id = ?').get(templateId) as Record<string, unknown> | undefined;
      if (!template) throw new Error(`Template ${templateId} not found`);
    
      const epic = db.prepare('SELECT id, name FROM epics WHERE id = ?').get(epicId) as { id: number; name: string } | undefined;
      if (!epic) throw new Error(`Epic ${epicId} not found`);
    
      const taskDefs = JSON.parse(template.template_data as string) as Array<Record<string, unknown>>;
    
      const createdTasks = db.transaction(() => {
        return taskDefs.map((taskDef) => {
          const title = substituteVariables(taskDef.title as string, variables);
          const description = taskDef.description
            ? substituteVariables(taskDef.description as string, variables)
            : null;
          const priority = (taskDef.priority as string) ?? 'medium';
          const estimatedHours = (taskDef.estimated_hours as number) ?? null;
          const tags = JSON.stringify((taskDef.tags as string[]) ?? []);
    
          const task = db.prepare(
            `INSERT INTO tasks (epic_id, title, description, priority, estimated_hours, tags)
             VALUES (?, ?, ?, ?, ?, ?) RETURNING *`
          ).get(epicId, title, description, priority, estimatedHours, tags);
    
          const row = task as Record<string, unknown>;
          logActivity(db, 'task', row.id as number, 'created', null, null, null,
            `Task '${title}' created from template '${template.name}'`);
    
          return task;
        });
      })();
    
      return {
        message: `Applied template '${template.name}' to epic '${epic.name}'`,
        template_name: template.name,
        epic_name: epic.name,
        tasks_created: createdTasks.length,
        tasks: createdTasks,
      };
    }
  • The definition for the template_apply tool, specifying its name, description, and input schema.
      name: 'template_apply',
      description:
        'Apply a template to create tasks in an epic. Replaces {variable} placeholders with provided values.',
      annotations: { title: 'Apply Template', readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
      inputSchema: {
        type: 'object',
        properties: {
          template_id: { type: 'integer', description: 'Template ID to apply' },
          epic_id: { type: 'integer', description: 'Epic to create tasks in' },
          variables: {
            type: 'object',
            description: 'Key-value pairs for {variable} substitution (e.g., {"feature": "auth"})',
            additionalProperties: { type: 'string' },
          },
        },
        required: ['template_id', 'epic_id'],
      },
    },
  • Registration of the template_apply tool to its handler function in the exported handlers object.
    template_apply: handleTemplateApply,
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate this is a non-read-only, non-destructive, non-idempotent, non-open-world operation, but the description adds valuable context: it specifies that the tool creates tasks (a write action) and involves variable substitution. This clarifies the mutation behavior beyond the annotations, though it doesn't detail side effects like error handling or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loaded with the core action and resource, followed by a concise explanation of variable handling. Every word contributes to understanding, with no redundant or vague phrasing, making it highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, no output schema, and annotations covering safety aspects, the description is largely complete. It explains the tool's purpose and variable substitution, though it could benefit from mentioning expected outcomes (e.g., task creation details) or error conditions, given the lack of output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for template_id, epic_id, and variables. The description adds marginal value by explaining the purpose of variables ('for {variable} substitution') and providing an example ({"feature": "auth"}), but it doesn't significantly enhance the schema's documentation. Baseline 3 is appropriate given high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Apply a template'), the target resource ('to create tasks in an epic'), and the mechanism ('Replaces {variable} placeholders with provided values'). It distinguishes this tool from siblings like template_create, template_list, or task_create by focusing on template application rather than template management or direct task creation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when you need to generate tasks from a template with variable substitution, but it does not explicitly state when to use this tool versus alternatives like task_create (for individual tasks) or template_list (to find templates). No exclusions or prerequisites are mentioned, leaving the agent to infer context from the tool's purpose.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/spranab/saga-mcp'

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