git_init
Initialize a new Git repository by specifying the path to set up version control for your project using the MCP Git Server.
Instructions
Initialize a new Git repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes |
Implementation Reference
- The core handler function that implements the git_init tool logic: initializes a new Git repository at the specified path using dulwich Repo.init().
def git_init(repo_path: str) -> str: """Initialize new Git repository""" try: path = Path(repo_path) path.mkdir(parents=True, exist_ok=True) # Initialize repository Repo.init(path) return f"✅ Initialized empty Git repository in {repo_path}" except Exception as e: return f"❌ Init failed: {str(e)}" - Pydantic input schema for the git_init tool, defining the required repo_path parameter.
class GitInit(BaseModel): repo_path: str - src/mcp_server_git/core/tools.py:262-269 (registration)ToolDefinition registration in the central ToolRegistry for the git_init tool (name="git_init"), linking schema and initial placeholder handler.
ToolDefinition( name=GitTools.INIT, category=ToolCategory.GIT, description="Initialize a new Git repository", schema=GitInit, handler=placeholder_handler, requires_repo=False, # Special case ), - src/mcp_server_git/core/handlers.py:107-107 (registration)Registration of the wrapped git_init handler in the git_handlers dictionary using special _create_git_init_handler (no repo required).
"git_init": self._create_git_init_handler(git_init), - Helper function to create a special wrapper handler for git_init, which extracts repo_path from kwargs and calls the core func (since it doesn't require a Repo object).
def _create_git_init_handler(self, func): """Special handler for git_init which doesn't need a repo object""" def handler(**kwargs): repo_path = kwargs["repo_path"] return func(repo_path) return handler