Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

git_init

Initialize a new git repository in any directory to start tracking code changes and manage version control for your development projects.

Instructions

Initialize a new git repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdNoDirectory to initialize as git repository
bareNoCreate bare repository

Implementation Reference

  • The handler function that executes the 'git init' command, constructing the command with optional --bare flag and calling the shared executeGitCommand helper.
    export async function gitInit(args: z.infer<typeof gitInitSchema>): Promise<ToolResponse> {
      const bareFlag = args.bare ? '--bare' : '';
      return executeGitCommand(`git init ${bareFlag}`.trim(), args.cwd);
    }
  • Zod schema defining the input parameters for the gitInit handler: optional cwd and bare boolean.
    export const gitInitSchema = z.object({
      cwd: z.string().optional().describe('Directory to initialize as git repository'),
      bare: z.boolean().optional().default(false).describe('Create bare repository')
    });
  • MCP tool registration object within gitTools array, defining name, description, and JSON schema for 'git_init'.
    {
      name: 'git_init',
      description: 'Initialize a new git repository',
      inputSchema: {
        type: 'object',
        properties: {
          cwd: { type: 'string', description: 'Directory to initialize as git repository' },
          bare: { type: 'boolean', default: false, description: 'Create bare repository' }
        }
      }
    },
  • src/index.ts:397-400 (registration)
    Dispatch logic in main MCP server handler that matches tool name 'git_init', validates args with gitInitSchema, and calls gitInit function.
    if (name === 'git_init') {
      const validated = gitInitSchema.parse(args);
      return await gitInit(validated);
    }
  • Shared helper function used by all git tools, including gitInit, to execute git commands via child_process.exec and format ToolResponse.
    async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> {
      try {
        const { stdout, stderr } = await execAsync(command, {
          cwd: cwd || process.cwd(),
          shell: '/bin/bash',
          maxBuffer: 10 * 1024 * 1024 // 10MB buffer
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({
                success: true,
                command: command,
                stdout: stdout.trim(),
                stderr: stderr.trim(),
                cwd: cwd || process.cwd()
              }, null, 2)
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({
                success: false,
                command: command,
                stdout: error.stdout?.trim() || '',
                stderr: error.stderr?.trim() || error.message,
                exitCode: error.code || 1,
                cwd: cwd || process.cwd()
              }, null, 2)
            }
          ],
          isError: true
        };
      }
    }

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/ConnorBoetig-dev/mcp2'

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