Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
pathNoPath to clone into. MUST be an absolute path (e.g., /Users/username/projects/my-repo)
urlYesURL of the repository to clone

Implementation Reference

  • 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
        }
      );
    }
  • 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;
    }
  • 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);
    }
  • 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'],
      },
    },
  • 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);
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Sheshiyer/git-mcp-v2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server