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)}`,
              },
            ],
          };
        }
      }
    );
Behavior2/5

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

With no annotations, the description carries full burden but only states it retrieves code as text. It lacks critical behavioral details: whether this is a read-only operation, potential performance impacts for large codebases, authentication needs, or output format specifics beyond 'single text output'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, front-loaded with core purpose, zero wasted words. It efficiently conveys the essential action without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 9 parameters and no annotations or output schema, the description is inadequate. It doesn't explain the output structure, performance considerations, or error handling, leaving significant gaps for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 9 parameters. The description adds no parameter-specific information beyond implying retrieval scope ('entire codebase'), maintaining the baseline score for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Retrieve') and resource ('entire codebase'), specifying it outputs as 'single text output using RepoMix'. It distinguishes from 'saveCodebase' (write vs. read) but not explicitly from 'getRemoteCodebase' (local vs. remote retrieval).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives. It doesn't mention 'getRemoteCodebase' for remote codebases or 'saveCodebase' for saving output, leaving the agent to infer usage from tool names alone.

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

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