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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool displays structure in tree form, which implies a read-only operation, but doesn't cover other important traits like whether it requires specific permissions, handles errors (e.g., invalid paths), or has performance considerations (e.g., large directories). For a tool with 3 parameters and no annotations, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Korean that directly states the tool's function without unnecessary details. It's appropriately sized and front-loaded, with every word contributing to understanding the core purpose. There's no waste or redundancy, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (3 parameters, no output schema, no annotations), the description is incomplete. It lacks information on behavioral traits (e.g., error handling, permissions), usage context relative to siblings, and output details (since there's no output schema, the description should hint at return values like tree structure format). For a directory analysis tool, this leaves gaps that could hinder agent effectiveness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter semantics beyond what the input schema provides. Since schema description coverage is 100%, the schema already documents all parameters ('path', 'maxDepth', 'showHidden') with descriptions and constraints. The description doesn't explain how these parameters interact (e.g., how 'maxDepth' affects the tree output) or provide additional context, so it meets the baseline of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '프로젝트 디렉토리 구조를 분석하여 트리 형태로 보여줍니다' (Analyzes project directory structure and displays it in tree form). It specifies the verb ('analyzes'), resource ('project directory structure'), and output format ('tree form'), which is clear and specific. However, it doesn't explicitly differentiate from siblings like 'analyze_dependencies' or 'count_lines', which could help an agent choose correctly.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention scenarios where this tool is preferred over siblings (e.g., 'analyze_dependencies' for dependency analysis or 'count_lines' for file content analysis), nor does it specify prerequisites or exclusions. This lack of context makes it harder for an agent to select the right tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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