Skip to main content
Glama

getRemoteCodebase

Retrieve a remote GitHub repository's codebase as a single text output in XML, markdown, or plain format, with options to include file summaries, directory structures, line numbers, and filter content using patterns.

Instructions

Retrieve a remote repository's codebase as a single text output using RepoMix

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format (xml, markdown, or plain)xml
ignorePatternsNoIgnore patterns (using glob patterns, comma-separated)
includeDirectoryStructureNoInclude directory structure
includeFileSummaryNoInclude summary of each file
includePatternsNoInclude patterns (using glob patterns, comma-separated)
removeCommentsNoRemove comments from the code
removeEmptyLinesNoRemove empty lines from the code
repoYesGitHub repository URL or shorthand format (e.g., 'username/repo')
showLineNumbersNoShow line numbers

Implementation Reference

  • Handler function that constructs and executes a 'repomix --remote' command to retrieve the remote codebase as text output, handling various formatting options and error cases.
    async ({ repo, format, includeFileSummary, includeDirectoryStructure, removeComments, removeEmptyLines, showLineNumbers, includePatterns, ignorePatterns }) => {
      try {
        let command = `npx repomix --remote ${repo} --output stdout`;
        
        // Add formatting options
        if (format) {
          command += ` --style ${format}`;
        }
        
        if (includeFileSummary === true) {
          command += ` --include-file-summary`;
        } else if (includeFileSummary === false) {
          command += ` --no-include-file-summary`;
        }
        
        if (includeDirectoryStructure === true) {
          command += ` --include-directory-structure`;
        } else if (includeDirectoryStructure === false) {
          command += ` --no-include-directory-structure`;
        }
        
        if (removeComments === true) {
          command += ` --remove-comments`;
        } else if (removeComments === false) {
          command += ` --no-remove-comments`;
        }
        
        if (removeEmptyLines === true) {
          command += ` --remove-empty-lines`;
        } else if (removeEmptyLines === false) {
          command += ` --no-remove-empty-lines`;
        }
        
        if (showLineNumbers === true) {
          command += ` --show-line-numbers`;
        } else if (showLineNumbers === false) {
          command += ` --no-show-line-numbers`;
        }
        
        if (includePatterns) {
          command += ` --include "${includePatterns}"`;
        }
        
        if (ignorePatterns) {
          command += ` --ignore "${ignorePatterns}"`;
        }
    
        console.error(`Running command: ${command}`);
        
        // Run Repomix to dump the codebase
        const output = execSync(command, {
          maxBuffer: 1024 * 1024 * 50, // 50MB buffer for large codebases
        }).toString();
    
        return {
          content: [
            {
              type: "text",
              text: output,
            },
          ],
        };
      } catch (error: unknown) {
        console.error("Error running Repomix on remote repository:", error);
        return {
          content: [
            {
              type: "text",
              text: `Error retrieving remote codebase: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
  • Zod schema defining the input parameters for the getRemoteCodebase tool, including repo URL and various repomix options.
    {
      repo: z.string().describe("GitHub repository URL or shorthand format (e.g., 'username/repo')"),
      format: z.enum(["xml", "markdown", "plain"]).describe("Output format (xml, markdown, or plain)").default("xml").optional(),
      includeFileSummary: z.boolean().describe("Include summary of each file").default(true).optional(),
      includeDirectoryStructure: z.boolean().describe("Include directory structure").default(true).optional(),
      removeComments: z.boolean().describe("Remove comments from the code").default(false).optional(),
      removeEmptyLines: z.boolean().describe("Remove empty lines from the code").default(false).optional(),
      showLineNumbers: z.boolean().describe("Show line numbers").default(true).optional(),
      includePatterns: z.string().describe("Include patterns (using glob patterns, comma-separated)").optional(),
      ignorePatterns: z.string().describe("Ignore patterns (using glob patterns, comma-separated)").optional(),
    },
  • Registration of the getRemoteCodebase tool using McpServer.tool(), including name, description, schema, and handler function.
    server.tool(
      "getRemoteCodebase",
      "Retrieve a remote repository's codebase as a single text output using RepoMix",
      {
        repo: z.string().describe("GitHub repository URL or shorthand format (e.g., 'username/repo')"),
        format: z.enum(["xml", "markdown", "plain"]).describe("Output format (xml, markdown, or plain)").default("xml").optional(),
        includeFileSummary: z.boolean().describe("Include summary of each file").default(true).optional(),
        includeDirectoryStructure: z.boolean().describe("Include directory structure").default(true).optional(),
        removeComments: z.boolean().describe("Remove comments from the code").default(false).optional(),
        removeEmptyLines: z.boolean().describe("Remove empty lines from the code").default(false).optional(),
        showLineNumbers: z.boolean().describe("Show line numbers").default(true).optional(),
        includePatterns: z.string().describe("Include patterns (using glob patterns, comma-separated)").optional(),
        ignorePatterns: z.string().describe("Ignore patterns (using glob patterns, comma-separated)").optional(),
      },
      async ({ repo, format, includeFileSummary, includeDirectoryStructure, removeComments, removeEmptyLines, showLineNumbers, includePatterns, ignorePatterns }) => {
        try {
          let command = `npx repomix --remote ${repo} --output stdout`;
          
          // Add formatting options
          if (format) {
            command += ` --style ${format}`;
          }
          
          if (includeFileSummary === true) {
            command += ` --include-file-summary`;
          } else if (includeFileSummary === false) {
            command += ` --no-include-file-summary`;
          }
          
          if (includeDirectoryStructure === true) {
            command += ` --include-directory-structure`;
          } else if (includeDirectoryStructure === false) {
            command += ` --no-include-directory-structure`;
          }
          
          if (removeComments === true) {
            command += ` --remove-comments`;
          } else if (removeComments === false) {
            command += ` --no-remove-comments`;
          }
          
          if (removeEmptyLines === true) {
            command += ` --remove-empty-lines`;
          } else if (removeEmptyLines === false) {
            command += ` --no-remove-empty-lines`;
          }
          
          if (showLineNumbers === true) {
            command += ` --show-line-numbers`;
          } else if (showLineNumbers === false) {
            command += ` --no-show-line-numbers`;
          }
          
          if (includePatterns) {
            command += ` --include "${includePatterns}"`;
          }
          
          if (ignorePatterns) {
            command += ` --ignore "${ignorePatterns}"`;
          }
    
          console.error(`Running command: ${command}`);
          
          // Run Repomix to dump the codebase
          const output = execSync(command, {
            maxBuffer: 1024 * 1024 * 50, // 50MB buffer for large codebases
          }).toString();
    
          return {
            content: [
              {
                type: "text",
                text: output,
              },
            ],
          };
        } catch (error: unknown) {
          console.error("Error running Repomix on remote repository:", error);
          return {
            content: [
              {
                type: "text",
                text: `Error retrieving remote codebase: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
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/DeDeveloper23/codebase-mcp'

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