8000 Multi-Repository Support for Git MCP Server by tomholford · Pull Request #3 · geropl/git-mcp-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Multi-Repository Support for Git MCP Server #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 19, 2025

Conversation

tomholford
Copy link
Contributor

This PR adds multi-repository support, allowing the Git MCP Server to monitor and operate on multiple repositories simultaneously. Users can now specify multiple repositories in several flexible ways, and a new tool has been added to list all available repositories.

Resolves #2

Key Features

  1. Multiple Repository Specification:

    • Via comma-separated paths: -r=/path/to/repo1,/path/to/repo2
    • Via multiple flag instances: -r=/path/to/repo1 -r=/path/to/repo2
    • Via positional arguments: serve /path/to/repo1 /path/to/repo2
  2. Intelligent Repository Selection:

    • When a specific repository is requested for an operation, it's used
    • When no repository is specified, the first repository is used as default
    • Each command output indicates which repository was used
  3. New Tool: git_list_repositories:

    • Lists all available repositories the server is monitoring
    • Shows repository path and name
    • Helps users keep track of configured repositories
  4. Backward Compatibility:

    • All existing commands and workflows continue to work
    • Single repository mode still supported (just specify one repository)

Implementation Details

  1. Changed GitServer to store an array of repository paths instead of a single path
  2. Added repository validation logic to check if paths are valid git repositories
  3. Changed -r/--repository from StringVar to StringSliceVar to support multiple values
  4. Modified all handler functions to use repository selection logic
  5. Updated documentation to explain the new features and usage patterns
  6. Added specific tests for multi-repository functionality

Testing

Automated tests have been added to verify:

  • The new git_list_repositories tool functions correctly
  • Repository selection logic works as expected
  • Operations across multiple repositories are handled properly
  • Invalid repository paths are properly rejected

Test with Claude Desktop

I also tested with Claude Desktop 0.8.1 / Sonnet 3.7 with this config in claude_desktop_config.json:

    "git": {
      "command": "~/dev/forks/git-mcp-go/git-mcp-go",
      "args": ["serve", "~/dev/forks/git-mcp-go", "~/dev/forks/wireguard-go"]
    },

And here is the conversation:

please use the git mcp tool available to you to see which repos you have access to

---

I'll help you explore the Git repositories that are available through the tools. Let's list the repositories first.

I have access to two Git repositories:

1. `git-mcp-go` at the path `~/dev/forks/git-mcp-go`
2. `wireguard-go` at the path `~/dev/forks/wireguard-go`

Would you like me to examine either of these repositories in more detail? I can check their status, commit history, or look at specific files within them.

---

Please show me a summary of the last commit for each repo.

---

I'll show you the summary of the last commit for each repository. Let's check them one by one.

First, let's look at the last commit for the git-mcp-go repository:

Now, let's check the last commit for the wireguard-go repository:

Here's a summary of the last commit for each repository:

1. **git-mcp-go**:
   - Commit: 553d6fc9ce2640699ac57ffe84b1709fb1b6aef6
   - Author: tomholford
   - Date: Sun Mar 16, 2025 (today)
   - Message: "Simplify repository flag handling"

2. **wireguard-go**:
   - Commit: 49e120adda6ee503dd14cf2799e34f73809a8c05
   - Author: tomholford
   - Date: Mon Jul 22, 2024
   - Message: "global: linter and deprecated"

The git-mcp-go repository has a very recent commit from today, while the wireguard-go repository's last commit is from July 2024.

Usage Examples

# Run with multiple repositories using comma-separated values
./git-mcp-go serve -r=/path/to/repo1,/path/to/repo2,/path/to/repo3

# Run with multiple repository flags
./git-mcp-go serve -r=/path/to/repo1 -r=/path/to/repo2

# Run with repositories as arguments
./git-mcp-go serve /path/to/repo1 /path/to/repo2 /path/to/repo3

# List all available repositories
# (Output will show all monitored repositories)

