@@ -52,6 +52,10 @@ class GitCheckout(BaseModel):
52
52
repo_path : str
53
53
branch_name : str
54
54
55
+ class GitShow (BaseModel ):
56
+ repo_path : str
57
+ revision : str
58
+
55
59
class GitTools (str , Enum ):
56
60
STATUS = "git_status"
57
61
DIFF_UNSTAGED = "git_diff_unstaged"
@@ -63,6 +67,7 @@ class GitTools(str, Enum):
63
67
LOG = "git_log"
64
68
CREATE_BRANCH = "git_create_branch"
65
69
CHECKOUT = "git_checkout"
70
+ SHOW = "git_show"
66
71
67
72
def git_status (repo : git .Repo ) -> str :
68
73
return repo .git .status ()
@@ -113,6 +118,24 @@ def git_checkout(repo: git.Repo, branch_name: str) -> str:
113
118
repo .git .checkout (branch_name )
114
119
return f"Switched to branch '{ branch_name } '"
115
120
121
+ def git_show (repo : git .Repo , revision : str ) -> str :
122
+ commit = repo .commit (revision )
123
+ output = [
124
+ f"Commit: { commit .hexsha } \n "
125
+ f"Author: { commit .author } \n "
126
+ f"Date: { commit .authored_datetime } \n "
127
+ f"Message: { commit .message } \n "
128
+ ]
129
+ if commit .parents :
130
+ parent = commit .parents [0 ]
131
+ diff = parent .diff (commit , create_patch = True )
132
+ else :
133
+ diff = commit .diff (git .NULL_TREE , create_patch = True )
134
+ for d in diff :
135
+ output .append (f"\n --- { d .a_path } \n +++ { d .b_path } \n " )
136
+ output .append (d .diff .decode ('utf-8' ))
137
+ return "" .join (output )
138
+
116
139
async def serve (repository : Path | None ) -> None :
117
140
logger = logging .getLogger (__name__ )
118
141
@@ -179,6 +202,11 @@ async def list_tools() -> list[Tool]:
179
202
description = "Switches branches" ,
180
203
inputSchema = GitCheckout .schema (),
181
204
),
205
+ Tool (
206
+ name = GitTools .SHOW ,
207
+ description = "Shows the contents of a commit" ,
208
+ inputSchema = GitShow .schema (),
209
+ )
182
210
]
183
211
184
212
async def list_repos () -> Sequence [str ]:
@@ -290,6 +318,13 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
290
318
text = result
291
319
)]
292
320
321
+ case GitTools .SHOW :
322
+ result = git_show (repo , arguments ["revision" ])
323
+ return [TextContent (
324
+ type = "text" ,
325
+ text = result
326
+ )]
327
+
293
328
case _:
294
329
raise ValueError (f"Unknown tool: { name } " )
295
330
0 commit comments