Skip to main content
Glama

githubGetFileContent

Read-onlyIdempotent

Retrieve specific content from GitHub files using line ranges, pattern matching, or full file reading to analyze code details and implementations.

Instructions

Read file content

Input Schema

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

Implementation Reference

  • Core handler function that executes the logic for fetching GitHub file contents, handling bulk queries, API calls, error handling, and result formatting.
    async function fetchMultipleGitHubFileContents(
      queries: FileContentQuery[],
      authInfo?: AuthInfo,
      sessionId?: string
    ): Promise<CallToolResult> {
      return executeBulkOperation(
        queries,
        async (query: FileContentQuery, _index: number) => {
          try {
            const apiRequest = buildApiRequest(query);
            const apiResult = await fetchGitHubFileContentAPI(
              apiRequest,
              authInfo,
              sessionId
            );
    
            const apiError = handleApiError(apiResult, query);
            if (apiError) return apiError;
    
            const result = 'data' in apiResult ? apiResult.data : apiResult;
    
            const hasContent = hasValidContent(result);
            const resultObj = result as Record<string, unknown>;
    
            // Extract pagination hints from the result (generated by fileOperations)
            const paginationHints = Array.isArray(resultObj.hints)
              ? (resultObj.hints as string[])
              : [];
    
            // Determine if file is large for context-aware hints
            const isLarge =
              typeof resultObj.contentLength === 'number' &&
              resultObj.contentLength > 50000;
    
            // Use unified pattern: context for dynamic hints, extraHints for pagination
            return createSuccessResult(
              query,
              resultObj,
              hasContent,
              TOOL_NAMES.GITHUB_FETCH_CONTENT,
              {
                hintContext: { isLarge },
                extraHints: paginationHints,
              }
            );
          } catch (error) {
            return handleCatchError(error, query);
          }
        },
        {
          toolName: TOOL_NAMES.GITHUB_FETCH_CONTENT,
          keysPriority: [
            'owner',
            'repo',
            'path',
            'branch',
            'contentLength',
            'content',
            'pagination',
            'isPartial',
            'startLine',
            'endLine',
            'lastModified',
            'lastModifiedBy',
            'matchLocations',
            'error',
          ],
        }
      );
    }
  • Input/output schema (FileContentBulkQuerySchema) used for validating tool parameters.
    export const FileContentBulkQuerySchema = createBulkQuerySchema(
      TOOL_NAMES.GITHUB_FETCH_CONTENT,
      FileContentQuerySchema
    );
  • Tool registration function that calls server.registerTool with name 'githubGetFileContent', schema, description, and handler.
    export function registerFetchGitHubFileContentTool(
      server: McpServer,
      callback?: ToolInvocationCallback
    ) {
      return server.registerTool(
        TOOL_NAMES.GITHUB_FETCH_CONTENT,
        {
          description: DESCRIPTIONS[TOOL_NAMES.GITHUB_FETCH_CONTENT],
          inputSchema: FileContentBulkQuerySchema,
          annotations: {
            title: 'GitHub File Content Fetch',
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: true,
          },
        },
        withSecurityValidation(
          TOOL_NAMES.GITHUB_FETCH_CONTENT,
          async (
            args: {
              queries: FileContentQuery[];
            },
            authInfo,
            sessionId
          ): Promise<CallToolResult> => {
            const queries = args.queries || [];
    
            await invokeCallbackSafely(
              callback,
              TOOL_NAMES.GITHUB_FETCH_CONTENT,
              queries
            );
    
            return fetchMultipleGitHubFileContents(queries, authInfo, sessionId);
          }
        )
      );
    }
  • Tool configuration entry that associates the tool name 'githubGetFileContent' with its registration function.
    export const GITHUB_FETCH_CONTENT: ToolConfig = {
      name: TOOL_NAMES.GITHUB_FETCH_CONTENT,
      description: getDescription(TOOL_NAMES.GITHUB_FETCH_CONTENT),
      isDefault: true,
      isLocal: false,
      type: 'content',
      fn: registerFetchGitHubFileContentTool,
    };
  • Static definition of the tool name constant GITHUB_FETCH_CONTENT = 'githubGetFileContent'.
    export const STATIC_TOOL_NAMES = {
      GITHUB_FETCH_CONTENT: 'githubGetFileContent',
Behavior5/5

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

The description adds substantial behavioral context beyond annotations. While annotations indicate read-only, open-world, idempotent, and non-destructive traits, the description provides practical constraints: file size limit (300KB max with FILE_TOO_LARGE error), token efficiency guidance, branch usage rules (use branch name not SHA), and strategy choices between parameters. This significantly enhances operational understanding.

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 well-structured with clear sections (<when>, <fromTool>, <gotchas>, <examples>) that make information easy to locate. While somewhat lengthy, every section adds value. The front-loaded purpose statement ('Read file content') immediately communicates the core function, and subsequent sections efficiently address different aspects of usage.

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 (multiple parameter strategies, file size limits, sibling relationships) and lack of output schema, the description provides comprehensive context. It covers when to use the tool, alternatives, behavioral constraints, parameter strategies, and examples. This compensates well for the missing output schema and provides complete operational guidance.

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, but the description adds meaningful semantic context. The <gotchas> section explains parameter relationships ('Choose one strategy: startLine+endLine OR matchString OR fullContent') and the <examples> section illustrates practical usage patterns. This provides valuable guidance beyond the schema's structural definitions.

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 as 'Read file content' with specific verb+resource. It distinguishes from siblings by focusing on reading from known file paths, unlike search tools that find files or repositories. The title 'GitHub File Content Fetch' from annotations reinforces this specific scope.

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?

Explicit guidance is provided in the <when> section ('Use when you need details from a known file path') and the <fromTool> section lists specific alternatives for different contexts (e.g., use githubSearchCode for searching, githubViewRepoStructure for file discovery). Clear exclusions are implied by stating when to use this tool versus others.

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