githubGetFileContent
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
| Name | Required | Description | Default |
|---|---|---|---|
| queries | Yes | Research 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); } ) ); }
- packages/octocode-mcp/src/tools/toolConfig.ts:45-52 (registration)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, };
- packages/octocode-mcp/src/tools/toolNames.ts:10-11 (registration)Static definition of the tool name constant GITHUB_FETCH_CONTENT = 'githubGetFileContent'.export const STATIC_TOOL_NAMES = { GITHUB_FETCH_CONTENT: 'githubGetFileContent',