Skip to main content
Glama

count_files

Analyze directory structures to generate markdown trees with file and folder counts for codebase understanding, issue identification, and technical debt assessment.

Instructions

Analyze directory structure and generate markdown directory tree with file and folder counts

WORKFLOW: Perfect for understanding complex code, identifying issues, and technical debt assessment TIP: Use Desktop Commander to read files, then pass content here for analysis SAVES: Claude context for strategic decisions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
analysisDepthNoLevel of analysis detaildetailed
analysisTypeNoType of analysis to performcomprehensive
codeNoThe code to analyze (for single-file analysis)
filePathNoPath to single file to analyze
filesNoArray of specific file paths (for multi-file analysis)
languageNoProgramming languagejavascript
maxDepthNoMaximum directory depth for discovery (1-10)
projectPathNoPath to directory root to analyze

Implementation Reference

  • Main execution handler for the count_files tool. Detects analysis mode, validates params, sets up model, and routes to single-file or multi-file analysis.
    async execute(params: any, llmClient: any) { return await withSecurity(this, params, llmClient, async (secureParams) => { try { // 1. Auto-detect analysis mode based on parameters const analysisMode = this.detectAnalysisMode(secureParams); // 2. Validate parameters based on detected mode this.validateParameters(secureParams, analysisMode); // 3. Setup model const { model, contextLength } = await ModelSetup.getReadyModel(llmClient); // 4. Route to appropriate analysis method if (analysisMode === 'single-file') { return await this.executeSingleFileAnalysis(secureParams, model, contextLength); } else { return await this.executeMultiFileAnalysis(secureParams, model, contextLength); } } catch (error: any) { return ErrorHandler.createExecutionError('count_files', error); } }); }
  • Parameter schema defining inputs for single-file and multi-file analysis modes, including projectPath for directory counting.
    parameters = { // Single-file parameters code: { type: 'string' as const, description: 'The code to analyze (for single-file analysis)', required: false }, filePath: { type: 'string' as const, description: 'Path to single file to analyze', required: false }, // Multi-file parameters projectPath: { type: 'string' as const, description: 'Path to directory root to analyze', required: false }, files: { type: 'array' as const, description: 'Array of specific file paths (for multi-file analysis)', required: false, items: { type: 'string' as const } }, maxDepth: { type: 'number' as const, description: 'Maximum directory depth for discovery (1-10)', required: false, default: 5 }, // Universal parameters language: { type: 'string' as const, description: 'Programming language', required: false, default: 'javascript' }, analysisDepth: { type: 'string' as const, description: 'Level of analysis detail', enum: ['basic', 'detailed', 'comprehensive'], default: 'detailed', required: false }, analysisType: { type: 'string' as const, description: 'Type of analysis to perform', enum: ['structure', 'counts', 'comprehensive'], default: 'comprehensive', required: false } };
  • Registers the plugin instance by its name ('count_files') in the plugin map, enabling lookup and execution.
    registerPlugin(plugin: IPromptPlugin): void { // Validate plugin has required properties if (!plugin.name || !plugin.category || !plugin.execute) { throw new Error('Invalid plugin: missing required properties'); } // Register in main map this.plugins.set(plugin.name, plugin); // Register in category map const categoryPlugins = this.categories.get(plugin.category) || []; categoryPlugins.push(plugin); this.categories.set(plugin.category, categoryPlugins); }
  • Dynamically loads and instantiates plugins from prompts/analyze directory, including count-files.ts, then registers them.
    private async loadPlugin(filePath: string, category: 'analyze' | 'generate' | 'custom' | 'system'): Promise<void> { try { // Skip .d.ts files (TypeScript declaration files) if (filePath.endsWith('.d.ts')) { return; } // Use pathToFileURL for proper ES module loading on Windows const fileUrl = pathToFileURL(filePath).href; const module = await import(fileUrl); const PluginClass = module.default; if (PluginClass && typeof PluginClass === 'function') { const plugin = new PluginClass(); if (plugin instanceof BasePlugin) { this.registerPlugin(plugin); // Removed console.log to avoid JSON-RPC interference } } } catch (error) { // Silent error handling to avoid JSON-RPC interference // console.error(`Error loading plugin from ${filePath}:`, error); } }
  • Helper function that analyzes individual files to gather stats like size, lines, extension for counting and structure analysis.
    private async analyzeIndividualFile(file: string, params: any, model: any): Promise<any> { const content = await import('fs/promises').then(fs => fs.readFile(file, 'utf-8')); const stats = await import('fs/promises').then(fs => fs.stat(file)); return { filePath: file, size: content.length, lines: content.split('\n').length, extension: file.split('.').pop() || '', isDirectory: stats.isDirectory(), modified: stats.mtime }; }

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/houtini-ai/lm'

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