Skip to main content
Glama

refresh_repository

Update local Git repositories by checking out the main branch and pulling all remote changes. Use this tool to ensure your repository is current and synchronized with the latest updates.

Instructions

Refresh repository by checking out main branch and pulling all remotes

Args: repo_name: Name of the git repository Returns: Dictionary containing status and information about the operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_nameYes

Implementation Reference

  • The handler function for the refresh_repository tool, registered via @mcp.tool(). It validates the repository, checks out the main or master branch, fetches and pulls the latest changes from all configured remotes, and returns the status and results.
    @mcp.tool() async def refresh_repository(ctx: Context, repo_name: str) -> Dict: """Refresh repository by checking out main branch and pulling all remotes Args: repo_name: Name of the git repository Returns: Dictionary containing status and information about the operation """ git_ctx = ctx.get_context(GitContext) repo_path = os.path.join(git_ctx.git_repos_path, repo_name) # Validate repository exists if not os.path.exists(repo_path) or not os.path.exists( os.path.join(repo_path, ".git") ): raise ValueError(f"Repository not found: {repo_name}") try: # Get all remotes remotes = _run_git_command(repo_path, ["remote"]).strip().split("\n") if not remotes or remotes[0] == "": return { "status": "error", "error": f"No remotes configured for repository {repo_name}", } # Checkout main branch try: _run_git_command(repo_path, ["checkout", "main"]) except ValueError as e: # Try master if main doesn't exist try: _run_git_command(repo_path, ["checkout", "master"]) except ValueError: return { "status": "error", "error": f"Failed to checkout main or master branch: {str(e)}", } # Pull from all remotes pull_results = {} for remote in remotes: if remote: # Skip empty remote names try: result = _run_git_command(repo_path, ["pull", remote, "main"]) pull_results[remote] = "success" except ValueError as e: # Try master if main doesn't exist try: result = _run_git_command(repo_path, ["pull", remote, "master"]) pull_results[remote] = "success" except ValueError as e: pull_results[remote] = f"error: {str(e)}" return { "status": "success", "repository": repo_name, "branch": "main", "pull_results": pull_results, } except Exception as e: return {"status": "error", "error": f"Failed to refresh repository: {str(e)}"}

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kjozsa/git-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server