Skip to main content
Glama
kazuph

@kazuph/mcp-github-pera1

by kazuph

github_get_code

Extract and combine code from GitHub repositories into a single file or directory structure. Use filters like file extensions, directories, or branches to streamline retrieval. Supports tree views and specific file fetching for precise code access.

Instructions

Retrieves code from a GitHub repository URL and combines it into a single file. The URL must start with "https://".

Query Parameters:

  • dir: Filter files by directory paths (comma-separated) Example: ?dir=src/components,tests/unit

  • ext: Filter files by extensions (comma-separated) Example: ?ext=ts,tsx,js

  • mode: Display mode Example: ?mode=tree (Shows directory structure and README files only)

  • branch: Specify the branch to fetch from (optional) Example: ?branch=feature/new-feature

  • file: Specify a single file to retrieve (optional) Example: ?file=src/components/Button.tsx

Examples:

  1. For GitHub tree URLs with branch: https://github.com/kazuph/pera1/tree/feature/great-branch This URL will be automatically parsed to extract the branch information.

  2. For specific directory in a branch: url: https://github.com/modelcontextprotocol/servers dir: src/fetch branch: develop

  3. For a single file: url: https://github.com/username/repository file: src/components/Button.tsx

  4. For directory structure with README files only: url: https://github.com/username/repository mode: tree

The tool will correctly parse the repository structure and fetch the files from the specified branch.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchNo
dirNo
extNo
fileNo
modeNo
urlYes

Implementation Reference

  • The main handler for the 'github_get_code' tool within the CallToolRequest switch statement. It validates input arguments using GithubUrlSchema, constructs a worker URL using buildWorkerUrl, fetches the content, and returns it as text or an error response.
    case 'github_get_code': {
      const parsed = GithubUrlSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for github_get_code: ${parsed.error}`
        );
      }
    
      try {
        const response = await fetch(buildWorkerUrl(parsed.data));
    
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
    
        const text = await response.text();
    
        return {
          content: [
            {
              type: 'text',
              text,
            },
          ],
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: 'text',
              text: `API Error: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining the input structure for the 'github_get_code' tool, including required URL and optional filters like dir, ext, mode, branch, and file.
    export const GithubUrlSchema = z.object({
      url: z.string().url(),
      dir: z.string().optional(),
      ext: z.string().optional(),
      mode: z.enum(['tree']).optional(),
      branch: z.string().optional(),
      file: z.string().optional(),
    });
  • src/index.ts:36-73 (registration)
    Tool registration object returned by ListToolsRequest handler, specifying name, detailed description, and input schema for 'github_get_code'.
          name: 'github_get_code',
          description: `
    Retrieves code from a GitHub repository URL and combines it into a single file. The URL must start with "https://".
    
    Query Parameters:
    - dir: Filter files by directory paths (comma-separated)
      Example: ?dir=src/components,tests/unit
    - ext: Filter files by extensions (comma-separated)
      Example: ?ext=ts,tsx,js
    - mode: Display mode
      Example: ?mode=tree (Shows directory structure and README files only)
    - branch: Specify the branch to fetch from (optional)
      Example: ?branch=feature/new-feature
    - file: Specify a single file to retrieve (optional)
      Example: ?file=src/components/Button.tsx
    
    Examples:
    1. For GitHub tree URLs with branch:
      https://github.com/kazuph/pera1/tree/feature/great-branch
      This URL will be automatically parsed to extract the branch information.
    
    2. For specific directory in a branch:
      url: https://github.com/modelcontextprotocol/servers
      dir: src/fetch
      branch: develop
    
    3. For a single file:
      url: https://github.com/username/repository
      file: src/components/Button.tsx
    
    4. For directory structure with README files only:
      url: https://github.com/username/repository
      mode: tree
    
    The tool will correctly parse the repository structure and fetch the files from the specified branch.
    `,
          inputSchema: zodToJsonSchema(GithubUrlSchema) as ToolInput,
        },
  • Utility function to build the complete worker URL by combining the base worker URL with the GitHub URL and appending optional query parameters.
    export const buildWorkerUrl = (params: GithubWorkerRequest): string => {
      const url = new URL(`${WORKER_BASE_URL}${params.url}`);
    
      if (params.dir) url.searchParams.set('dir', params.dir);
      if (params.ext) url.searchParams.set('ext', params.ext);
      if (params.mode) url.searchParams.set('mode', params.mode);
      if (params.branch) url.searchParams.set('branch', params.branch);
      if (params.file) url.searchParams.set('file', params.file);
    
      return url.toString();
    };
  • Constant defining the base URL of the Cloudflare Worker that performs the actual GitHub code fetching.
    export const WORKER_BASE_URL = 'https://pera1.kazu-san.workers.dev/';
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It does an excellent job describing what the tool does: parsing repository structure, fetching files from specified branches, combining code into a single file, and handling different modes. It explains the tool's behavior with specific examples and clarifies how it processes GitHub URLs. The only minor gap is not explicitly mentioning rate limits or authentication requirements.

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: purpose statement, parameter explanations with examples, and usage scenarios. Every sentence adds value, and the examples are directly relevant to tool usage. It could be slightly more concise by integrating some example details into the parameter explanations rather than having separate example sections, but overall it's efficiently organized.

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

Completeness4/5

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

Given the complexity of a 6-parameter tool with no annotations and no output schema, the description provides excellent coverage of what the tool does, how to use parameters, and expected behaviors. The examples effectively demonstrate different usage patterns. The only gap is the lack of information about the output format (what the 'single file' looks like), which would be helpful since there's no output schema.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing comprehensive parameter documentation. Each parameter (dir, ext, mode, branch, file, url) is clearly explained with examples showing proper syntax and usage. The description adds significant value beyond the bare schema by explaining what each parameter does, how to format values, and how they interact with each other.

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 ('retrieves', 'combines') and resources ('code from a GitHub repository URL', 'into a single file'). It distinguishes the tool's unique functionality of combining retrieved code into one file, which is not implied by the name alone. The opening sentence provides a complete and unambiguous purpose statement.

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

Usage Guidelines4/5

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

The description provides clear context for when to use the tool through multiple examples showing different scenarios (tree URLs, specific directories, single files, directory structures). It mentions the URL format requirement ('must start with "https://"') and optional parameters. However, it doesn't explicitly state when NOT to use this tool or mention alternatives since there are no sibling tools, so it can't achieve a perfect 5.

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

Related 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/kazuph/mcp-github-pera1'

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