Skip to main content
Glama
AbdurRaahimm

MCP Terminal & Git Server

by AbdurRaahimm

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
NameRequiredDescriptionDefault
repositoryUrlYesGit repository URL
destinationYesDestination path where to clone the repository
openInVSCodeNoOpen the cloned repository in VSCode (default: false)

Implementation Reference

  • 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" : ""}`,
          },
        ],
      };
    }
  • 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"],
      },
    },
  • 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);
    }
  • 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);
      }
  • 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");
      }

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/AbdurRaahimm/mcp-git-terminal-server'

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