@@ -56,6 +56,9 @@ class GitShow(BaseModel):
56
56
repo_path : str
57
57
revision : str
58
58
59
+ class GitInit (BaseModel ):
60
+ repo_path : str
61
+
59
62
class GitTools (str , Enum ):
60
63
STATUS = "git_status"
61
64
DIFF_UNSTAGED = "git_diff_unstaged"
@@ -68,6 +71,7 @@ class GitTools(str, Enum):
68
71
CREATE_BRANCH = "git_create_branch"
69
72
CHECKOUT = "git_checkout"
70
73
SHOW = "git_show"
74
+ INIT = "git_init"
71
75
72
76
def git_status (repo : git .Repo ) -> str :
73
77
return repo .git .status ()
@@ -118,6 +122,13 @@ def git_checkout(repo: git.Repo, branch_name: str) -> str:
118
122
repo .git .checkout (branch_name )
119
123
return f"Switched to branch '{ branch_name } '"
120
124
125
+ def git_init (repo_path : str ) -> str :
126
+ try :
127
+ repo = git .Repo .init (path = repo_path , mkdir = True )
128
+ return f"Initialized empty Git repository in { repo .git_dir } "
129
+ except Exception as e :
130
+ return f"Error initializing repository: { str (e )} "
131
+
121
132
def git_show (repo : git .Repo , revision : str ) -> str :
122
133
commit = repo .commit (revision )
123
134
output = [
@@ -206,6 +217,11 @@ async def list_tools() -> list[Tool]:
206
217
name = GitTools .SHOW ,
207
218
description = "Shows the contents of a commit" ,
208
219
inputSchema = GitShow .schema (),
220
+ ),
221
+ Tool (
222
+ name = GitTools .INIT ,
223
+ description = "Initialize a new Git repository" ,
224
+ inputSchema = GitInit .schema (),
209
225
)
210
226
]
211
227
@@ -241,6 +257,16 @@ def by_commandline() -> Sequence[str]:
241
257
@server .call_tool ()
242
258
async def call_tool (name : str , arguments : dict ) -> list [TextContent ]:
243
259
repo_path = Path (arguments ["repo_path" ])
260
+
261
+ # Handle git init separately since it doesn't require an existing repo
262
+ if name == GitTools .INIT :
263
+ result = git_init (str (repo_path ))
264
+ return [TextContent (
265
+ type = "text" ,
266
+ text = result
267
+ )]
268
+
269
+ # For all other commands, we need an existing repo
244
270
repo = git .Repo (repo_path )
245
271
246
272
match name :
0 commit comments