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
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output format (xml, markdown, or plain) | xml |
| ignorePatterns | No | Ignore patterns (using glob patterns, comma-separated) | |
| includeDirectoryStructure | No | Include directory structure | |
| includeFileSummary | No | Include summary of each file | |
| includePatterns | No | Include patterns (using glob patterns, comma-separated) | |
| removeComments | No | Remove comments from the code | |
| removeEmptyLines | No | Remove empty lines from the code | |
| repo | Yes | GitHub repository URL or shorthand format (e.g., 'username/repo') | |
| showLineNumbers | No | Show line numbers |
Implementation Reference
- src/tools/codebase.ts:125-197 (handler)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)}`, }, ], }; }
- src/tools/codebase.ts:114-124 (schema)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(), },
- src/tools/codebase.ts:111-199 (registration)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)}`, }, ], }; } } );