Skip to main content
Glama
kazuph

@kazuph/mcp-github-pera1

by kazuph

github_get_code

Fetches code from a GitHub repository URL and combines it into a single file. Filter by directory, extension, branch, or specific file to retrieve only the needed code.

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
urlYes
dirNo
extNo
modeNo
branchNo
fileNo

Implementation Reference

  • The main handler for the 'github_get_code' tool. It parses arguments using GithubUrlSchema, calls fetch on the URL built by buildWorkerUrl, and returns the response text as the tool output.
    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,
        };
      }
    }
  • The Zod schema (GithubUrlSchema) used for validating inputs to the github_get_code tool. Defines fields: url (required), dir, ext, mode, branch, file (all optional).
    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(),
    });
  • Helper function that builds a worker URL by appending query parameters (dir, ext, mode, branch, file) to the base worker URL.
    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();
    };
  • src/index.ts:33-77 (registration)
    Registration of the 'github_get_code' tool via ListToolsRequestSchema handler. Defines the tool's name, description, and inputSchema (converted from GithubUrlSchema via zodToJsonSchema).
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      const tools = [
        {
          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,
        },
      ];
    
      return { tools };
    });
Behavior4/5

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

The description discloses that the tool retrieves and combines code, parses repository structure, and auto-extracts branch from tree URLs. Given no annotations, it covers key behaviors but does not mention rate limits or error handling.

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 sections for parameters and examples, and the first sentence clearly states the purpose. It is somewhat lengthy but all content is informative.

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 no annotations or output schema, the description covers all behaviors: parameter usage, URL parsing, combining files, and example scenarios. It is complete for a read-only code retrieval tool.

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?

Despite 0% schema description coverage, the description thoroughly explains each parameter with formats (e.g., comma-separated for dir/ext) and examples. This fully compensates for the schema's lack of descriptions.

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 verb ('retrieves code') and resource ('GitHub repository URL'), and specifies that it combines content into a single file. There are no sibling tools, so no differentiation needed.

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 detailed query parameters and multiple examples covering different use cases (tree URLs, directories, single file, tree mode). However, it does not explicitly state when to use this tool versus alternatives, though no siblings exist.

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

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