Skip to content

Commit 582bc1d

Browse files
authored
Merge pull request #2757 from 0dd/security/git-server-optimization
Fix: Git Server Path Restriction
2 parents 402f0ed + c519dbb commit 582bc1d

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

src/git/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,8 @@ Please note that mcp-server-git is currently in early development. The functiona
8484
- `repo_path` (string): Path to Git repository
8585
- `revision` (string): The revision (commit hash, branch name, tag) to show
8686
- Returns: Contents of the specified commit
87-
12. `git_init`
88-
- Initializes a Git repository
89-
- Inputs:
90-
- `repo_path` (string): Path to directory to initialize git repo
91-
- Returns: Confirmation of repository initialization
9287

93-
13. `git_branch`
88+
12. `git_branch`
9489
- List Git branches
9590
- Inputs:
9691
- `repo_path` (string): Path to the Git repository.

src/git/src/mcp_server_git/server.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ class GitShow(BaseModel):
7070
repo_path: str
7171
revision: str
7272

73-
class GitInit(BaseModel):
74-
repo_path: str
73+
7574

7675
class GitBranch(BaseModel):
7776
repo_path: str = Field(
@@ -104,7 +103,7 @@ class GitTools(str, Enum):
104103
CREATE_BRANCH = "git_create_branch"
105104
CHECKOUT = "git_checkout"
106105
SHOW = "git_show"
107-
INIT = "git_init"
106+
108107
BRANCH = "git_branch"
109108

110109
def git_status(repo: git.Repo) -> str:
@@ -183,12 +182,7 @@ def git_checkout(repo: git.Repo, branch_name: str) -> str:
183182
repo.git.checkout(branch_name)
184183
return f"Switched to branch '{branch_name}'"
185184

186-
def git_init(repo_path: str) -> str:
187-
try:
188-
repo = git.Repo.init(path=repo_path, mkdir=True)
189-
return f"Initialized empty Git repository in {repo.git_dir}"
190-
except Exception as e:
191-
return f"Error initializing repository: {str(e)}"
185+
192186

193187
def git_show(repo: git.Repo, revision: str) -> str:
194188
commit = repo.commit(revision)
@@ -308,11 +302,7 @@ async def list_tools() -> list[Tool]:
308302
description="Shows the contents of a commit",
309303
inputSchema=GitShow.model_json_schema(),
310304
),
311-
Tool(
312-
name=GitTools.INIT,
313-
description="Initialize a new Git repository",
314-
inputSchema=GitInit.model_json_schema(),
315-
),
305+
316306
Tool(
317307
name=GitTools.BRANCH,
318308
description="List Git branches",
@@ -354,15 +344,7 @@ def by_commandline() -> Sequence[str]:
354344
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
355345
repo_path = Path(arguments["repo_path"])
356346

357-
# Handle git init separately since it doesn't require an existing repo
358-
if name == GitTools.INIT:
359-
result = git_init(str(repo_path))
360-
return [TextContent(
361-
type="text",
362-
text=result
363-
)]
364-
365-
# For all other commands, we need an existing repo
347+
# For all commands, we need an existing repo
366348
repo = git.Repo(repo_path)
367349

368350
match name:

0 commit comments

Comments
 (0)