This feature significantly improves the user experience when working with multiple repositories, making the Git MCP Server more versatile and efficient.

Copy link
Owner
@geropl geropl left a comment

Choose a reason for hiding this comment

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

My LLM says your LLM did a pretty good job, and tests look good and are green, so let's merge! 😉

README.md Outdated
./git-mcp-go serve -r /path/to/git/repository

# Run with multiple repositories using comma-separated values
Copy link
Owner

Choose a reason for hiding this comment

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

@tomholford Would be great to tone down the duplication here a bit

README.md Outdated
./git-mcp-go setup -r /path/to/git/repository

# Set up with multiple repositories using comma-separated values
Copy link
Owner

Choose a reason for hiding this comment

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

here as well

README.md Outdated
}
}
```

For backward compatibility, the following still works for a single repository:
Copy link
Owner

Choose a reason for hiding this comment

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

Can me dropped I think

@geropl
Copy link
Owner
geropl commented Mar 18, 2025

@tomholford Please take a quick look at the comments and rebase, happy to merge after.

This commit refactors the Git MCP server to support monitoring multiple
Git repositories simultaneously. Key changes include:

- Changed GitServer.repoPath from string to repoPaths []string
- Added repository validation and path resolution logic
- Updated cmd/server.go to accept multiple repos via args and --repositories flag
- Updated cmd/setup.go to configure multiple repositories in Cline
- Added git_list_repositories tool to show available repositories
- Modified all handler functions to use new repository resolution logic
- Updated tests to work with multiple repositories

The server maintains backward compatibility with the single-repository
approach via the -r/--repository flag.
This commit updates the README.md with comprehensive documentation
for the multi-repository feature:

- Add git_list_repositories to the list of tools
- Update command line structure with new flags and arguments
- Add a Multi-Repository Support section explaining options
- Update serve and setup command examples with multiple repos
- Add Repository Management section explaining tool and selection
- Update the configuration examples for multiple repositories

This documentation covers all the ways users can work with multiple
repositories and explains the repository selection logic.
This commit adds comprehensive 
8000
tests for the multi-repository feature:

- TestGitListRepositories: Verifies the git_list_repositories tool
  works correctly by checking the output contains all repositories

- TestRepositorySelection: Tests the repository selection logic for
  default selection, specific selection, and invalid paths

- TestOperationsAcrossMultipleRepositories: Ensures operations work
  correctly when targeting different repositories and properly error
  when given invalid repositories

These tests help ensure that the multi-repository feature works
correctly in all scenarios and maintains the expected behavior.
This commit simplifies the repository flag handling to provide a better
user experience:

- Changed -r/--repository from StringVar to StringSliceVar to support
  both comma-separated values and multiple flag instances
- Removed separate --repositories flag in favor of the more versatile
  --repository flag
- Updated the documentation to reflect the new usage patterns
- Fixed the setup command to configure Cline with the new flag format
- Made error messages and help text clearer

These changes make it easier to specify multiple repositories while
maintaining backward compatibility with existing usage patterns.
- Update verifyFileExpectations to use partial path matching for configuration files
- Look for files containing the important path suffix after "globalStorage/"
- Maintain OS independence by using the same verification logic across platforms
- Improve test logging to better understand what files are found
- Add validation for empty repository paths with clear error message
- Update setupTool to handle single repository case differently for test compatibility
- Use --repository format for single repository case to match test expectations
- Use -r format for multiple repositories case for consistency with other commands
@tomholford
Copy link
Contributor Author

@tomholford Please take a quick look at the comments and rebase, happy to merge after.

Thanks for the review. Rebased and addressed feedback 👍

@geropl geropl merged commit 84e998f into geropl:main Mar 19, 2025
2 checks passed
@geropl
Copy link
Owner
geropl commented Mar 19, 2025

@tomholford Thanks for you contribution!

@tomholford tomholford deleted the th/multiple-repos branch March 19, 2025 19:44
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.

Multiple repositories
2 participants
0