git mcp v2

Local 2025-08-31 23:46:54 0
Version Control @Sheshiyer/git-mcp-v2

The Git MCP Server allows AI assistants to perform enhanced Git operations via the Model Context Protocol, supporting core Git functions, branch and tag management, GitHub integration, and more.


A Model Context Protocol (MCP) server that provides enhanced Git operations through a standardized interface. This server integrates with the MCP ecosystem to provide Git functionality to AI assistants.

Features

  • Core Git Operations: init, clone, status, add, commit, push, pull
  • Branch Management: list, create, delete, checkout
  • Tag Operations: list, create, delete
  • Remote Management: list, add, remove
  • Stash Operations: list, save, pop
  • Bulk Actions: Execute multiple Git operations in sequence
  • GitHub Integration: Built-in GitHub support via Personal Access Token
  • Path Resolution: Smart path handling with optional default path configuration
  • Error Handling: Comprehensive error handling with custom error types
  • Repository Caching: Efficient repository state management
  • Performance Monitoring: Built-in performance tracking

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/git-mcp-v2.git
    cd git-mcp-v2

  2. Install dependencies:

    npm install

  3. Build the project:

    npm run build

Configuration

Add to your MCP settings file:

{
  "mcpServers": {
    "git-v2": {
      "command": "node",
      "args": ["path/to/git-mcp-v2/build/index.js"],
      "env": {
        "GIT_DEFAULT_PATH": "/path/to/default/git/directory",
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your-github-pat"
      }
    }
  }
}

Environment Variables

  • GIT_DEFAULT_PATH: (Optional) Default path for Git operations
  • GITHUB_PERSONAL_ACCESS_TOKEN: (Optional) GitHub Personal Access Token for GitHub operations

Available Tools

Basic Operations

  • init: Initialize a new Git repository
  • clone: Clone a repository
  • status: Get repository status
  • add: Stage files
  • commit: Create a commit
  • push: Push commits to remote
  • pull: Pull changes from remote

Branch Operations

  • branch_list: List all branches
  • branch_create: Create a new branch
  • branch_delete: Delete a branch
  • checkout: Switch branches or restore working tree files

Tag Operations

  • tag_list: List tags
  • tag_create: Create a tag
  • tag_delete: Delete a tag

Remote Operations

  • remote_list: List remotes
  • remote_add: Add a remote
  • remote_remove: Remove a remote

Stash Operations

  • stash_list: List stashes
  • stash_save: Save changes to stash
  • stash_pop: Apply and remove a stash

Bulk Operations

  • bulk_action: Execute multiple Git operations in sequence

Development

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Run linter
npm run lint

