servers icon indicating copy to clipboard operation
servers copied to clipboard

mcp-server-git: Make `--repository .` auto-detect git root like standard git commands

Open fabn opened this issue 1 month ago • 1 comments

Problem

When using mcp-server-git with --repository ., the server uses the literal current working directory instead of finding the git repository root. This differs from standard git behavior and creates portability issues:

  1. Breaks when invoked from subdirectories: If the MCP client is launched from a subdirectory of the repository, --repository . points to that subdirectory instead of the repository root, causing failures.

  2. Forces absolute paths: Teams must use absolute paths in configuration, requiring each developer to maintain local overrides since everyone has different clone paths.

Current Behavior

{
  "mcpServers": {
    "git": {
      "command": "uvx",
      "args": [
        "mcp-server-git",
        "--repository",
        "."
      ]
    }
  }
}

This only works when the MCP client is launched exactly from the repository root.

Proposed Solution: Make . Auto-detect Repository Root (Preferred)

When --repository . is specified, mcp-server-git should automatically search upward from the current directory to find the git repository root, just like standard git commands do.

Implementation: Use git rev-parse --show-toplevel to find the repository root when the specified path is . or any path within a git repository.

Benefits:

  • Matches standard git behavior: Every git command (git status, git log, etc.) works from anywhere inside the repository
  • Zero configuration changes needed: Existing configurations with --repository . would just work better
  • Team-friendly: Shared configuration works for all developers regardless of:
    • Which subdirectory they're working in
    • Where they cloned the repository
    • Which OS they're using

Alternative Solutions (Less Preferred)

Option 2: Environment Variable Expansion

Allow --repository "${GIT_REPO_ROOT}" but this still requires configuration and environment setup.

Option 3: New Flag

Add --auto-detect-root flag, but this breaks existing configurations and is less intuitive than making . work naturally.

Use Case

We maintain a large IaC repository (~1000 files) with multiple subdirectories (terraform/, applications/, etc.). Team members work in specific subdirectories, and the current behavior forces us to either:

  • Always launch the MCP client from root (inconvenient)
  • Maintain per-developer absolute paths in local config files (maintenance burden)

Standard git commands work perfectly from any subdirectory—mcp-server-git should too.

Comparison with Standard Git Behavior

# These work from ANY subdirectory within a git repo:
cd /path/to/repo/terraform/environments/production
git status              # ✅ Works - finds repo root automatically
git log                 # ✅ Works - finds repo root automatically

# But mcp-server-git with --repository . does NOT:
mcp-server-git --repository .  # ❌ Uses CWD literally, doesn't find repo root

Would be happy to contribute a PR for this!

fabn avatar Nov 20 '25 13:11 fabn

For 'Forces absolute paths', could this not work with using a path upwards to the repository root if you know how deep you are? E.g. mcp-server-git --repository ../..

domdomegg avatar Nov 25 '25 21:11 domdomegg