Skip to main content
Glama

push_git_tag

Push a specified Git tag to the default remote repository. Requires the repository name and tag name to execute the operation, returning status and details about the action.

Instructions

Push a git tag to the default remote

Args:
    repo_name: Name of the git repository
    tag_name: Name of the tag to push

Returns:
    Dictionary containing status and information about the operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_nameYes
tag_nameYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), which registers and implements the push_git_tag tool. It validates the repo and tag, finds the default remote, pushes the tag, and returns status info.
    @mcp.tool()
    def push_git_tag(ctx: Context, repo_name: str, tag_name: str) -> Dict[str, str]:
        """Push a git tag to the default remote
    
        Args:
            repo_name: Name of the git repository
            tag_name: Name of the tag to push
    
        Returns:
            Dictionary containing status and information about the operation
        """
        git_repos_path = ctx.request_context.lifespan_context.git_repos_path
        repo_path = os.path.join(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}")
    
        # Validate tag exists
        try:
            _run_git_command(repo_path, ["tag", "-l", tag_name])
        except ValueError:
            return {
                "status": "error",
                "error": f"Tag {tag_name} not found in repository {repo_name}",
            }
    
        # Get the default remote (usually 'origin')
        try:
            remote = _run_git_command(repo_path, ["remote"])
            if not remote:
                return {
                    "status": "error",
                    "error": f"No remote configured for repository {repo_name}",
                }
            # Use the first remote if multiple are available
            default_remote = remote.split("\n")[0].strip()
    
            # Push the tag to the remote
            push_result = _run_git_command(repo_path, ["push", default_remote, tag_name])
    
            return {
                "status": "success",
                "remote": default_remote,
                "tag": tag_name,
                "message": f"Successfully pushed tag {tag_name} to remote {default_remote}",
            }
        except ValueError as e:
            return {"status": "error", "error": str(e)}
  • Helper utility function used by the push_git_tag handler (and others) to safely execute git commands in a repository context, capturing output and raising errors appropriately.
    def _run_git_command(repo_path: str, command: List[str]) -> str:
        """Run a git command in the specified repository path"""
        if not os.path.exists(repo_path):
            raise ValueError(f"Repository path does not exist: {repo_path}")
    
        full_command = ["git"] + command
        try:
            result = subprocess.run(
                full_command, cwd=repo_path, check=True, capture_output=True, text=True
            )
            return result.stdout.strip()
        except subprocess.CalledProcessError as e:
            error_message = e.stderr.strip() if e.stderr else str(e)
            raise ValueError(f"Git command failed: {error_message}")
Install Server

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