template-list
Retrieve available code generation templates for Swagger/OpenAPI documents, filtering by template type and framework to generate TypeScript types and API client code.
Instructions
Get available code generation template list
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "template-list"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | Template type filter | |
| framework | No | Framework type filter (only for API client and config file templates) | |
| includeContent | No | Whether to include template content |
Implementation Reference
- Core implementation of the template-list tool handler. Filters and lists templates by type and framework, optionally includes content, returns JSON response.
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 the template-list tool, defining optional parameters for filtering templates.
{ 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:44-55 (registration)Registration of the 'template-list' tool on the MCP server, specifying name, description, input schema, and handler function.
server.tool( 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); } );