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 }], }; }

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