add MCP-server attach_packed_output tool for importing existing repom…#756
add MCP-server attach_packed_output tool for importing existing repom…#756yamadashy merged 5 commits intoyamadashy:mainfrom petrarca:mcp-attach-packed-output
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit 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 skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughA new tool named Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes ✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
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 newattach_packed_outputtool 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.xmlfile 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_codebasetool, ensuring seamless integration with existing workflows. - Comprehensive Unit Testing: I've included a comprehensive suite of unit tests for the
attach_packed_outputtool, 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
-
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. ↩
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
📒 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
extractFilePathsfunction is updated to use proper XML parsing (as suggested above), this call needs to be updated.Ensure this line is updated if
extractFilePathsbecomes 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.
|
Anything left over from my side? Issues were fixed. Any feedback? |
|
@petrarca |
|
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!). |
…ix XML files, including tests
… cases in attachPackedOutputTool
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
@petrarca I'm planning to release this soon. |
|
This feature has been released in v1.3.0! Thank you for your contribution! |
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:
This enhancement allows users to work with previously generated Repomix outputs without needing to repack the codebase.
Checklist
npm run testnpm run lint(issues in src/core, existing, not related to changes, those are passed linter)