init
Initialize a new Git repository by specifying the path, initial branch, template, or creating a bare repository, enabling streamlined repository setup for AI-driven workflows.
Instructions
Initialize new Git repository.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bare | No | Create a bare repository (--bare) | |
| initialBranch | No | Set the initial branch name (--initial-branch) | |
| repoPath | Yes | Absolute path where to initialize the git repository | |
| template | No | Template directory to use (--template) |
Implementation Reference
- packages/mcp-git/src/tools/init.ts:36-68 (handler)The private #handle method that executes the 'init' tool: initializes a Git repo at repoPath using simple-git with optional bare, initialBranch, template flags, returns success message and result.readonly #handle: ToolCallback<typeof GIT_INIT_INPUT_SCHEMA> = async (input) => { const sg = simpleGit(input.repoPath); const options: string[] = []; if (input.bare) { options.push('--bare'); } if (input.initialBranch) { options.push('--initial-branch', input.initialBranch); } if (input.template) { options.push('--template', input.template); } const result = await sg.init(options); return { content: [ { type: 'text', text: `Initialized ${input.bare ? 'bare ' : ''}Git repository in ${input.repoPath}`, }, { type: 'text', text: JSON.stringify(result), }, ], }; }; }
- Zod input schema for the 'init' tool defining required repoPath and optional bare, initialBranch, template parameters.export const GIT_INIT_INPUT_SCHEMA = { repoPath: z.string().describe('Absolute path where to initialize the git repository'), bare: z.boolean().optional().describe('Create a bare repository (--bare)'), initialBranch: z.string().optional().describe('Set the initial branch name (--initial-branch)'), template: z.string().optional().describe('Template directory to use (--template)'), };
- packages/mcp-git/src/tools/init.ts:32-34 (registration)Class method that registers the 'init' tool with the MCP server by calling srv.registerTool(name, config, handle).register(srv: McpServer) { srv.registerTool(this.name, this.config, this.#handle); }
- packages/mcp-git/src/index.ts:29-29 (registration)Site where GitInitTool is instantiated and its register method is called to add the 'init' tool to the server.new GitInitTool().register(server);
- Getter returning the tool name as 'init'.get name() { return 'init'; }