Skip to main content
Glama

create_prompt_template

Generate template code for custom MCP prompts by specifying a name, description, and output directory. Includes optional variables for dynamic functionality.

Instructions

Generates template code for a new MCP prompt

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYes
include_variablesNo
output_dirYes
prompt_nameYes

Implementation Reference

  • Main handler function that validates input using Zod schema, compiles a Handlebars template with prompt details, generates camelCase and PascalCase variants, writes the new prompt TypeScript file to src/prompts/, and returns success/error details.
    export async function createPromptTemplate(
      options: PromptTemplateOptions
    ): Promise<{ success: boolean; message: string; filePath?: string }> {
      try {
        // Validate options
        const validatedOptions = promptTemplateSchema.parse(options);
    
        // Use the provided output directory (now required and absolute)
        const baseDir = validatedOptions.output_dir;
    
        // Ensure the prompts directory exists
        const promptsDir = path.join(baseDir, "src", "prompts");
        await ensureDir(promptsDir);
    
        // Generate the file path for the new prompt
        const promptFilename = `${validatedOptions.prompt_name.replace(
          /-/g,
          "_"
        )}.ts`;
        const promptFilePath = path.join(promptsDir, promptFilename);
    
        // Check if the file already exists
        const fileExists = await pathExists(promptFilePath);
        if (fileExists) {
          return {
            success: false,
            message: `A prompt with the name "${validatedOptions.prompt_name}" already exists at ${promptFilePath}`,
          };
        }
    
        // Generate the prompt content using the template
        const promptContent = await compileTemplate(getTemplatePath("prompt.hbs"), {
          ...validatedOptions,
          // Additional template variables
          prompt_camel_case: validatedOptions.prompt_name
            .replace(/-/g, "_")
            .replace(/_([a-z])/g, (_, char) => char.toUpperCase()),
          prompt_pascal_case: validatedOptions.prompt_name
            .replace(/-/g, "_")
            .split("_")
            .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
            .join(""),
        });
    
        // Write the prompt file
        await writeFile(promptFilePath, promptContent);
    
        console.log(
          chalk.green(
            `Prompt template generated successfully at: ${promptFilePath}`
          )
        );
    
        return {
          success: true,
          message: `Prompt template generated successfully at: ${promptFilePath}`,
          filePath: promptFilePath,
        };
      } catch (error: any) {
        console.error(chalk.red("Error creating prompt template:"), error);
        return {
          success: false,
          message: `Error creating prompt template: ${
            error.message || String(error)
          }`,
        };
      }
    }
  • Zod schema for input validation of createPromptTemplate, enforcing snake_case for prompt_name and absolute path for output_dir.
    export const promptTemplateSchema = z.object({
      prompt_name: z
        .string()
        .min(1)
        .refine((val) => /^[a-z0-9_-]+$/.test(val), {
          message: "Prompt name must be in snake_case (lowercase with underscores)",
        }),
      description: z.string().min(1),
      include_variables: z.boolean().optional().default(false),
      output_dir: z.string().refine((val) => path.isAbsolute(val), {
        message: "output_dir must be an absolute path",
      }),
    });
  • TypeScript interface defining the input parameters for the create_prompt_template tool.
    export interface PromptTemplateOptions {
      prompt_name: string;
      description: string;
      include_variables?: boolean;
      /**
       * Absolute path to the directory where the prompt should be generated
       */
      output_dir: string;
    }
  • src/server.ts:97-111 (registration)
    MCP server tool registration for 'create_prompt_template', including inline Zod input schema and handler invocation.
    server.tool(
      "create_prompt_template",
      "Generates template code for a new MCP prompt",
      {
        prompt_name: z.string().min(1),
        description: z.string().min(1),
        include_variables: z.boolean().optional(),
        output_dir: z.string(),
      },
      async (params: PromptTemplateOptions) => {
        const result = await createPromptTemplate(params);
        return {
          content: [{ type: "text", text: result.message }],
        };
      }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool generates code, implying a write operation, but doesn't cover critical aspects like file system effects (e.g., whether it overwrites existing files), permissions needed, error handling, or output format. This is a significant gap for a tool that likely creates files.

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 a single, efficient sentence that directly states the tool's function without any fluff. It's appropriately sized and front-loaded, making it easy to grasp immediately.

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

Completeness2/5

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

Given the complexity of a code-generation tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavior, parameter meanings, and expected outcomes, which are essential for effective use. The conciseness comes at the cost of necessary context.

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?

The schema description coverage is 0%, so the description must compensate, but it adds no parameter information beyond what's inferred from the tool name. It doesn't explain the meaning of parameters like 'include_variables' or 'output_dir', leaving them undocumented. However, the tool name and description imply parameters related to prompt creation, providing minimal context.

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

Purpose4/5

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

The description clearly states the action ('Generates') and the resource ('template code for a new MCP prompt'), making the purpose understandable. However, it doesn't differentiate this tool from its siblings like 'create_resource_template' or 'create_tool_template', which likely generate similar templates for different MCP components.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives such as 'create_resource_template' or 'generate_mcp_boilerplate'. There's no mention of prerequisites, typical scenarios, or exclusions, leaving usage context entirely implicit.

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

Related 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/CaptainCrouton89/mcp-maker'

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