add
Stage files in a Git repository by specifying absolute paths. Integrates with the Git MCP Server to enhance AI-assisted Git operations for efficient version control.
Instructions
Stage files
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | Files to stage | |
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) |
Input Schema (JSON Schema)
{
"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"
}
Implementation Reference
- src/git-operations.ts:179-210 (handler)The primary handler function for the 'add' tool. It validates the repository path, executes 'git add' for each specified file, invalidates relevant caches, and returns a success message.static async add({ path, files }: AddOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); // Handle each file individually to avoid path issues for (const file of files) { await CommandExecutor.executeGitCommand( `add "${file}"`, context.operation, repoPath ); } return { content: [{ type: 'text', text: 'Files staged successfully' }] }; }, { command: 'add', invalidateCache: true, // Invalidate status cache stateType: RepoStateType.STATUS } ); }
- src/tool-handler.ts:116-137 (registration)Registers the 'add' tool with MCP server, including its name, description, and input schema for tool listing.{ name: 'add', description: 'Stage files', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, files: { type: 'array', items: { type: 'string', description: FILE_PATH_DESCRIPTION, }, description: 'Files to stage', }, }, required: ['files'], }, },
- src/types.ts:54-60 (schema)TypeScript interface defining the input parameters for the 'add' tool.export interface AddOptions extends GitOptions, BasePathOptions { /** * Array of absolute paths to files to stage * Example: /Users/username/projects/my-repo/src/file.js */ files: string[]; }
- src/types.ts:151-156 (helper)Type guard function used to validate arguments for the 'add' tool before execution.export function isAddOptions(obj: any): obj is AddOptions { return obj && validatePath(obj.path) && Array.isArray(obj.files) && obj.files.every((f: any) => typeof f === 'string' && isAbsolutePath(f)); }
- src/tool-handler.ts:583-586 (handler)Dispatch handler in the tool executor that validates arguments and delegates to GitOperations.add.case 'add': { const validArgs = this.validateArguments(operation, args, isAddOptions); return await GitOperations.add(validArgs, context); }