git_add
Stage files in a Git repository. Prepares specified files for commit by adding their current contents to the staging area.
Instructions
Adds file contents to the staging area
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | ||
| files | Yes |
Implementation Reference
- The git_add function: executes the 'git add' logic. If files is ['.'], runs 'git add .' to stage all changes. Otherwise uses 'git add -- <files>' to safely stage specific files (the '--' prevents file names starting with '-' from being interpreted as options). Returns 'Files staged successfully'.
def git_add(repo: git.Repo, files: list[str]) -> str: if files == ["."]: repo.git.add(".") else: # Use '--' to prevent files starting with '-' from being interpreted as options repo.git.add("--", *files) return "Files staged successfully" - GitAdd Pydantic model: defines the input schema for the git_add tool with two fields: 'repo_path' (str) and 'files' (list[str]).
class GitAdd(BaseModel): repo_path: str files: list[str] - src/git/src/mcp_server_git/server.py:96-102 (registration)Enum registration: GitTools.ADD = 'git_add' registers the tool name used throughout the codebase.
class GitTools(str, Enum): STATUS = "git_status" DIFF_UNSTAGED = "git_diff_unstaged" DIFF_STAGED = "git_diff_staged" DIFF = "git_diff" COMMIT = "git_commit" ADD = "git_add" - src/git/src/mcp_server_git/server.py:364-374 (registration)Tool registration in list_tools(): registers the 'git_add' tool with description 'Adds file contents to the staging area' and inputSchema from GitAdd.model_json_schema(). Annotations indicate it is not readOnly, not destructive, and idempotent.
Tool( name=GitTools.ADD, description="Adds file contents to the staging area", inputSchema=GitAdd.model_json_schema(), annotations=ToolAnnotations( readOnlyHint=False, destructiveHint=False, idempotentHint=True, openWorldHint=False, ), ),