git_clone
Clone a Git repository into a specified directory with options for branch selection, shallow cloning, and custom destination paths.
Instructions
Clone a repository into a new directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Repository URL to clone | |
| destination | No | Destination directory (defaults to repo name) | |
| cwd | No | Directory to clone into | |
| branch | No | Specific branch to clone | |
| depth | No | Create shallow clone with depth |
Implementation Reference
- src/tools/git.ts:302-307 (handler)The gitClone function implements the core logic for the git_clone tool by constructing and executing a 'git clone' command with optional parameters using the shared executeGitCommand helper.export async function gitClone(args: z.infer<typeof gitCloneSchema>): Promise<ToolResponse> { const branchFlag = args.branch ? `-b ${args.branch}` : ''; const depthFlag = args.depth ? `--depth ${args.depth}` : ''; const destination = args.destination || ''; return executeGitCommand(`git clone ${branchFlag} ${depthFlag} ${args.url} ${destination}`.trim(), args.cwd); }
- src/tools/git.ts:128-134 (schema)Zod schema defining the input validation for the git_clone tool parameters.export const gitCloneSchema = z.object({ url: z.string().describe('Repository URL to clone'), destination: z.string().optional().describe('Destination directory (defaults to repo name)'), cwd: z.string().optional().describe('Directory to clone into'), branch: z.string().optional().describe('Specific branch to clone'), depth: z.number().optional().describe('Create shallow clone with depth') });
- src/index.ts:393-396 (registration)Registration in the main MCP server request handler that dispatches 'git_clone' tool calls to the gitClone function after validating arguments with gitCloneSchema.if (name === 'git_clone') { const validated = gitCloneSchema.parse(args); return await gitClone(validated); }
- src/tools/git.ts:617-631 (registration)MCP tool definition in the gitTools array, providing the tool name, description, and JSON inputSchema for listing in MCP tool discovery.{ name: 'git_clone', description: 'Clone a repository into a new directory', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'Repository URL to clone' }, destination: { type: 'string', description: 'Destination directory (defaults to repo name)' }, cwd: { type: 'string', description: 'Directory to clone into' }, branch: { type: 'string', description: 'Specific branch to clone' }, depth: { type: 'number', description: 'Create shallow clone with depth' } }, required: ['url'] } },
- src/tools/git.ts:21-61 (helper)Shared helper function used by all git tools, including gitClone, to execute git commands and format responses.async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }