Skip to main content
Glama

init

Initialize a new Git repository by specifying an absolute path for setup, enabling enhanced Git operations via the Git MCP Server for streamlined version control.

Instructions

Initialize a new Git repository

Input Schema

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

Implementation Reference

  • Primary handler for the 'init' tool. Validates path, executes 'git init' command, handles caching/invalidation, error handling, and returns formatted result.
    static async init(options: InitOptions, 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(
            'init',
            context.operation,
            pathInfo
          );
    
          return {
            content: [{
              type: 'text',
              text: `Repository initialized successfully\n${CommandExecutor.formatOutput(result)}`
            }]
          };
        },
        {
          command: 'init',
          invalidateCache: true // Invalidate all caches for this repo
        }
      );
    }
  • Registers the 'init' tool with the MCP server in ListTools handler, defining name, description, and JSON input schema.
    {
      name: 'init',
      description: 'Initialize a new Git repository',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: `Path to initialize the repository in. ${PATH_DESCRIPTION}`,
          },
        },
        required: [],
      },
  • Registers and dispatches 'init' tool calls in the CallTool handler by validating arguments and invoking GitOperations.init.
    case 'init': {
      const validArgs = this.validateArguments(operation, args, isInitOptions);
      return await GitOperations.init(validArgs, context);
    }
  • TypeScript interface defining input parameters for the 'init' tool.
    export interface InitOptions extends GitOptions, BasePathOptions {}
  • Type guard function for validating 'init' tool input arguments.
    export function isInitOptions(obj: any): obj is InitOptions {
      return obj && validatePath(obj.path);
    }
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