git_clone
Clone a Git repository to a specified directory path. Optionally open the cloned project in VSCode for immediate development work.
Instructions
Clone a git repository to a specified location
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repositoryUrl | Yes | Git repository URL | |
| destination | Yes | Destination path where to clone the repository | |
| openInVSCode | No | Open the cloned repository in VSCode (default: false) |
Implementation Reference
- src/index.ts:255-279 (handler)Handler implementation for the git_clone tool. Clones the specified git repository to the destination path using simple-git, ensures the parent directory exists, resolves paths, and optionally opens the cloned repository in VSCode.case "git_clone": { const { repositoryUrl, destination, openInVSCode: shouldOpenInVSCode = false } = args as { repositoryUrl: string; destination: string; openInVSCode?: boolean; }; const destPath = resolvePath(destination); await ensureDirectory(path.dirname(destPath)); await git.clone(repositoryUrl, destPath); if (shouldOpenInVSCode) { await openInVSCode(destPath); } return { content: [ { type: "text", text: `Successfully cloned ${repositoryUrl} to ${destPath}${shouldOpenInVSCode ? " and opened in VSCode" : ""}`, }, ], }; }
- src/index.ts:95-116 (schema)Tool schema definition including name, description, and input schema for git_clone, registered in the ListTools response.{ name: "git_clone", description: "Clone a git repository to a specified location", inputSchema: { type: "object", properties: { repositoryUrl: { type: "string", description: "Git repository URL", }, destination: { type: "string", description: "Destination path where to clone the repository", }, openInVSCode: { type: "boolean", description: "Open the cloned repository in VSCode (default: false)", }, }, required: ["repositoryUrl", "destination"], }, },
- src/index.ts:26-31 (helper)Helper function to resolve input paths, handling ~ expansion to home directory, used in git_clone handler.function resolvePath(inputPath: string): string { if (inputPath.startsWith("~")) { return path.join(os.homedir(), inputPath.slice(1)); } return path.resolve(inputPath); }
- src/index.ts:17-22 (helper)Helper function to ensure a directory exists, called in git_clone to create parent dir if needed.async function ensureDirectory(dirPath: string): Promise<void> { try { await fs.mkdir(dirPath, { recursive: true }); } catch (error) { console.error(`Error creating directory ${dirPath}:`, error); }
- src/index.ts:34-57 (helper)Helper function to open a project in VSCode, trying multiple executable paths, used optionally in git_clone.async function openInVSCode(projectPath: string): Promise<void> { try { await execa("code", [projectPath]); } catch (error) { // If 'code' command fails, try common VSCode executable paths const vscodePaths = [ "code", "/usr/local/bin/code", "/usr/bin/code", "C:\\Program Files\\Microsoft VS Code\\Code.exe", "C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe", ]; for (const codePath of vscodePaths) { try { await execa(codePath, [projectPath]); return; } catch { // Continue to next path } } throw new Error("VSCode not found. Please ensure VSCode is installed and 'code' command is available in PATH"); }