Merge pull request #1753 from hesreallyhim/hesreallyhim/git-small-fixes-with-typing-and-strings

[FIX] `mcp_server_git`: replace deprecated pydantic functions and small fixes to typing issues
This commit is contained in:
Ola Hungerford 2025-06-24 20:55:10 -07:00 • committed by GitHub
commit 9898e5a94e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 21 deletions

View file

View file

@ -102,16 +102,16 @@ def git_log(repo: git.Repo, max_count: int = 10) -> list[str]:
log = [] log = []
for commit in commits: for commit in commits:
log.append( log.append(
f"Commit: {commit.hexsha}\n" f"Commit: {commit.hexsha!r}\n"
f"Author: {commit.author}\n" f"Author: {commit.author!r}\n"
f"Date: {commit.authored_datetime}\n" f"Date: {commit.authored_datetime}\n"
f"Message: {commit.message}\n" f"Message: {commit.message!r}\n"
) )
return log return log
def git_create_branch(repo: git.Repo, branch_name: str, base_branch: str | None = None) -> str: def git_create_branch(repo: git.Repo, branch_name: str, base_branch: str | None = None) -> str:
if base_branch: if base_branch:
base = repo.refs[base_branch] base = repo.references[base_branch]
else: else:
base = repo.active_branch base = repo.active_branch
@ -132,10 +132,10 @@ def git_init(repo_path: str) -> str:
def git_show(repo: git.Repo, revision: str) -> str: def git_show(repo: git.Repo, revision: str) -> str:
commit = repo.commit(revision) commit = repo.commit(revision)
output = [ output = [
f"Commit: {commit.hexsha}\n" f"Commit: {commit.hexsha!r}\n"
f"Author: {commit.author}\n" f"Author: {commit.author!r}\n"
f"Date: {commit.authored_datetime}\n" f"Date: {commit.authored_datetime!r}\n"
f"Message: {commit.message}\n" f"Message: {commit.message!r}\n"
] ]
if commit.parents: if commit.parents:
parent = commit.parents[0] parent = commit.parents[0]
@ -166,62 +166,62 @@ async def serve(repository: Path | None) -> None:
Tool( Tool(
name=GitTools.STATUS, name=GitTools.STATUS,
description="Shows the working tree status", description="Shows the working tree status",
inputSchema=GitStatus.schema(), inputSchema=GitStatus.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.DIFF_UNSTAGED, name=GitTools.DIFF_UNSTAGED,
description="Shows changes in the working directory that are not yet staged", description="Shows changes in the working directory that are not yet staged",
inputSchema=GitDiffUnstaged.schema(), inputSchema=GitDiffUnstaged.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.DIFF_STAGED, name=GitTools.DIFF_STAGED,
description="Shows changes that are staged for commit", description="Shows changes that are staged for commit",
inputSchema=GitDiffStaged.schema(), inputSchema=GitDiffStaged.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.DIFF, name=GitTools.DIFF,
description="Shows differences between branches or commits", description="Shows differences between branches or commits",
inputSchema=GitDiff.schema(), inputSchema=GitDiff.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.COMMIT, name=GitTools.COMMIT,
description="Records changes to the repository", description="Records changes to the repository",
inputSchema=GitCommit.schema(), inputSchema=GitCommit.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.ADD, name=GitTools.ADD,
description="Adds file contents to the staging area", description="Adds file contents to the staging area",
inputSchema=GitAdd.schema(), inputSchema=GitAdd.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.RESET, name=GitTools.RESET,
description="Unstages all staged changes", description="Unstages all staged changes",
inputSchema=GitReset.schema(), inputSchema=GitReset.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.LOG, name=GitTools.LOG,
description="Shows the commit logs", description="Shows the commit logs",
inputSchema=GitLog.schema(), inputSchema=GitLog.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.CREATE_BRANCH, name=GitTools.CREATE_BRANCH,
description="Creates a new branch from an optional base branch", description="Creates a new branch from an optional base branch",
inputSchema=GitCreateBranch.schema(), inputSchema=GitCreateBranch.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.CHECKOUT, name=GitTools.CHECKOUT,
description="Switches branches", description="Switches branches",
inputSchema=GitCheckout.schema(), inputSchema=GitCheckout.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.SHOW, name=GitTools.SHOW,
description="Shows the contents of a commit", description="Shows the contents of a commit",
inputSchema=GitShow.schema(), inputSchema=GitShow.model_json_schema(),
), ),
Tool( Tool(
name=GitTools.INIT, name=GitTools.INIT,
description="Initialize a new Git repository", description="Initialize a new Git repository",
inputSchema=GitInit.schema(), inputSchema=GitInit.model_json_schema(),
) )
] ]