Skip to main content
Glama

githubViewRepoStructure

Read-onlyIdempotent

Explore GitHub repository directory structures to understand layout, locate files, and analyze configurations by navigating through folders with controlled depth parameters.

Instructions

Display directory structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queriesYesResearch queries for githubViewRepoStructure (1-3 queries per call for optimal resource management). Review schema before use for optimal results

Implementation Reference

  • Registration of the githubViewRepoStructure tool, including inline handler that delegates to exploreMultipleRepositoryStructures
    export function registerViewGitHubRepoStructureTool(
      server: McpServer,
      callback?: ToolInvocationCallback
    ) {
      return server.registerTool(
        TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE,
        {
          description: DESCRIPTIONS[TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE],
          inputSchema: GitHubViewRepoStructureBulkQuerySchema,
          annotations: {
            title: 'GitHub Repository Structure Explorer',
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: true,
          },
        },
        withSecurityValidation(
          TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE,
          async (
            args: {
              queries: GitHubViewRepoStructureQuery[];
            },
            authInfo,
            sessionId
          ): Promise<CallToolResult> => {
            const queries = args.queries || [];
    
            await invokeCallbackSafely(
              callback,
              TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE,
              queries
            );
    
            return exploreMultipleRepositoryStructures(
              queries,
              authInfo,
              sessionId
            );
          }
        )
      );
    }
  • Core handler logic: processes bulk queries, calls GitHub API via viewGitHubRepositoryStructureAPI, filters structure, handles errors and pagination, formats results
    async function exploreMultipleRepositoryStructures(
      queries: GitHubViewRepoStructureQuery[],
      authInfo?: AuthInfo,
      sessionId?: string
    ): Promise<CallToolResult> {
      return executeBulkOperation(
        queries,
        async (query: GitHubViewRepoStructureQuery, _index: number) => {
          try {
            const apiRequest = buildStructureApiRequest(query);
    
            const apiResult = await viewGitHubRepositoryStructureAPI(
              apiRequest,
              authInfo,
              sessionId
            );
    
            const apiError = handleApiError(apiResult, query);
            if (apiError) {
              return createEmptyStructureResult(query, apiError);
            }
    
            if (!('structure' in apiResult) || !apiResult.structure) {
              return createEmptyStructureResult(
                query,
                handleCatchError(
                  new Error('Invalid API response structure'),
                  query
                )!
              );
            }
    
            const filteredStructure = filterStructure(apiResult.structure);
    
            const hasContent = Object.keys(filteredStructure).length > 0;
    
            // Build result data with pagination info
            const resultData: Record<string, unknown> = {
              owner: apiRequest.owner,
              repo: apiRequest.repo,
              branch: apiResult.branch ?? apiRequest.branch,
              path: apiRequest.path || '/',
              structure: filteredStructure,
              summary: apiResult.summary,
            };
    
            // Include pagination info if present
            if (apiResult.pagination) {
              resultData.pagination = apiResult.pagination;
            }
    
            // Extract API-generated hints (pagination hints, etc.)
            const apiHints = apiResult.hints || [];
    
            // Count entries for context-aware hints
            const entryCount = Object.values(filteredStructure).reduce(
              (sum, entry) => sum + entry.files.length + entry.folders.length,
              0
            );
    
            // Use unified pattern: context for dynamic hints, extraHints for API pagination hints
            return createSuccessResult(
              query,
              resultData,
              hasContent,
              TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE,
              {
                hintContext: { entryCount },
                extraHints: apiHints,
              }
            );
          } catch (error) {
            const catchError = handleCatchError(
              error,
              query,
              'Failed to explore repository structure'
            );
            return createEmptyStructureResult(query, catchError);
          }
        },
        {
          toolName: TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE,
          keysPriority: [
            'owner',
            'repo',
            'branch',
            'path',
            'structure',
            'error',
          ] satisfies Array<keyof RepoStructureResult>,
        }
      );
    }
  • Zod schema for GitHubViewRepoStructureQuery input validation
    export const GitHubViewRepoStructureQuerySchema = BaseQuerySchema.extend({
      owner: z
        .string()
        .min(1)
        .max(200)
        .describe(GITHUB_VIEW_REPO_STRUCTURE.scope.owner),
      repo: z
        .string()
        .min(1)
        .max(150)
        .describe(GITHUB_VIEW_REPO_STRUCTURE.scope.repo),
      branch: z
        .string()
        .min(1)
        .max(255)
        .describe(GITHUB_VIEW_REPO_STRUCTURE.scope.branch),
      path: z
        .string()
        .default('')
        .optional()
        .describe(GITHUB_VIEW_REPO_STRUCTURE.scope.path),
      depth: z
        .number()
        .min(1)
        .max(2)
        .default(1)
        .optional()
        .describe(GITHUB_VIEW_REPO_STRUCTURE.range.depth),
      entriesPerPage: z
        .number()
        .min(1)
        .max(GITHUB_STRUCTURE_DEFAULTS.MAX_ENTRIES_PER_PAGE)
        .default(GITHUB_STRUCTURE_DEFAULTS.ENTRIES_PER_PAGE)
        .optional()
        .describe(GITHUB_VIEW_REPO_STRUCTURE.pagination.entriesPerPage),
      entryPageNumber: z
        .number()
        .min(1)
        .default(1)
        .optional()
        .describe(GITHUB_VIEW_REPO_STRUCTURE.pagination.entryPageNumber),
    });
  • Tool configuration entry that registers the tool via registerTools in toolsManager.ts
    export const GITHUB_VIEW_REPO_STRUCTURE: ToolConfig = {
      name: TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE,
      description: getDescription(TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE),
      isDefault: true,
      isLocal: false,
      type: 'content',
      fn: registerViewGitHubRepoStructureTool,
    };
  • Bulk query schema for handling multiple repo structure queries in a single tool call
    export const GitHubViewRepoStructureBulkQuerySchema = createBulkQuerySchema(
      TOOL_NAMES.GITHUB_VIEW_REPO_STRUCTURE,
      GitHubViewRepoStructureQuerySchema
    );
