Skip to main content
Glama

generate_structure

Generates a project's directory structure and detailed documentation including file contents, helping you understand repository or folder contents.

Instructions

プロジェクトのディレクトリ構造を生成し、ファイル内容も含めた詳細なドキュメントを作成します。プロジェクトやリポジトリ、フォルダの内容を理解するときに使用します。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes構造を生成するディレクトリの絶対パス
ignorePathNo.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;
    }
  • 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'],
            },
          },
        ],
      }));
  • 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,
            },
          ],
        };
      });
    }
  • Input type definition: GenerateStructureArgs interface with path (string) and optional ignorePath (string).
    export interface GenerateStructureArgs {
      path: string;
      ignorePath?: string;
    }
  • 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');
    };
Behavior3/5

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

No annotations provided, so the description must cover behavioral aspects. It mentions reading file contents and generating a document, but does not disclose side effects, permissions, or performance considerations. Basic transparency but lacks depth.

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

Conciseness4/5

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

The description is a single sentence, concise and front-loaded with the core action. It wastes no words but could be slightly more structured.

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

Completeness3/5

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

No output schema exists, so the description should clarify the output format. It only says 'detailed document' without specifying the type or delivery method. Missing details for a complete understanding.

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?

Schema coverage is 100% with parameter descriptions already present. The description adds context about use cases but no additional semantic information beyond what the schema provides.

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

Purpose5/5

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

The description clearly states that the tool generates a directory structure and a detailed document including file contents, with a specific use case. The verb 'generate' and resource 'directory structure' are distinct and unambiguous.

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

Usage Guidelines3/5

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

The description implies usage for understanding project contents but does not provide when-not-to-use or alternatives. Since there are no sibling tools, it is minimally adequate.

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/Sunwood-ai-labs/source-sage-mcp-server'

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