generate_structure
Generates detailed project directory structures in Markdown format, including file contents with syntax highlighting, to help understand and document repository or folder contents. Supports customizable exclusions for precise output.
Instructions
プロジェクトのディレクトリ構造を生成し、ファイル内容も含めた詳細なドキュメントを作成します。プロジェクトやリポジトリ、フォルダの内容を理解するときに使用します。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ignorePath | No | .SourceSageignoreファイルの絶対パス(オプション) | |
| path | Yes | 構造を生成するディレクトリの絶対パス |
Implementation Reference
- src/server/tool-handlers.ts:31-52 (registration)Registers the 'generate_structure' tool with name, description, and input schema in the MCP server's listTools handler.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'generate_structure', description: 'プロジェクトのディレクトリ構造を生成し、ファイル内容も含めた詳細なドキュメントを作成します。プロジェクトやリポジトリ、フォルダの内容を理解するときに使用します。', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '構造を生成するディレクトリの絶対パス', }, ignorePath: { type: 'string', description: '.SourceSageignoreファイルの絶対パス(オプション)', }, }, required: ['path'], }, }, ], }));
- src/server/tool-handlers.ts:60-83 (handler)MCP callTool request handler for 'generate_structure': checks name, validates args, invokes StructureGenerator, returns markdown text content.if (request.params.name !== 'generate_structure') { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!isGenerateStructureArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid arguments for generate_structure' ); } const structure = await this.structureGenerator.generateStructure(request.params.arguments); return { content: [ { type: 'text', text: structure, }, ], };
- Core implementation of generate_structure: generates directory tree, file stats, contents, and saves summary.md to .SourceSageAssets.public async generateStructure(args: GenerateStructureArgs): Promise<string> { const targetPath = path.resolve(args.path); if (!fs.existsSync(targetPath)) { throw new McpError( ErrorCode.InvalidParams, `Directory not found: ${targetPath}` ); } const files = await getFileList(targetPath, args.ignorePath); const tree = this.treeBuilder.buildTree(targetPath, files); const output = [ `# 📁 Project: ${path.basename(targetPath)}`, '', '## 🌳 ディレクトリ構造', '', '```plaintext', `OS: ${process.platform}`, `Directory: ${targetPath}`, `Ignore File: ${args.ignorePath || '.SourceSageignore (auto-generated)'}`, '', ...this.treeBuilder.printTree(tree), '```', ]; // 統計情報を追加 const [statsOutput] = await this.generateFileStats(targetPath, files); output.push(...statsOutput); // ファイル内容を追加 output.push(...await this.generateFileContents(targetPath, files)); const content = output.join('\n'); // .SourceSageAssetsフォルダを作成して保存 const assetsDir = path.join(targetPath, '.SourceSageAssets'); if (!fs.existsSync(assetsDir)) { fs.mkdirSync(assetsDir, { recursive: true }); } fs.writeFileSync(path.join(assetsDir, 'Repository_summary.md'), content, 'utf-8'); return content; }
- src/types/types.ts:4-7 (schema)TypeScript interface defining input parameters for generate_structure tool.export interface GenerateStructureArgs { path: string; ignorePath?: string; }
- src/utils/validation.ts:6-11 (helper)Type guard function to validate tool arguments conform to GenerateStructureArgs.export const isGenerateStructureArgs = (args: unknown): args is GenerateStructureArgs => { if (typeof args !== 'object' || args === null) return false; const obj = args as Record<string, unknown>; return typeof obj.path === 'string' && (obj.ignorePath === undefined || typeof obj.ignorePath === 'string'); };