mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-19 00:23:24 +02:00
Allow to check out branches
The git server currently lacks branch switching capabilities, limiting both LLMs and developers. This adds branch checkout so LLMs can help developers add new functionality in a new feature branch.
This commit is contained in:
@@ -44,6 +44,10 @@ class GitCreateBranch(BaseModel):
|
||||
branch_name: str
|
||||
base_branch: str | None = None
|
||||
|
||||
class GitCheckout(BaseModel):
|
||||
repo_path: str
|
||||
branch_name: str
|
||||
|
||||
class GitTools(str, Enum):
|
||||
STATUS = "git_status"
|
||||
DIFF_UNSTAGED = "git_diff_unstaged"
|
||||
@@ -53,6 +57,7 @@ class GitTools(str, Enum):
|
||||
RESET = "git_reset"
|
||||
LOG = "git_log"
|
||||
CREATE_BRANCH = "git_create_branch"
|
||||
CHECKOUT = "git_checkout"
|
||||
|
||||
def git_status(repo: git.Repo) -> str:
|
||||
return repo.git.status()
|
||||
@@ -96,6 +101,10 @@ def git_create_branch(repo: git.Repo, branch_name: str, base_branch: str | None
|
||||
repo.create_head(branch_name, base)
|
||||
return f"Created branch '{branch_name}' from '{base.name}'"
|
||||
|
||||
def git_checkout(repo: git.Repo, branch_name: str) -> str:
|
||||
repo.git.checkout(branch_name)
|
||||
return f"Switched to branch '{branch_name}'"
|
||||
|
||||
async def serve(repository: Path | None) -> None:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -152,6 +161,11 @@ async def serve(repository: Path | None) -> None:
|
||||
description="Creates a new branch from an optional base branch",
|
||||
inputSchema=GitCreateBranch.schema(),
|
||||
),
|
||||
Tool(
|
||||
name=GitTools.CHECKOUT,
|
||||
description="Switches branches",
|
||||
inputSchema=GitCheckout.schema(),
|
||||
),
|
||||
]
|
||||
|
||||
async def list_repos() -> Sequence[str]:
|
||||
@@ -249,6 +263,13 @@ async def serve(repository: Path | None) -> None:
|
||||
text=result
|
||||
)]
|
||||
|
||||
case GitTools.CHECKOUT:
|
||||
result = git_checkout(repo, arguments["branch_name"])
|
||||
return [TextContent(
|
||||
type="text",
|
||||
text=result
|
||||
)]
|
||||
|
||||
case _:
|
||||
raise ValueError(f"Unknown tool: {name}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user