clone
Clone a Git repository from a specified URL to a specific local path using the Git MCP Server's enhanced capabilities. Ideal for initializing projects or managing codebases programmatically.
Instructions
Clone a repository
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path to clone into. MUST be an absolute path (e.g., /Users/username/projects/my-repo) | |
| url | Yes | URL of the repository to clone |
Input Schema (JSON Schema)
{
"properties": {
"path": {
"description": "Path to clone into. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
"type": "string"
},
"url": {
"description": "URL of the repository to clone",
"type": "string"
}
},
"required": [
"url"
],
"type": "object"
}
Implementation Reference
- src/git-operations.ts:125-149 (handler)The main handler function in GitOperations class that validates the path, executes the 'git clone' command via CommandExecutor, handles caching and errors, and returns the formatted result.static async clone(options: CloneOptions, 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( `clone ${options.url} ${pathInfo}`, context.operation ); return { content: [{ type: 'text', text: `Repository cloned successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'clone', invalidateCache: true // Invalidate all caches for this repo } ); }
- src/types.ts:47-52 (schema)Type definition for CloneOptions interface, defining the input parameters including required 'url' and optional 'path'.export interface CloneOptions extends GitOptions, BasePathOptions { /** * URL of the repository to clone */ url: string; }
- src/types.ts:145-149 (schema)Type guard function to validate if an object conforms to CloneOptions.export function isCloneOptions(obj: any): obj is CloneOptions { return obj && typeof obj.url === 'string' && validatePath(obj.path); }
- src/tool-handler.ts:84-101 (registration)Tool registration in the ListTools handler, defining the 'clone' tool name, description, and input schema.{ name: 'clone', description: 'Clone a repository', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL of the repository to clone', }, path: { type: 'string', description: `Path to clone into. ${PATH_DESCRIPTION}`, }, }, required: ['url'], }, },
- src/tool-handler.ts:573-576 (registration)Dispatch logic in the CallTool handler switch statement that validates arguments using isCloneOptions and calls the GitOperations.clone handler.case 'clone': { const validArgs = this.validateArguments(operation, args, isCloneOptions); return await GitOperations.clone(validArgs, context); }