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
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | ||
| output_dir | Yes | ||
| parameters | Yes | ||
| tool_name | Yes |
Implementation Reference
- src/tools/create-tool-template.ts:36-98 (handler)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 }], }; } );
- src/types.ts:22-30 (schema)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; }