list_templates
Browse available project templates to start new projects quickly. Filter by category to find relevant templates for your needs.
Instructions
List available project templates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Filter by category |
Implementation Reference
- src/tools/scaffold.ts:312-397 (handler)Implementation of the logic for listing templates.
async function listTemplatesImpl(input: ListTemplatesInput): Promise<ToolResult> { try { const templates: Array<{ name: string; path: string; description: string; category?: string; variables?: Array<{ name: string; description: string }>; }> = []; for (const basePath of getTemplatePaths()) { try { const entries = await fs.readdir(basePath, { withFileTypes: true }); for (const entry of entries) { if (!entry.isDirectory()) continue; const templatePath = path.join(basePath, entry.name); const metadataPath = path.join(templatePath, 'template.json'); let metadata: TemplateMetadata = { name: entry.name, description: 'Template directory', }; try { const metadataContent = await fs.readFile(metadataPath, 'utf-8'); metadata = JSON.parse(metadataContent) as TemplateMetadata; } catch { // No metadata file, use defaults } // Filter by category if specified if (input.category && metadata.category !== input.category) { continue; } templates.push({ name: metadata.name, path: templatePath, description: metadata.description, category: metadata.category, variables: metadata.variables?.map((v) => ({ name: v.name, description: v.description, })), }); } } catch { // Template path doesn't exist, skip } } return { content: [ { type: 'text', text: JSON.stringify( { template_paths: getTemplatePaths(), count: templates.length, templates, }, null, 2 ), }, ], }; } catch (error) { const err = error as Error; return { isError: true, content: [ { type: 'text', text: JSON.stringify({ code: 'UNKNOWN_ERROR', message: `Error listing templates: ${err.message}`, }), }, ], }; } } - src/tools/scaffold.ts:422-433 (registration)Registration of the 'list_templates' tool with the MCP server.
// list_templates tool server.tool( 'list_templates', 'List available project templates', { category: z.string().optional().describe('Filter by category'), }, async (args) => { const input = ListTemplatesInputSchema.parse(args); return await listTemplatesImpl(input); } ); - src/types.ts:268-272 (schema)Input schema definition for the list_templates tool.
export const ListTemplatesInputSchema = z.object({ category: z.string().optional().describe('Filter by category'), }); export type ListTemplatesInput = z.infer<typeof ListTemplatesInputSchema>;