mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-20 12:55:21 +02:00
add git_show tool
This commit is contained in:
@@ -73,6 +73,12 @@ Please note that mcp-server-git is currently in early development. The functiona
|
|||||||
- `repo_path` (string): Path to Git repository
|
- `repo_path` (string): Path to Git repository
|
||||||
- `branch_name` (string): Name of branch to checkout
|
- `branch_name` (string): Name of branch to checkout
|
||||||
- Returns: Confirmation of branch switch
|
- Returns: Confirmation of branch switch
|
||||||
|
9. `git_show`
|
||||||
|
- Shows the contents of a commit
|
||||||
|
- Inputs:
|
||||||
|
- `repo_path` (string): Path to Git repository
|
||||||
|
- `revision` (string): The revision (commit hash, branch name, tag) to show
|
||||||
|
- Returns: Contents of the specified commit
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ class GitCheckout(BaseModel):
|
|||||||
repo_path: str
|
repo_path: str
|
||||||
branch_name: str
|
branch_name: str
|
||||||
|
|
||||||
|
class GitShow(BaseModel):
|
||||||
|
repo_path: str
|
||||||
|
revision: str
|
||||||
|
|
||||||
class GitTools(str, Enum):
|
class GitTools(str, Enum):
|
||||||
STATUS = "git_status"
|
STATUS = "git_status"
|
||||||
DIFF_UNSTAGED = "git_diff_unstaged"
|
DIFF_UNSTAGED = "git_diff_unstaged"
|
||||||
@@ -63,6 +67,7 @@ class GitTools(str, Enum):
|
|||||||
LOG = "git_log"
|
LOG = "git_log"
|
||||||
CREATE_BRANCH = "git_create_branch"
|
CREATE_BRANCH = "git_create_branch"
|
||||||
CHECKOUT = "git_checkout"
|
CHECKOUT = "git_checkout"
|
||||||
|
SHOW = "git_show"
|
||||||
|
|
||||||
def git_status(repo: git.Repo) -> str:
|
def git_status(repo: git.Repo) -> str:
|
||||||
return repo.git.status()
|
return repo.git.status()
|
||||||
@@ -113,6 +118,24 @@ def git_checkout(repo: git.Repo, branch_name: str) -> str:
|
|||||||
repo.git.checkout(branch_name)
|
repo.git.checkout(branch_name)
|
||||||
return f"Switched to branch '{branch_name}'"
|
return f"Switched to branch '{branch_name}'"
|
||||||
|
|
||||||
|
def git_show(repo: git.Repo, revision: str) -> str:
|
||||||
|
commit = repo.commit(revision)
|
||||||
|
output = [
|
||||||
|
f"Commit: {commit.hexsha}\n"
|
||||||
|
f"Author: {commit.author}\n"
|
||||||
|
f"Date: {commit.authored_datetime}\n"
|
||||||
|
f"Message: {commit.message}\n"
|
||||||
|
]
|
||||||
|
if commit.parents:
|
||||||
|
parent = commit.parents[0]
|
||||||
|
diff = parent.diff(commit, create_patch=True)
|
||||||
|
else:
|
||||||
|
diff = commit.diff(git.NULL_TREE, create_patch=True)
|
||||||
|
for d in diff:
|
||||||
|
output.append(f"\n--- {d.a_path}\n+++ {d.b_path}\n")
|
||||||
|
output.append(d.diff.decode('utf-8'))
|
||||||
|
return "".join(output)
|
||||||
|
|
||||||
async def serve(repository: Path | None) -> None:
|
async def serve(repository: Path | None) -> None:
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -179,6 +202,11 @@ async def serve(repository: Path | None) -> None:
|
|||||||
description="Switches branches",
|
description="Switches branches",
|
||||||
inputSchema=GitCheckout.schema(),
|
inputSchema=GitCheckout.schema(),
|
||||||
),
|
),
|
||||||
|
Tool(
|
||||||
|
name=GitTools.SHOW,
|
||||||
|
description="Shows the contents of a commit",
|
||||||
|
inputSchema=GitShow.schema(),
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
async def list_repos() -> Sequence[str]:
|
async def list_repos() -> Sequence[str]:
|
||||||
@@ -290,6 +318,13 @@ async def serve(repository: Path | None) -> None:
|
|||||||
text=result
|
text=result
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
case GitTools.SHOW:
|
||||||
|
result = git_show(repo, arguments["revision"])
|
||||||
|
return [TextContent(
|
||||||
|
type="text",
|
||||||
|
text=result
|
||||||
|
)]
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
raise ValueError(f"Unknown tool: {name}")
|
raise ValueError(f"Unknown tool: {name}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user