Repository navigation
git: name the --repository in the server's instructions - #5710
Conversation
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>
|
|
| 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.
There was a problem hiding this comment.
🟢 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
--repositoryis 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
|
Copilot round 1: clean, with no findings and no suppressed comments. The loop stops on the first clean round, as |
Closes #5610
Description
Implements the decision on #5610: when the git server is started with
--repository, itsinstructionsname the allowed repository, so a model has the exactrepo_pathstring before its first call.repo_pathstays required, with one input schema in every configuration.server_instructions(repository)builds the text. It names the repository root asvalidate_repo_pathcompares it (repository.resolve()), so the string it gives passes confinement as is: a--repositorygiven through a symlink, or as a subdirectory, still yields the resolved root.create_serverpasses it toMCPServer(instructions=...). The SDK puts it in the 2025-11-25initializeresult and the 2026-07-28server/discoverresult, on stdio and Streamable HTTP alike.--repository), every repository is in scope and there is nothing to name, so the server sends no instructions.The text, for
--repository /tmp/ron macOS:Server Details
git(mcp-server-git)instructions(new,--repositoryonly); 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 ininstructionsremoved every path error (15/15 tasks passed, with 0 errors in 17 calls). Makingrepo_pathoptional and adding Roots-based confinement were both declined in the decision comment. Descriptions on everyrepo_pathare #5647.How Has This Been Tested?
Protocol-level tests (real
mcpClient):tests/test_eras.py: in each era, a server started on<symlink to repo>/subdirsends instructions naming the resolved root, andgit_statuswith exactly that path succeeds. Without--repository,client.instructionsisNonein each era. For 2026-07-28 the client runs inautomode and the test asserts that it negotiated2026-07-28: a client pinned to that era builds its own discover result and never sendsserver/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.pyat 100% lines and 99.6% branches.Stdio probe, SDK
Client, both eras,--repository /tmp/.../demo-repo(a symlinked path on macOS):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 untrackedb.txt--protocol-era modern:isError: false, the sameLLM client: Claude Code 2.1.332 (
claude -p --strict-mcp-config, onlymcp__git__git_statusallowed). 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; perclient-smokeit negotiates 2026-07-28 with these servers.v2/main): passedrepo_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."repo_path: /private/tmp/.../demo-repoon the first call, and the reply listed one untracked file,b.txt.npm run local:gateexits 0. The interface-diff stage shows the newinstructions, which is expected.Breaking Changes
None. No tool, prompt or schema changes. A client that ignores
instructionsbehaves as before.Types of changes
Checklist
instructionsonInitializeResultand the 2026-07-28DiscoverResult)npm run changeset) if this changes what a TypeScript server publishes (not applicable: Python server, CalVer)serve()has already opened the repository)--repositorynow adds)Additional context
Roots-based confinement isn't wired, so the instructions cover
--repositoryonly, as the decision says. The diff stays increate_serverand the function before it, and touches no tool parameter annotation, so it does not overlap #5647, #5641 or #5690.🤖 Generated with Claude Code