Skip to main content
Glama
dh1789

My First MCP

by dh1789

analyze_structure

Analyzes project directory structures and displays them as tree diagrams to visualize file organization and hierarchy.

Instructions

프로젝트 디렉토리 구조를 분석하여 트리 형태로 보여줍니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes분석할 디렉토리 경로
maxDepthNo최대 깊이 (1-10). 기본값: 전체
showHiddenNo숨김 파일/폴더 표시 여부. 기본값: false

Implementation Reference

  • Core handler function implementing the directory structure analysis logic, including tree building and stats computation.
    export function analyzeStructure( targetPath: string, options: StructureOptions = {} ): StructureResult { const { maxDepth = Infinity, showHidden = false } = options; try { if (!fs.existsSync(targetPath)) { return { success: false, path: targetPath, error: `경로를 찾을 수 없습니다: ${targetPath}`, }; } const stats: DirectoryStats = { totalFiles: 0, totalDirs: 0 }; const tree = buildTree(targetPath, "", 0, maxDepth, showHidden, stats); return { success: true, path: targetPath, tree, stats, }; } catch (err) { return { success: false, path: targetPath, error: err instanceof Error ? err.message : String(err), }; } }
  • src/index.ts:417-457 (registration)
    MCP server.tool registration for 'analyze_structure', defining input schema with Zod and wrapper that invokes the core handler.
    server.tool( "analyze_structure", "프로젝트 디렉토리 구조를 분석하여 트리 형태로 보여줍니다.", { path: z.string().describe("분석할 디렉토리 경로"), maxDepth: z .number() .int() .min(1) .max(10) .optional() .describe("최대 깊이 (1-10). 기본값: 전체"), showHidden: z .boolean() .optional() .describe("숨김 파일/폴더 표시 여부. 기본값: false"), }, async ({ path: targetPath, maxDepth, showHidden }) => { const result = analyzeStructure(targetPath, { maxDepth, showHidden }); if (!result.success) { return { content: [{ type: "text", text: `오류: ${result.error}` }], isError: true, }; } const statsText = result.stats ? `\n\n📊 통계: ${result.stats.totalFiles}개 파일, ${result.stats.totalDirs}개 폴더` : ""; return { content: [ { type: "text", text: `📁 ${result.path}\n\n${result.tree}${statsText}`, }, ], }; } );
  • TypeScript interfaces defining input options (StructureOptions), stats (DirectoryStats), and output result (StructureResult) for the analyzeStructure function.
    export interface StructureOptions { maxDepth?: number; showHidden?: boolean; } /** * 디렉토리 통계 */ export interface DirectoryStats { totalFiles: number; totalDirs: number; } /** * 디렉토리 구조 분석 결과 */ export interface StructureResult { success: boolean; path: string; tree?: string; stats?: DirectoryStats; error?: string; }
  • Recursive helper function to build the visual directory tree string representation.
    function buildTree( dirPath: string, prefix: string, depth: number, maxDepth: number, showHidden: boolean, stats: DirectoryStats ): string { if (depth >= maxDepth) { return ""; } let result = ""; const entries = fs.readdirSync(dirPath, { withFileTypes: true }); // 숨김 파일 필터링 및 정렬 (디렉토리 먼저) const filtered = entries .filter((e) => showHidden || !e.name.startsWith(".")) .sort((a, b) => { if (a.isDirectory() && !b.isDirectory()) return -1; if (!a.isDirectory() && b.isDirectory()) return 1; return a.name.localeCompare(b.name); }); for (let i = 0; i < filtered.length; i++) { const entry = filtered[i]; const isLast = i === filtered.length - 1; const connector = isLast ? "└── " : "├── "; const newPrefix = prefix + (isLast ? " " : "│ "); if (entry.isDirectory()) { stats.totalDirs++; result += `${prefix}${connector}${entry.name}/\n`; result += buildTree( path.join(dirPath, entry.name), newPrefix, depth + 1, maxDepth, showHidden, stats ); } else { stats.totalFiles++; result += `${prefix}${connector}${entry.name}\n`; } } return result; }

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/dh1789/my-first-mcp'

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