Skip to main content
Glama

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
NameRequiredDescriptionDefault
categoryNoFilter by category

Implementation Reference

  • 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}`,
              }),
            },
          ],
        };
      }
    }
  • 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);
      }
    );
  • 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>;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp-tool-shop-org/mcp-file-forge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server