# Format code
npm run format

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request
[
  {
    "description": "Initialize a new Git repository",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to initialize the repository in. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "init"
  },
  {
    "description": "Clone a repository",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to clone into. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        },
        "url": {
          "description": "URL of the repository to clone",
          "type": "string"
        }
      },
      "required": [
        "url"
      ],
      "type": "object"
    },
    "name": "clone"
  },
  {
    "description": "Get repository status",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "status"
  },
  {
    "description": "Stage files",
    "inputSchema": {
      "properties": {
        "files": {
          "description": "Files to stage",
          "items": {
            "description": "MUST be an absolute path (e.g., /Users/username/projects/my-repo/src/file.js)",
            "type": "string"
          },
          "type": "array"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [
        "files"
      ],
      "type": "object"
    },
    "name": "add"
  },
  {
    "description": "Create a commit",
    "inputSchema": {
      "properties": {
        "message": {
          "description": "Commit message",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [
        "message"
      ],
      "type": "object"
    },
    "name": "commit"
  },
  {
    "description": "Push commits to remote",
    "inputSchema": {
      "properties": {
        "branch": {
          "description": "Branch name",
          "type": "string"
        },
        "force": {
          "default": false,
          "description": "Force push changes",
          "type": "boolean"
        },
        "noVerify": {
          "default": false,
          "description": "Skip pre-push hooks",
          "type": "boolean"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        },
        "remote": {
          "default": "origin",
          "description": "Remote name",
          "type": "string"
        },
        "tags": {
          "default": false,
          "description": "Push all tags",
          "type": "boolean"
        }
      },
      "required": [
        "branch"
      ],
      "type": "object"
    },
    "name": "push"
  },
  {
    "description": "Pull changes from remote",
    "inputSchema": {
      "properties": {
        "branch": {
          "description": "Branch name",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        },
        "remote": {
          "default": "origin",
          "description": "Remote name",
          "type": "string"
        }
      },
      "required": [
        "branch"
      ],
      "type": "object"
    },
    "name": "pull"
  },
  {
    "description": "List all branches",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "branch_list"
  },
  {
    "description": "Create a new branch",
    "inputSchema": {
      "properties": {
        "force": {
          "default": false,
          "description": "Force create branch even if it exists",
          "type": "boolean"
        },
        "name": {
          "description": "Branch name",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        },
        "setUpstream": {
          "default": false,
          "description": "Set upstream for push/pull",
          "type": "boolean"
        },
        "track": {
          "default": true,
          "description": "Set up tracking mode",
          "type": "boolean"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "name": "branch_create"
  },
  {
    "description": "Delete a branch",
    "inputSchema": {
      "properties": {
        "name": {
          "description": "Branch name",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "name": "branch_delete"
  },
  {
    "description": "Switch branches or restore working tree files",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        },
        "target": {
          "description": "Branch name, commit hash, or file path",
          "type": "string"
        }
      },
      "required": [
        "target"
      ],
      "type": "object"
    },
    "name": "checkout"
  },
  {
    "description": "List tags",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "tag_list"
  },
  {
    "description": "Create a tag",
    "inputSchema": {
      "properties": {
        "annotated": {
          "default": true,
          "description": "Create an annotated tag",
          "type": "boolean"
        },
        "force": {
          "default": false,
          "description": "Force create tag even if it exists",
          "type": "boolean"
        },
        "message": {
          "description": "Tag message",
          "type": "string"
        },
        "name": {
          "description": "Tag name",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        },
        "sign": {
          "default": false,
          "description": "Create a signed tag",
          "type": "boolean"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "name": "tag_create"
  },
  {
    "description": "Delete a tag",
    "inputSchema": {
      "properties": {
        "name": {
          "description": "Tag name",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "name": "tag_delete"
  },
  {
    "description": "List remotes",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "remote_list"
  },
  {
    "description": "Add a remote",
    "inputSchema": {
      "properties": {
        "name": {
          "description": "Remote name",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        },
        "url": {
          "description": "Remote URL",
          "type": "string"
        }
      },
      "required": [
        "name",
        "url"
      ],
      "type": "object"
    },
    "name": "remote_add"
  },
  {
    "description": "Remove a remote",
    "inputSchema": {
      "properties": {
        "name": {
          "description": "Remote name",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "name": "remote_remove"
  },
  {
    "description": "List stashes",
    "inputSchema": {
      "properties": {
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "stash_list"
  },
  {
    "description": "Save changes to stash",
    "inputSchema": {
      "properties": {
        "all": {
          "default": false,
          "description": "Include ignored files",
          "type": "boolean"
        },
        "includeUntracked": {
          "default": false,
          "description": "Include untracked files",
          "type": "boolean"
        },
        "keepIndex": {
          "default": false,
          "description": "Keep staged changes",
          "type": "boolean"
        },
        "message": {
          "description": "Stash message",
          "type": "string"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "stash_save"
  },
  {
    "description": "Apply and remove a stash",
    "inputSchema": {
      "properties": {
        "index": {
          "default": 0,
          "description": "Stash index",
          "type": "number"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [],
      "type": "object"
    },
    "name": "stash_pop"
  },
  {
    "description": "Execute multiple Git operations in sequence. This is the preferred way to execute multiple operations.",
    "inputSchema": {
      "properties": {
        "actions": {
          "description": "Array of Git operations to execute in sequence",
          "items": {
            "oneOf": [
              {
                "properties": {
                  "files": {
                    "description": "Files to stage. If not provided, stages all changes.",
                    "items": {
                      "description": "MUST be an absolute path (e.g., /Users/username/projects/my-repo/src/file.js)",
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "type": {
                    "const": "stage"
                  }
                },
                "required": [
                  "type"
                ],
                "type": "object"
              },
              {
                "properties": {
                  "message": {
                    "description": "Commit message",
                    "type": "string"
                  },
                  "type": {
                    "const": "commit"
                  }
                },
                "required": [
                  "type",
                  "message"
                ],
                "type": "object"
              },
              {
                "properties": {
                  "branch": {
                    "description": "Branch name",
                    "type": "string"
                  },
                  "remote": {
                    "default": "origin",
                    "description": "Remote name",
                    "type": "string"
                  },
                  "type": {
                    "const": "push"
                  }
                },
                "required": [
                  "type",
                  "branch"
                ],
                "type": "object"
              }
            ],
            "type": "object"
          },
          "minItems": 1,
          "type": "array"
        },
        "path": {
          "description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
          "type": "string"
        }
      },
      "required": [
        "actions"
      ],
      "type": "object"
    },
    "name": "bulk_action"
  }
]