modelcontextprotocol / modelcontextprotocol/servers

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

Open
#3,029 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
90.5k
Forks
11.7k
Avg merge
2d 2h
Merged PRs (30d)
5

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the mcp-server-git entry point and the code that handles the --repository argument, then inspect any existing tests for repository path behavior. Implement the requested root detection for paths inside a Git repository and add coverage showing that --repository . works from a subdirectory; done means the behavior matches standard Git commands without requiring absolute paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, typescript
Domain
cli, devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.