Behavior5/5

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

The description adds substantial behavioral context beyond annotations: it explains auto-filtering of 85+ directories, truncation limits (max 200 items, 50 per depth), performance characteristics (depth=2 is slow), and monorepo handling. While annotations cover safety (readOnlyHint=true), the description provides practical implementation details that help the agent use the tool effectively.

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 well-structured with clear sections (<when>, <output>, <fromTool>, <gotchas>, <examples>) that make information easy to locate. Every sentence serves a specific purpose - there's no redundant or filler content. The formatting helps the agent quickly scan for relevant information.

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

Completeness5/5

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

Given the tool's complexity (nested queries object with 10 parameters) and absence of output schema, the description provides excellent completeness. It thoroughly documents the output format, performance considerations, usage patterns, and integration with sibling tools. The examples section gives concrete invocation patterns that compensate for the lack of output schema.

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

Parameters4/5

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

With 100% schema description coverage, the baseline is 3. The description adds meaningful context about parameters through workflow examples (root with depth=1 first, then drill down) and practical advice about depth limitations. However, it doesn't explain all 10 parameters in the nested queries object, leaving some semantic gaps despite the high schema coverage.

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 the tool's purpose with specific verbs ('Display directory structure', 'Understand repo structure', 'Discover file paths') and distinguishes it from siblings by focusing on structural exploration rather than content reading or searching. The title 'GitHub Repository Structure Explorer' reinforces this distinction.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool (understanding layout, discovering paths) versus alternatives (githubSearchCode for searching, githubGetFileContent for reading). The <fromTool> section explicitly names sibling tools and their relationships, and the <gotchas> section offers clear when-not-to-use advice (avoid unknown paths, depth=2 on large dirs).

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/bgauryy/octocode-mcp'

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