Skip to content

git: name the --repository in the server's instructions - #5710

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/feat/5610-git-repository-instructions
Nov 30, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/feat/5610-git-repository-instructions

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #5610

Description

Implements the decision on #5610: when the git server is started with --repository, its instructions name the allowed repository, so a model has the exact repo_path string before its first call. repo_path stays required, with one input schema in every configuration.

  • server_instructions(repository) builds the text. It names the repository root as validate_repo_path compares it (repository.resolve()), so the string it gives passes confinement as is: a --repository given through a symlink, or as a subdirectory, still yields the resolved root.
  • create_server passes it to MCPServer(instructions=...). The SDK puts it in the 2025-11-25 initialize result and the 2026-07-28 server/discover result, on stdio and Streamable HTTP alike.
  • Unconfined (no --repository), every repository is in scope and there is nothing to name, so the server sends no instructions.

The text, for --repository /tmp/r on macOS:

This server is confined to the Git repository at /private/tmp/r. Pass exactly that path as repo_path to every tool and prompt: a path outside that repository is refused.

Server Details

  • Server: git (mcp-server-git)
  • Changes: server instructions (new, --repository only); README Configuration section. No tool, prompt or schema change.

Motivation and Context

#5552 and the measurements on #5610: with no hint, models guess repo_path (".", the project root) and are refused. In the measurement on #5610, naming the repository in instructions removed every path error (15/15 tasks passed, with 0 errors in 17 calls). Making repo_path optional and adding Roots-based confinement were both declined in the decision comment. Descriptions on every repo_path are #5647.

How Has This Been Tested?

Protocol-level tests (real mcp Client):

  • tests/test_eras.py: in each era, a server started on <symlink to repo>/subdir sends instructions naming the resolved root, and git_status with exactly that path succeeds. Without --repository, client.instructions is None in each era. For 2026-07-28 the client runs in auto mode and the test asserts that it negotiated 2026-07-28: a client pinned to that era builds its own discover result and never sends server/discover, so it would not see the instructions.
  • tests/test_http.py: the same over Streamable HTTP, in both eras.
  • npm run coverage:py -- git: server.py at 100% lines and 99.6% branches.

Stdio probe, SDK Client, both eras, --repository /tmp/.../demo-repo (a symlinked path on macOS):

2026-07-28 | This server is confined to the Git repository at /private/tmp/.../demo-repo. Pass exactly that path as repo_path to every tool and prompt: a path outside that repository is refused.
2025-11-25 | This server is confined to the Git repository at /private/tmp/.../demo-repo. Pass exactly that path as repo_path to every tool and prompt: a path outside that repository is refused.

Without --repository: 2026-07-28 | None, 2025-11-25 | None.

Inspector CLI 2.9.0: the CLI does not print instructions, so it checks that the path they name is accepted. --method tools/call --tool-name git_status --tool-arg repo_path=/private/tmp/.../demo-repo, with the server started on /tmp/.../demo-repo:

  • --protocol-era legacy: isError: false, Repository status: lists the untracked b.txt
  • --protocol-era modern: isError: false, the same

LLM client: Claude Code 2.1.332 (claude -p --strict-mcp-config, only mcp__git__git_status allowed). Prompt: "Using only the git MCP server's tools, list the untracked files in the repository the git server is configured for. Make at most one tool call. Reply with the exact repo_path value you passed, then the untracked file names, or say what went wrong." The prompt does not give the path. Claude Code gives no way to choose the era; per client-smoke it negotiates 2026-07-28 with these servers.

  • Before (v2/main): passed repo_path = the session's working directory, /Users/.../mcp-servers, and was refused with "Repository path '…' is outside the allowed repository '/tmp/.../demo-repo'". It said "None of the git tools tell you which repository the server is configured for. So I guessed."
  • After (this branch): passed repo_path: /private/tmp/.../demo-repo on the first call, and the reply listed one untracked file, b.txt.

npm run local:gate exits 0. The interface-diff stage shows the new instructions, which is expected.

Breaking Changes

None. No tool, prompt or schema changes. A client that ignores instructions behaves as before.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation (instructions on InitializeResult and the 2026-07-28 DiscoverResult)
  • My changes follow MCP security best practices (the instructions name only the repository the operator already confined the server to, and say nothing when it is unconfined)
  • I have updated the server's README accordingly
  • I have added a changeset (npm run changeset) if this changes what a TypeScript server publishes (not applicable: Python server, CalVer)
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling (not applicable: building the text cannot fail, since serve() has already opened the repository)
  • I have documented all environment variables and configuration options (no new option; the README describes what --repository now adds)

Additional context

Roots-based confinement isn't wired, so the instructions cover --repository only, as the decision says. The diff stays in create_server and the function before it, and touches no tool parameter annotation, so it does not overlap #5647, #5641 or #5690.

🤖 Generated with Claude Code

Started with --repository, the server's initialize result (2025-11-25)
and server/discover result (2026-07-28) carry instructions naming the
allowed repository root, resolved the way validate_repo_path compares
it, and telling the model to pass exactly that path as repo_path. A
model no longer has to guess a path and read the right one back from
the refusal. repo_path stays required with one schema; unconfined, the
server sends no instructions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall cliffhall added the v2 label Nov 30, 2026
@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ae2c4c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cliffhall
cliffhall requested a balanced review from Copilot November 30, 2026 07:24
@github-actions

Copy link
Copy Markdown
Contributor

git: MCP interface diff

Base: c0075947ac6b (Merge pull request #5682 from modelcontextprotocol/v2/chore/5681-python-calver-2026.11.27)
Head: the build in this checkout, at b6dfc42fb1d1 (Merge ae2c4c4 into c007594)

Diffed because it was named (--server).

⚠️ Interface changes detected in 2 part(s) of the interface. Review them below to confirm they are intended.

Tools Prompts Resources Resource templates
Base 14 2 0 0
Head 14 2 0 0

initialize

--- base/initialize.json
+++ target/initialize.json

+ instructions: "This server is confined to the Git repository at /home/runner/work/servers/servers/node_modules/.cac..."

instructions

Endpoint added in target (not present in base)

Updated by this run for ae2c4c483214ba5a54664addb178f2da60a51123.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the change exposing the configured repository path in server instructions.

No open issues 🎉

What changed in this PR

Addresses #5610 by giving models the configured Git repository path in server instructions before their first call, while keeping repo_path required and input schemas unchanged.

Changes:

  • Adds instructions naming the resolved repository root when --repository is set; leaves instructions unset otherwise.
  • Adds protocol-level coverage for both supported eras, including Streamable HTTP and symlink/subdirectory resolution.
  • Documents the instructions and unchanged path requirements.
File Description
src/​git/​tests/​test_http.py Checks repository instructions and path acceptance over HTTP in both eras.
src/​git/​tests/​test_eras.py Checks resolved-root instructions and their absence when unconfined.
src/​git/​src/​mcp_server_git/​server.py Builds repository-specific instructions and passes them to the server.
src/​git/​README.md Explains how instructions expose the configured repository path.

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: clean, with no findings and no suppressed comments. The loop stops on the first clean round, as pr-flow says. CI on ae2c4c48: 39 checks passed, 8 skipped.

@cliffhall
cliffhall merged commit 9634716 into v2/main Nov 30, 2026
48 checks passed
@cliffhall
cliffhall deleted the v2/feat/5610-git-repository-instructions branch November 30, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git: decide whether repo_path should default to the configured --repository

2 participants