list_custom_templates
List your custom-uploaded Word templates referenced by UUID. Retrieve template details like available page sizes and orientations.
Instructions
List only the user's custom-uploaded Word templates. Use this when the user asks about their own templates ('show me my templates', 'do I have a letterhead?'). Custom templates are referenced by UUID, not name, when calling convert_document.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeDetails | No | Include template details like available page sizes and orientations (default: false) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of custom templates returned | |
| templates | Yes | User's custom templates |
Implementation Reference
- src/tools/listTemplates.ts:132-186 (handler)The handler function that executes the 'list_custom_templates' tool logic. It parses input, calls apiClient.getCustomTemplates(), and returns a formatted list of custom templates.
export async function handleListCustomTemplates( apiClient: MDMagicApiClient, args: any ): Promise<CallToolResult> { try { const input = listCustomTemplatesSchema.parse(args); console.error('[list_custom_templates] Fetching custom templates...'); const response = await apiClient.getCustomTemplates(); const templates = response.templates || []; if (templates.length === 0) { return { content: [ { type: "text", text: `🎨 **No custom templates available** You don't have any custom templates yet. Custom templates are user-specific templates that you can upload through the MDMagic dashboard. 💡 **To add custom templates:** 1. Visit your MDMagic dashboard 2. Go to Templates section 3. Upload your custom Word (.docx) templates` } ] }; } let output = `🎨 **Your Custom Templates** (${templates.length} available)\n\n`; templates.forEach(template => { output += `**${template.name}** (\`${template.id}\`)\n`; if (template.description) { output += ` ${template.description}\n`; } output += ` 📁 Type: ${template.type}\n\n`; }); output += '💡 **Usage:** Use the template ID (in backticks) with the `convert_document` tool.'; return { content: [ { type: "text", text: output } ] }; } catch (error: any) { console.error('[list_custom_templates] Error:', error.message); throw error; } } - src/utils/validation.ts:37-39 (schema)Zod schema for validating list_custom_templates input: accepts optional includeDetails boolean.
export const listCustomTemplatesSchema = z.object({ includeDetails: z.boolean().default(false).describe("Include template details") }); - src/tools/index.ts:39-79 (registration)Switch-case registration in the unified handler that routes 'list_custom_templates' to handleListCustomTemplates.
case 'list_custom_templates': return await handleListCustomTemplates(apiClient, request.params.arguments); case 'show_default_settings': return await handleShowDefaultSettings(apiClient, request.params.arguments); case 'check_credit_balance': return await handleCheckCreditBalance(creditCalculator, request.params.arguments); case 'estimate_conversion_cost': return await handleEstimateConversionCost(creditCalculator, request.params.arguments); case 'validate_markdown': return await handleValidateMarkdown(apiClient, request.params.arguments); case 'get_template_details': return await handleGetTemplateDetails(apiClient, request.params.arguments); case 'recommend_template': return await handleRecommendTemplate(apiClient, request.params.arguments); default: throw new Error(`Unknown tool: ${toolName}`); } } catch (error: any) { console.error(`[MCP] Error handling ${toolName}:`, error); return { content: [ { type: "text", text: `❌ Error: ${error.message}` } ], isError: true }; } }); console.error('✅ All MCP tools registered successfully with unified handler'); console.error('📋 Available tools: convert_document, list_all_templates, list_builtin_templates, list_custom_templates, show_default_settings, check_credit_balance, estimate_conversion_cost, validate_markdown, get_template_details, recommend_template'); } - src/index.ts:171-198 (registration)Tool definition registration including name, description, annotations, inputSchema, and outputSchema exposed to the MCP protocol.
{ name: "list_custom_templates", description: "List only the user's custom-uploaded Word templates. Use this when the user asks about their own templates ('show me my templates', 'do I have a letterhead?'). Custom templates are referenced by UUID, not name, when calling convert_document.", annotations: { title: "List user's custom templates", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }, inputSchema: { type: "object" as const, properties: { includeDetails: { type: "boolean", description: "Include template details like available page sizes and orientations (default: false)" } } }, outputSchema: { type: "object" as const, properties: { count: { type: "integer", description: "Number of custom templates returned" }, templates: { type: "array", items: TEMPLATE_OBJECT_SCHEMA, description: "User's custom templates" } }, required: ["templates"] } },