fix(git): auto-detect repo root from --repository#3997
Open
FazeelUsmani wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(git): auto-detect repo root from --repository#3997FazeelUsmani wants to merge 1 commit intomodelcontextprotocol:mainfrom
FazeelUsmani wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Walk parent directories when --repository points inside a working tree, the same way `git rev-parse --show-toplevel` does. Makes `--repository .` work from any subdirectory of the repo so a checked-in config works for every developer regardless of where they launch from. If the resolved path differs from the input, the rewrite is logged at startup. Per-tool repo_path arguments are unchanged. Closes modelcontextprotocol#3029
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets mcp-server-git --repository accept any path inside a Git working tree instead of only the repo root. At startup the server walks up parents to find .git/, like git rev-parse--show-toplevel.
Fixes the case in #3029 where --repository . only works when the client is launched from the repo root. Now it works from any subdirectory, so a checked-in mcp.json works for everyone without per-developer absolute paths.
Closes #3029.
Real git walks up the tree from any subdir. The server should too, otherwise --repository. It is basically unusable in a shared config.
On the thread, @jonathanhefner and @domdomegg both said not to special-case, so this applies to any path passed to --repository.
How Has This Been Tested?
Breaking Changes
No impact for configs that already point at the repo root.
One behavior change: --repository /repo/non_repo_subdir used to fail with "not a valid Git repository". Now it resolves upward to /repo and starts. If the resolved path differs from the input, it logs it at INFO so it's visible. The README documents this and notes that the flag alone doesn't enforce subtree scoping.
The error message also changed from "is not a valid Git repository" to "is not inside a Git repository".
Types of changes
Checklist
Additional context
Kept the fix scoped to the --repository CLI flag. Applying the same parent-walking to per-tool repo_path would break git_add semantics: repo.git.add(".") runs at the repo root, so passing repo_path=/repo/subdir with files=["."] would stage the whole repo instead of just the subdir. Leaving repo_path strict avoids that. The README says so explicitly.