Skip to content

add MCP-server attach_packed_output tool for importing existing repom…#756

Merged
yamadashy merged 5 commits intoyamadashy:mainfrom
petrarca:mcp-attach-packed-output
Aug 11, 2025
Merged

add MCP-server attach_packed_output tool for importing existing repom…#756
yamadashy merged 5 commits intoyamadashy:mainfrom
petrarca:mcp-attach-packed-output

Conversation

@petrarca
Copy link
Contributor

@petrarca petrarca commented Aug 1, 2025

Feature: MCP Attach Packed Output Tool

This PR adds a new MCP tool capability that allows attaching existing Repomix packed output files. The tool accepts either a directory containing a repomix-output.xml file or a direct path to an XML file, registers it with the MCP server, and returns the same structure as the pack_codebase tool.

Key changes:

  • Added new attachPackedOutputTool.ts implementation
  • Added comprehensive unit tests in attachPackedOutputTool.test.ts
  • Updated MCP server registration to include the new tool
  • Added validation for packed output files to ensure they're valid Repomix outputs Integrated with existing MCP tool runtime for consistent response formatting
  • Added support for both directory and direct file path inputs
  • Resolve metrics from existing packed files, to get identical output as when repo was packaged

This enhancement allows users to work with previously generated Repomix outputs without needing to repack the codebase.

Checklist

  • [x ] Run npm run test
  • Run npm run lint (issues in src/core, existing, not related to changes, those are passed linter)

@petrarca petrarca requested a review from yamadashy as a code owner August 1, 2025 07:27
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new tool named attach_packed_output is added to the MCP server, enabling it to process packed repository output XML files. The server is updated to register and describe this tool. Implementation includes input validation, XML parsing, metrics extraction, and error handling. Comprehensive tests are introduced to verify tool registration, operation, and error scenarios.

Changes

Cohort / File(s) Change Summary
MCP Server Integration
src/mcp/mcpServer.ts
Imports and registers the new attach_packed_output tool with the MCP server. Updates the server instructions to reference the new tool. No other server logic is changed.
Attach Packed Output Tool Implementation
src/mcp/tools/attachPackedOutputTool.ts
Introduces the attach_packed_output tool. Handles input path validation (directory or XML), reads and parses XML, extracts file paths, computes metrics, and generates a response consistent with the pack_codebase tool. Implements error handling and schema validation. Exports the registration function for server integration.
Attach Packed Output Tool Tests
tests/mcp/tools/attachPackedOutputTool.test.ts
Adds a new test suite for the tool. Mocks filesystem and utility functions. Tests registration, input handling (file and directory), options, error cases (invalid input, missing file, read failure), and correct extraction of file paths and metrics. Verifies integration with the MCP tool runtime's formatting and error response functions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MCPServer
    participant AttachPackedOutputTool
    participant FileSystem

    Client->>MCPServer: Request attach_packed_output with inputPath
    MCPServer->>AttachPackedOutputTool: Invoke handler with inputPath
    AttachPackedOutputTool->>FileSystem: Validate and resolve inputPath
    AttachPackedOutputTool->>FileSystem: Read XML file
    FileSystem-->>AttachPackedOutputTool: Return XML content
    AttachPackedOutputTool->>AttachPackedOutputTool: Parse XML, extract file paths, compute metrics
    AttachPackedOutputTool-->>MCPServer: Return formatted response or error
    MCPServer-->>Client: Respond with result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @petrarca, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've introduced a significant enhancement to the MCP server by adding a new attach_packed_output tool. This tool streamlines the workflow for AI analysis by allowing users to import and work with existing Repomix packed output files directly. My goal is to provide a more efficient way to leverage previously generated codebase representations without the overhead of re-packaging, thereby improving productivity and reducing processing time for AI-driven code analysis tasks.

Highlights

  • New MCP Tool: attach_packed_output: I've added a new attach_packed_output tool to the Model Context Protocol (MCP) server. This tool enables users to import and utilize previously generated Repomix packed output files for AI analysis, eliminating the need to repack the codebase.
  • Flexible Input Handling: The new tool is flexible, accepting either a direct path to a repomix-output.xml file or a directory containing one. It automatically resolves the correct file path and validates the input to ensure it's a valid XML file.
  • Metric Resolution and Consistent Output: Upon successful attachment, the tool processes the XML content to extract file paths and calculate approximate metrics such as total files, characters, and tokens. The output format is consistent with the pack_codebase tool, ensuring seamless integration with existing workflows.
  • Comprehensive Unit Testing: I've included a comprehensive suite of unit tests for the attach_packed_output tool, covering various scenarios including successful operations, edge cases, and error handling, ensuring its robustness and reliability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new MCP tool, attach_packed_output, for working with existing Repomix packed outputs. The implementation is a good start, but there are several critical issues with how metrics are calculated, leading to inaccurate and misleading information. The current approach for calculating file sizes and total characters is flawed. Additionally, the unit tests are not comprehensive enough to catch these issues as they mock out key functionality without asserting the results. I've provided detailed feedback and code suggestions to improve the accuracy of the metrics, enhance error handling, and strengthen the test suite.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/mcp/tools/attachPackedOutputTool.ts (1)

