template-list
Retrieve available code generation templates for TypeScript types, API clients, and config files. Filter by template type, framework, and include content details using the MCP server.
Instructions
Get available code generation template list
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| framework | No | Framework type filter (only for API client and config file templates) | |
| includeContent | No | Whether to include template content | |
| type | No | Template type filter |
Implementation Reference
- The primary handler function for the 'template-list' tool. It filters templates by optional type and framework parameters, optionally includes template content, handles errors, and returns a standardized MCP response with JSON data.private async listTemplates(params: { type?: string; framework?: string; includeContent?: boolean; }): Promise<any> { try { let templates: Template[] = []; // 根据类型过滤 if (params.type && params.type !== 'all') { const templateType = params.type as TemplateType; templates = this.templateManager.getTemplatesByType(templateType); // 根据框架类型进一步过滤 if (params.framework && (templateType === TemplateType.API_CLIENT || templateType === TemplateType.CONFIG_FILE)) { const frameworkType = params.framework as FrameworkType; templates = templates.filter(template => template.framework === frameworkType); } } else { templates = this.templateManager.getAllTemplates(); // 根据框架类型过滤 if (params.framework) { const frameworkType = params.framework as FrameworkType; templates = templates.filter(template => template.framework === frameworkType); } } // 处理返回结果 const result = templates.map(template => { const { content, ...rest } = template; // 如果不需要包含内容,则省略 if (!params.includeContent) { return rest; } return template; }); return { content: [ { type: 'text' as const, text: JSON.stringify({ success: true, templates: result }, null, 2) } ] }; } catch (error) { console.error('[TemplateManagerTool] 获取模板列表失败:', error); return { content: [ { type: 'text' as const, text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }, null, 2) } ] }; } }
- Input schema using Zod for validating parameters: type (optional enum for filtering by template type), framework (optional enum for framework filter), includeContent (optional boolean).type: z.enum(['all', 'api-client', 'typescript-types', 'config-file']).optional().describe('Template type filter'), framework: z.enum(['axios', 'fetch', 'react-query', 'swr', 'angular', 'vue']).optional().describe('Framework type filter (only for API client and config file templates)'), includeContent: z.boolean().optional().describe('Whether to include template content') },
- src/tools/template-manager-tool.ts:45-55 (registration)Registers the 'template-list' tool on the MCP server, providing name, description, input schema, and the handler function that delegates to listTemplates.TEMPLATE_LIST_TOOL_NAME, TEMPLATE_LIST_TOOL_DESCRIPTION, { type: z.enum(['all', 'api-client', 'typescript-types', 'config-file']).optional().describe('Template type filter'), framework: z.enum(['axios', 'fetch', 'react-query', 'swr', 'angular', 'vue']).optional().describe('Framework type filter (only for API client and config file templates)'), includeContent: z.boolean().optional().describe('Whether to include template content') }, async (params) => { return await this.listTemplates(params); } );
- src/index.ts:64-64 (registration)Top-level invocation that creates a TemplateManagerTool instance and calls its register method, thereby registering the 'template-list' tool (and others) with the main MCP server.new TemplateManagerTool().register(server);