add
Stage files in a Git repository by specifying the repository path and file paths. Simplify Git workflows and prepare changes for commits efficiently.
Instructions
Add files to the git staging area.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | List of pathspecs to add | |
| repoPath | Yes | Absolute path to the git repository |
Implementation Reference
- packages/mcp-git/src/tools/add.ts:34-61 (handler)The private handler method that implements the core logic of the 'add' tool: validates the repository, executes git add on the input files using simple-git, and returns success or error message.readonly #handle: ToolCallback<typeof GIT_ADD_INPUT_SCHEMA> = async (input) => { const sg = simpleGit(input.repoPath); const isRepo = await sg.checkIsRepo(); if (!isRepo) { return { isError: true, content: [ { type: 'text', text: 'Not a git repository', }, ], }; } // Execute git add await sg.add(input.files); return { content: [ { type: 'text', text: `Files added to staging area.`, }, ], }; };
- Zod input schema defining the parameters for the 'add' tool: repository path and list of files to add.export const GIT_ADD_INPUT_SCHEMA = { repoPath: z.string().describe('Absolute path to the git repository'), files: z.array(z.string()).describe('List of pathspecs to add'), };
- packages/mcp-git/src/tools/add.ts:30-32 (registration)The register method of GitAddTool class that registers the tool with the MCP server using its name ('add'), config, and handler.register(srv: McpServer) { srv.registerTool(this.name, this.config, this.#handle); }
- packages/mcp-git/src/index.ts:21-21 (registration)Instantiation of GitAddTool and call to its register method on the MCP server instance, effectively registering the 'add' tool.new GitAddTool().register(server);
- packages/mcp-git/src/tools/add.ts:26-28 (registration)Getter that returns the tool name 'add' used during registration.get name() { return 'add'; }