Skip to main content
Glama

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
NameRequiredDescriptionDefault
cwdNoCurrent working directory of the codebase (defaults to current dir)
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
showLineNumbersNoShow line numbers

Implementation Reference

  • 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)}`, }, ], }; } }
  • 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(), },
  • 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)}`, }, ], }; } } );

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