115-120: Inefficient string padding for large files.

Creating strings with .padEnd() for large files could consume excessive memory and serve no functional purpose since the content is just padding.

Replace with a more memory-efficient approach:

-function createProcessedFiles(filePaths: string[], charCounts: Record<string, number>): ProcessedFile[] {
-  return filePaths.map((path) => ({
-    path,
-    content: ''.padEnd(charCounts[path]), // Create a string of the appropriate length
-  }));
-}
+function createProcessedFiles(filePaths: string[], charCounts: Record<string, number>): ProcessedFile[] {
+  return filePaths.map((path) => ({
+    path,
+    content: `[Content placeholder - ${charCounts[path]} characters]`,
+  }));
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0de1f02 and 11a0973.

📒 Files selected for processing (3)
  • src/mcp/mcpServer.ts (3 hunks)
  • src/mcp/tools/attachPackedOutputTool.ts (1 hunks)
  • tests/mcp/tools/attachPackedOutputTool.test.ts (1 hunks)
🔇 Additional comments (6)
src/mcp/tools/attachPackedOutputTool.ts (1)

149-150: Update function call to handle async XML parsing.

If the extractFilePaths function is updated to use proper XML parsing (as suggested above), this call needs to be updated.

Ensure this line is updated if extractFilePaths becomes async:

-        const filePaths = extractFilePaths(content);
+        const filePaths = await extractFilePaths(content);
src/mcp/mcpServer.ts (3)

6-6: LGTM: Clean import integration.

The import statement follows the existing pattern and is properly placed alphabetically.


20-20: LGTM: Appropriate instructions update.

The instructions string correctly describes the new tool's purpose and fits well with the existing tool descriptions.


42-42: LGTM: Proper tool registration.

The tool registration follows the established pattern and is placed appropriately in the sequence.

tests/mcp/tools/attachPackedOutputTool.test.ts (2)

10-19: LGTM: Proper mocking strategy.

The mocking approach correctly isolates the unit under test while preserving the actual implementation details that need to be tested.


185-197: LGTM: Thorough validation of file path extraction.

The test properly validates that the XML parsing extracts the expected file paths, which is critical for the tool's functionality.

@petrarca
Copy link
Contributor Author

petrarca commented Aug 5, 2025

Anything left over from my side? Issues were fixed. Any feedback?

@yamadashy
Copy link
Owner

@petrarca
Thank you for the PR!
I was reviewing it partway through, but I ran out of time to continue the review. I'll take another look at it later!

@petrarca
Copy link
Contributor Author

petrarca commented Aug 6, 2025

Thank you @yamadashy . This should be non-destructive and fully compatible. We already use this internally in a larger R&D development setup, and it works seamless (as does repomix itself—thanks for the great work!).
This particularly solves the current issue where a repomix MCP server does not remove the packed repositories that get created somewhere in temp space. Beyond the disk space usage, people don't like having code lying around in hidden locations.
With Windsurf, which we use, we even disable the pack_repo tool in the repomix MCP server so that the repomix.xml is created externally and use only the attach_repo tool from this MR.

petrarca and others added 5 commits August 11, 2025 21:54
…rmation

Add comprehensive documentation for the new attach_packed_output MCP tool in llms-install.md to maintain consistency with README.md updates. This includes detailed parameter descriptions, usage examples, and proper section numbering.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Aug 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.59%. Comparing base (f5104d1) to head (e2e8b01).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #756      +/-   ##
==========================================
+ Coverage   88.39%   88.59%   +0.20%     
==========================================
  Files         109      110       +1     
  Lines        6083     6192     +109     
  Branches     1258     1282      +24     
==========================================
+ Hits         5377     5486     +109     
  Misses        706      706              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yamadashy
Copy link
Owner

@petrarca
Sorry for the delay! The code and functionality look good, so I'll go ahead and merge this.
Thank you for your work on this!

I'm planning to release this soon.

@yamadashy yamadashy merged commit 1771372 into yamadashy:main Aug 11, 2025
54 checks passed
@yamadashy
Copy link
Owner

This feature has been released in v1.3.0!
https://github.com/yamadashy/repomix/releases/tag/v1.3.0

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants