Skip to main content
Glama

create_tool_template

Generate customizable template code for new MCP tools, including tool name, parameters, and descriptions, to streamline development on the MCP Maker server.

Instructions

Generates template code for a new MCP tool with customizable parameters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYes
output_dirYes
parametersYes
tool_nameYes

Implementation Reference

  • The async handler function that executes the tool's logic: validates input with Zod schema, ensures directories, checks for existing files, compiles a Handlebars template with tool details, writes the new tool TypeScript file, and returns success/error messages.
    export async function createToolTemplate(
      options: ToolTemplateOptions
    ): Promise<{ success: boolean; message: string; filePath?: string }> {
      try {
        // Validate options
        const validatedOptions = toolTemplateSchema.parse(options);
    
        // Use the provided output directory (now required and absolute)
        const baseDir = validatedOptions.output_dir;
    
        // Ensure the tools directory exists
        const toolsDir = path.join(baseDir, "src", "tools");
        await ensureDir(toolsDir);
    
        // Generate the file path for the new tool
        const toolFilename = `${validatedOptions.tool_name.replace(/-/g, "_")}.ts`;
        const toolFilePath = path.join(toolsDir, toolFilename);
    
        // Check if the file already exists
        const fileExists = await pathExists(toolFilePath);
        if (fileExists) {
          return {
            success: false,
            message: `A tool with the name "${validatedOptions.tool_name}" already exists at ${toolFilePath}`,
          };
        }
    
        // Generate the tool content using the template
        const toolContent = await compileTemplate(getTemplatePath("tool.hbs"), {
          ...validatedOptions,
          // Additional template variables
          tool_camel_case: validatedOptions.tool_name
            .replace(/-/g, "_")
            .replace(/_([a-z])/g, (_, char) => char.toUpperCase()),
          tool_pascal_case: validatedOptions.tool_name
            .replace(/-/g, "_")
            .split("_")
            .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
            .join(""),
        });
    
        // Write the tool file
        await writeFile(toolFilePath, toolContent);
    
        console.log(
          chalk.green(`Tool template generated successfully at: ${toolFilePath}`)
        );
    
        return {
          success: true,
          message: `Tool template generated successfully at: ${toolFilePath}`,
          filePath: toolFilePath,
        };
      } catch (error: any) {
        console.error(chalk.red("Error creating tool template:"), error);
        return {
          success: false,
          message: `Error creating tool template: ${
            error.message || String(error)
          }`,
        };
      }
    }
  • Zod validation schema used internally by the handler to parse and validate input parameters, enforcing snake_case tool_name, absolute output_dir, and structured parameters array.
    export const toolTemplateSchema = z.object({
      tool_name: z
        .string()
        .min(1)
        .refine((val) => /^[a-z0-9_-]+$/.test(val), {
          message: "Tool name must be in snake_case (lowercase with underscores)",
        }),
      description: z.string().min(1),
      parameters: z.array(
        z.object({
          name: z.string().min(1),
          type: z.enum(["string", "number", "boolean", "array", "object"]),
          required: z.boolean(),
          description: z.string().min(1),
        })
      ),
      output_dir: z.string().refine((val) => path.isAbsolute(val), {
        message: "output_dir must be an absolute path",
      }),
    });
  • src/server.ts:54-76 (registration)
    MCP server registration of the 'create_tool_template' tool, providing name, description, input Zod schema (matches internal schema, but output_dir not strictly absolute), and async wrapper that invokes the handler and formats response as MCP content.
    server.tool(
      "create_tool_template",
      "Generates template code for a new MCP tool with customizable parameters",
      {
        tool_name: z.string().min(1),
        description: z.string().min(1),
        parameters: z.array(
          z.object({
            name: z.string().min(1),
            type: z.enum(["string", "number", "boolean", "array", "object"]),
            required: z.boolean(),
            description: z.string().min(1),
          })
        ),
        output_dir: z.string(),
      },
      async (params: ToolTemplateOptions) => {
        const result = await createToolTemplate(params);
        return {
          content: [{ type: "text", text: result.message }],
        };
      }
    );
  • TypeScript interface defining the expected input shape for the tool, matching the Zod schema; used for type annotations in handler and registration.
    export interface ToolTemplateOptions {
      tool_name: string;
      description: string;
      parameters: ToolParameter[];
      /**
       * Absolute path to the directory where the tool should be generated
       */
      output_dir: string;
    }
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. While 'Generates template code' implies a creation/write operation, the description doesn't specify what happens to existing files, whether it overwrites or creates new files, what permissions are needed, or what the output looks like. For a tool that creates files with 4 required parameters, this is insufficient behavioral context.

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 gets straight to the point. It's appropriately sized for the tool's complexity, with no wasted words or unnecessary elaboration. The structure is front-loaded with the core functionality immediately clear.

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?

For a tool with 4 required parameters, 0% schema description coverage, no annotations, and no output schema, the description is incomplete. It doesn't explain what the generated template includes, what format it produces, how parameters affect the output, or what happens in the output_dir. The description leaves too many open questions about the tool's behavior and output.

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

Parameters2/5

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

Schema description coverage is 0%, meaning none of the 4 parameters have descriptions in the schema. The description mentions 'customizable parameters' but doesn't explain what those parameters are or their purposes. It doesn't compensate for the complete lack of parameter documentation in the schema, leaving all 4 required parameters (tool_name, description, parameters, output_dir) semantically undefined.

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 tool's purpose: 'Generates template code for a new MCP tool with customizable parameters'. It specifies the verb ('Generates'), resource ('template code'), and scope ('new MCP tool'), but doesn't explicitly differentiate it from sibling tools like 'create_prompt_template' or 'generate_mcp_boilerplate' which might have overlapping functionality.

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. With siblings like 'create_prompt_template', 'create_resource_template', and 'generate_mcp_boilerplate', there's no indication of which tool to choose for different template generation scenarios. The description only states what it does, not when it's appropriate.

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