getCodebase
Retrieve and analyze entire codebases as single text output, with options to include summaries, directory structures, and custom formatting like XML or Markdown. Removes comments or empty lines, filters files by patterns, and displays line numbers.
Instructions
Retrieve the entire codebase as a single text output using RepoMix
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Current working directory of the codebase (defaults to current dir) | |
| 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 | |
| showLineNumbers | No | Show line numbers |
Implementation Reference
- src/tools/codebase.ts:30-107 (handler)The handler function that constructs a repomix CLI command based on input parameters and executes it using execSync to retrieve and return the codebase as text content.async ({ cwd, format, includeFileSummary, includeDirectoryStructure, removeComments, removeEmptyLines, showLineNumbers, includePatterns, ignorePatterns }) => { try { // Prepare options for Repomix const workingDir = cwd || process.cwd(); let command = "npx repomix --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, { cwd: workingDir, maxBuffer: 1024 * 1024 * 50, // 50MB buffer for large codebases }).toString(); return { content: [ { type: "text", text: output, }, ], }; } catch (error: unknown) { console.error("Error running Repomix:", error); return { content: [ { type: "text", text: `Error retrieving codebase: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/tools/codebase.ts:19-29 (schema)Zod schema defining the input parameters for the getCodebase tool, including options for formatting, filtering, and processing the codebase output.{ cwd: z.string().describe("Current working directory of the codebase (defaults to current dir)").optional(), 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:16-108 (registration)Registration of the 'getCodebase' tool on the MCP server using server.tool(), including name, description, input schema, and handler function.server.tool( "getCodebase", "Retrieve the entire codebase as a single text output using RepoMix", { cwd: z.string().describe("Current working directory of the codebase (defaults to current dir)").optional(), 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 ({ cwd, format, includeFileSummary, includeDirectoryStructure, removeComments, removeEmptyLines, showLineNumbers, includePatterns, ignorePatterns }) => { try { // Prepare options for Repomix const workingDir = cwd || process.cwd(); let command = "npx repomix --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, { cwd: workingDir, maxBuffer: 1024 * 1024 * 50, // 50MB buffer for large codebases }).toString(); return { content: [ { type: "text", text: output, }, ], }; } catch (error: unknown) { console.error("Error running Repomix:", error); return { content: [ { type: "text", text: `Error retrieving codebase: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );