generate_structure
Generates a project's directory structure and detailed documentation including file contents, helping you understand repository or folder contents.
Instructions
プロジェクトのディレクトリ構造を生成し、ファイル内容も含めた詳細なドキュメントを作成します。プロジェクトやリポジトリ、フォルダの内容を理解するときに使用します。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | 構造を生成するディレクトリの絶対パス | |
| ignorePath | No | .SourceSageignoreファイルの絶対パス(オプション) |
Implementation Reference
- Main handler: generates project structure (directory tree, file stats, file contents) using the given path and optional ignorePath. Validates path, builds tree via TreeBuilder, generates markdown output, and saves to .SourceSageAssets/Repository_summary.md.
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/server/tool-handlers.ts:30-52 (registration)Registration: lists 'generate_structure' tool with description and inputSchema (path required, ignorePath optional) via ListToolsRequestSchema.
private setupListToolsHandler(): void { 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:58-85 (handler)Call handler: routes CallToolRequest for 'generate_structure', validates args via isGenerateStructureArgs, invokes StructureGenerator.generateStructure, returns result as text content.
private setupCallToolHandler(): void { this.server.setRequestHandler(CallToolRequestSchema, async (request) => { 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, }, ], }; }); } - src/types/types.ts:4-7 (schema)Input type definition: GenerateStructureArgs interface with path (string) and optional ignorePath (string).
export interface GenerateStructureArgs { path: string; ignorePath?: string; } - src/utils/validation.ts:6-11 (helper)Type guard helper: isGenerateStructureArgs validates that args is an object with string path and optional string ignorePath.
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'); };