init
Initialize a new Git repository by specifying an absolute path for setup, enabling enhanced Git operations via the Git MCP Server for streamlined version control.
Instructions
Initialize a new Git repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path to initialize the repository in. MUST be an absolute path (e.g., /Users/username/projects/my-repo) |
Implementation Reference
- src/git-operations.ts:98-123 (handler)Primary handler for the 'init' tool. Validates path, executes 'git init' command, handles caching/invalidation, error handling, and returns formatted result.static async init(options: InitOptions, context: GitToolContext): Promise<GitToolResult> { const path = this.getPath(options); return await this.executeOperation( context.operation, path, async () => { const pathInfo = PathValidator.validatePath(path, { mustExist: false, allowDirectory: true }); const result = await CommandExecutor.executeGitCommand( 'init', context.operation, pathInfo ); return { content: [{ type: 'text', text: `Repository initialized successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'init', invalidateCache: true // Invalidate all caches for this repo } ); }
- src/tool-handler.ts:70-82 (registration)Registers the 'init' tool with the MCP server in ListTools handler, defining name, description, and JSON input schema.{ name: 'init', description: 'Initialize a new Git repository', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to initialize the repository in. ${PATH_DESCRIPTION}`, }, }, required: [], },
- src/tool-handler.ts:568-571 (registration)Registers and dispatches 'init' tool calls in the CallTool handler by validating arguments and invoking GitOperations.init.case 'init': { const validArgs = this.validateArguments(operation, args, isInitOptions); return await GitOperations.init(validArgs, context); }
- src/types.ts:45-45 (schema)TypeScript interface defining input parameters for the 'init' tool.export interface InitOptions extends GitOptions, BasePathOptions {}
- src/types.ts:141-143 (schema)Type guard function for validating 'init' tool input arguments.export function isInitOptions(obj: any): obj is InitOptions { return obj && validatePath(obj.path); }