Skip to main content
Glama

read_project_structure

Analyze project directory structure to generate hierarchical file and folder trees for documentation preparation.

Instructions

Read the directory structure of a project. Returns a tree-like structure of files and folders.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe absolute path to the project directory
maxDepthNoMaximum depth to traverse (default: 3)

Implementation Reference

  • Handler for the 'read_project_structure' tool. Extracts path and optional maxDepth from arguments, calls getDirectoryStructure helper, and returns the directory structure as JSON-formatted text content.
    case "read_project_structure": { const { path, maxDepth = 3 } = args as { path: string; maxDepth?: number; }; const structure = await getDirectoryStructure(path, maxDepth); return { content: [ { type: "text", text: JSON.stringify(structure, null, 2), }, ], }; }
  • src/index.ts:391-409 (registration)
    Tool registration in the ListTools response, including name, description, and input schema definition.
    name: "read_project_structure", description: "Read the directory structure of a project. Returns a tree-like structure of files and folders.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The absolute path to the project directory", }, maxDepth: { type: "number", description: "Maximum depth to traverse (default: 3)", default: 3, }, }, required: ["path"], }, },
  • Input schema for the 'read_project_structure' tool, defining path (required) and optional maxDepth parameters.
    inputSchema: { type: "object", properties: { path: { type: "string", description: "The absolute path to the project directory", }, maxDepth: { type: "number", description: "Maximum depth to traverse (default: 3)", default: 3, }, }, required: ["path"], },
  • Recursive helper function that builds the directory tree structure, ignoring common patterns like node_modules, with configurable max depth.
    async function getDirectoryStructure( dirPath: string, maxDepth: number = 3, currentDepth: number = 0, ignorePatterns: string[] = [ "node_modules", ".git", "dist", "build", ".next", "coverage", ], ): Promise<any> { if (currentDepth >= maxDepth) { return null; } try { const entries = await readdir(dirPath, { withFileTypes: true }); const structure: any = { type: "directory", name: parse(dirPath).base || dirPath, children: [], }; for (const entry of entries) { if (ignorePatterns.some((pattern) => entry.name.includes(pattern))) { continue; } const fullPath = join(dirPath, entry.name); if (entry.isDirectory()) { const subStructure = await getDirectoryStructure( fullPath, maxDepth, currentDepth + 1, ignorePatterns, ); if (subStructure) { structure.children.push(subStructure); } } else { structure.children.push({ type: "file", name: entry.name, path: fullPath, }); } } return structure; } catch (error) { throw new Error(`Failed to read directory: ${error}`); } }

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/JojoSlice/README-Gen-MCP-Server'

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