git_pull
Synchronize local repository with remote changes by pulling updates from a specified branch using the MCP Git Server. Simplify version control for Git-based projects.
Instructions
Pull changes from remote repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | No | ||
| remote | No | origin | |
| repo_path | Yes |
Implementation Reference
- The core handler function that executes the git pull operation using GitPython's repo.git.pull method, with error handling for authentication and conflicts.def git_pull(repo: Repo, remote: str = "origin", branch: str | None = None) -> str: """Pull changes from remote repository""" try: # Get current branch if not specified if not branch: try: branch = repo.active_branch.name except TypeError: # Detached HEAD or no commits return "❌ No active branch found and no branch specified" # Perform pull if branch: result = repo.git.pull(remote, branch) else: result = repo.git.pull(remote) return f"✅ Successfully pulled from {remote}/{branch}\n{result}" except GitCommandError as e: if "Authentication failed" in str(e): return f"❌ Authentication failed. Check credentials for {remote}" elif "merge conflict" in str(e).lower(): return "❌ Pull failed due to merge conflicts. Resolve conflicts and retry" else: return f"❌ Pull failed: {str(e)}" except Exception as e: return f"❌ Pull error: {str(e)}"
- Pydantic schema/model defining the input parameters for the git_pull tool: repo_path (required), remote (default 'origin'), branch (optional).class GitPull(BaseModel): repo_path: str remote: str = "origin" branch: str | None = None
- src/mcp_server_git/core/handlers.py:113-115 (registration)Registration of the git_pull tool handler in the GitToolRouter, wrapping the git_pull function from operations.py with error handling and repo validation."git_pull": self._create_git_handler( git_pull, requires_repo=True, extra_args=["remote", "branch"] ),
- src/mcp_server_git/core/tools.py:278-285 (registration)ToolDefinition registration in the ToolRegistry for 'git_pull' (GitTools.PULL), associating the schema and metadata; handler set later by router.ToolDefinition( name=GitTools.PULL, category=ToolCategory.GIT, description="Pull changes from remote repository", schema=GitPull, handler=placeholder_handler, requires_repo=True, ),
- Protected wrapper for git_pull that adds repository binding validation and remote contamination checks before calling the core git_pull function.async def protected_git_pull( self, repo_path: str, remote: str = "origin", branch: str | None = None ) -> str: """Git pull with repository binding protection.""" validated_path = await self._validate_and_prepare_operation(repo_path) # Additional remote validation for pull operations binding = self.binding_manager.binding if binding and remote == binding.remote_name: current_remote = await self._get_current_remote_url(validated_path) if current_remote != binding.expected_remote_url: raise RemoteContaminationError( f"Cannot pull: remote {remote} has been contaminated!\n" f"Expected: {binding.expected_remote_url}\n" f"Current: {current_remote}" ) logger.info( f"Protected pull: {validated_path} <- {remote}/{branch or 'current'}" ) repo = Repo(validated_path) return git_pull(repo, remote, branch)