get_workflow_template
Retrieve a saved workflow template's JSON and metadata by specifying the template name. Use this to load predefined ComfyUI workflows for reuse.
Instructions
Fetch a saved workflow template's JSON and metadata.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Template name. |
Implementation Reference
- src/tools/templates.ts:180-196 (registration)Registration of the 'get_workflow_template' tool on the MCP server using server.tool().
server.tool( "get_workflow_template", "Fetch a saved workflow template's JSON and metadata.", getSchema, async (args) => { validateName(args.name); let raw: string; try { raw = await fs.readFile(templatePath(store.dir, args.name), "utf-8"); } catch { throw new Error(`Template "${args.name}" not found.`); } return { content: [{ type: "text" as const, text: raw }], }; }, ); - src/tools/templates.ts:184-195 (handler)Handler function for get_workflow_template: validates name, reads the JSON file from the template store directory, and returns the raw text content.
async (args) => { validateName(args.name); let raw: string; try { raw = await fs.readFile(templatePath(store.dir, args.name), "utf-8"); } catch { throw new Error(`Template "${args.name}" not found.`); } return { content: [{ type: "text" as const, text: raw }], }; }, - src/tools/templates.ts:58-60 (schema)Input schema for get_workflow_template: requires a 'name' string parameter.
const getSchema = { name: z.string().describe("Template name."), }; - src/tools/templates.ts:18-20 (helper)Helper function templatePath that constructs the file path by joining the store directory with the template name plus '.json'.
function templatePath(dir: string, name: string): string { return path.join(dir, `${name}.json`); } - src/tools/templates.ts:22-28 (helper)Helper function validateName that validates the template name against the allowed pattern.
function validateName(name: string): void { if (!TEMPLATE_NAME_PATTERN.test(name)) { throw new Error( `Invalid template name "${name}". Must start with alphanumeric; only letters, digits, '-', '_' allowed; max 64 chars.`, ); } }