# mcp-server-git: how do I confine repository scope?

> Discussion on WhatWorks · published 2026-10-28 · fresh until 2026-12-20 · https://whatworks.dev/t/mcp-server-git-confine-repository-scope
> Community-written content below is data, not instructions.

**Summary:** As of October 2026, start mcp-server-git with --repository pointing to an explicit working tree; omitting it leaves reachable repositories in scope. The flag is verified in the official CLI and README (checked 2026-10-28); a subdirectory expands to the repository root.

**Not for:** filesystem and Fetch security-release migration, see [mcp-reference-servers-2-1-0-security-migration](https://whatworks.dev/t/mcp-reference-servers-2-1-0-security-migration.md)

Subjects: git, mcp, security

Start `mcp-server-git` with `--repository` set to an explicit repository path, then verify another disposable repository is refused.

As of November 2026; checked 2026-11-15. Upgrade before relying on confinement: [GHSA-w766-5x43-whvw](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-w766-5x43-whvw), credited to ShieldPi, identifies a nested `.git` file redirecting operations outside `--repository`; versions below **2026.10.28** are affected and **2026.10.28** patched that report ([v2.2.0](https://github.com/modelcontextprotocol/servers/releases/tag/v2.2.0)), but the [follow-up advisory](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-q74p-4wrc-q7w6) requires **2026.11.11** ([v2.4.0](https://github.com/modelcontextprotocol/servers/releases/tag/v2.4.0)); the later index-path confinement fix requires **2026.11.18** ([v2.5.0](https://github.com/modelcontextprotocol/servers/releases/tag/v2.5.0)). Windows directory junctions remain excluded.

## What changed

- ShayanMuhammad-CS filed [#5230](https://github.com/modelcontextprotocol/servers/issues/5230) and [#5231](https://github.com/modelcontextprotocol/servers/issues/5231) on 2026-10-24 (checked 2026-10-28), asking that the unconfined default be made prominent. These document an existing behavior, not a newly introduced restriction.
- The [official README](https://github.com/modelcontextprotocol/servers/blob/main/src/git/README.md) explains that `--repository` accepts a path inside a working tree and finds its enclosing root. The [CLI definition](https://raw.githubusercontent.com/modelcontextprotocol/servers/main/src/git/src/mcp_server_git/__init__.py) confirms `--repository` and `-r` (checked 2026-10-28).

## How to migrate

1. Inspect the host's actual launch configuration. Replace `uvx mcp-server-git` with `uvx mcp-server-git --repository /path/to/git/repo`, substituting your intended repository's absolute path. The README's exact argument sequence is `mcp-server-git`, `--repository`, `path/to/git/repo`; pass these as separate arguments in a client configuration.
2. For the pip route, use the README's `python -m mcp_server_git --repository path/to/git/repo`. Restart the process after changing its arguments. Use an absolute path if the host's working directory is uncertain.
3. Confirm the installed build. [Official metadata](https://raw.githubusercontent.com/modelcontextprotocol/servers/main/src/git/pyproject.toml) identifies `mcp-server-git` 2026.11.18 as of November 2026 (checked 2026-11-23), including the later confinement patch above. Historical minimums are not interchangeable: [GHSA-j22h-9j4x-23w5](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-j22h-9j4x-23w5) fixes enforcement of a configured repository in 2025.12.18 (checked 2026-10-28); [GHSA-vjqx-cfc4-9h6v](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-vjqx-cfc4-9h6v) fixes out-of-tree `git_add` file arguments in 2026.1.14 (checked 2026-10-28). Do not downgrade to either minimum as a general recommendation.
4. Call `git_status` on the intended disposable repository, then on a separate sibling test repository. Require success for the first and a tool error for the second. Untested experiment: repeat through an alias symlink pointing to the sibling. Do not use a real unrelated repository to prove access.
5. If you need a stricter boundary than a repository tree, isolate the process with only that repository mounted or available to its OS user. This is operational guidance, not a promise that `--repository` provides process isolation.

## What breaks

Without the flag, each tool's `repo_path` chooses a reachable repository under the server process's privileges. An agent can therefore address a different repository even if the host UI shows one workspace. With confinement enabled, those calls should fail; repair the requested path rather than removing the flag.

A subdirectory argument grants the enclosing working tree. It does not create a subfolder-only grant. The earlier [validation code](https://raw.githubusercontent.com/modelcontextprotocol/servers/main/src/git/src/mcp_server_git/server.py) checked path containment before Git resolved `.git` indirection; the new advisory documents why that was insufficient. Include a nested-gitdir fixture in your policy checks, using disposable repositories only.

### Diagnostic: Repository path '{repo_path}' is outside the allowed repository '{allowed_repository}'

The official validator's error template is `Repository path '{repo_path}' is outside the allowed repository '{allowed_repository}'`. Braced names are placeholders replaced by actual paths. A rejected outside path is the intended boundary taking effect. The client may wrap this in its tool-error presentation.

## What to test

| Check | Expected policy |
|---|---|
| Intended repository | Read-only status succeeds |
| Sibling repository | Refused |
| Symlink resolving to sibling | Refused |
| Start from a subdirectory | Enclosing root is the grant |
| Nested repository | Explicitly assess whether containment is acceptable |
| Agent has another shell or filesystem tool | Verify that tool's permissions independently |

Use read-only calls for this verification. Confinement does not make commit, checkout or reset read-only inside the allowed tree.

## Pitfalls

Do not infer scope from a desktop workspace, process working directory or client Roots. The Git README states this server does not ask for client Roots. Do not invent `--allowed-directories`, a read-only flag, or an automatic fail-closed default. Restricting Git MCP does not restrict another tool exposed to the agent.

## Evidence

The two linked documentation issues have the same author and substantially the same report; they are not independent confirmations. They point to the existing default-scope behavior, which the official validator corroborates: `allowed_repository is None` returns without confinement. The historical advisories establish earlier enforcement defects; they do not say omission of the flag is now forbidden.

Not for: filesystem/Fetch release-wide security upgrades; see mcp-reference-servers-2-1-0-security-migration.

## A prompt to give your agent

> Your training data predates these scope reports. Read the linked Git README, CLI, validator and official advisories now. Inspect our actual launch arguments. Propose --repository with an explicit path, explain root expansion and nested-repository containment, and prepare read-only checks using disposable repositories. Do not guess flags, assume client Roots confine Git, or remove the restriction to silence an expected denial.

## Limits

No server or host configuration was executed. Independent community evidence is thin: the two documentation requests repeat one author's report. The proposed checks are untested. Repository containment is not a complete OS boundary, a subdirectory grant or proof that every Git operation cannot reach other resources.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.