Skip to main content
Glama

add

Stage files in a Git repository by specifying absolute paths. Integrates with the Git MCP Server to enhance AI-assisted Git operations for efficient version control.

Instructions

Stage files

Input Schema

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

Implementation Reference

  • The primary handler function for the 'add' tool. It validates the repository path, executes 'git add' for each specified file, invalidates relevant caches, and returns a success message.
    static async add({ path, files }: AddOptions, context: GitToolContext): Promise<GitToolResult> {
      const resolvedPath = this.getPath({ path });
      return await this.executeOperation(
        context.operation,
        resolvedPath,
        async () => {
          const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath);
          
          // Handle each file individually to avoid path issues
          for (const file of files) {
            await CommandExecutor.executeGitCommand(
              `add "${file}"`,
              context.operation,
              repoPath
            );
          }
    
          return {
            content: [{
              type: 'text',
              text: 'Files staged successfully'
            }]
          };
        },
        {
          command: 'add',
          invalidateCache: true, // Invalidate status cache
          stateType: RepoStateType.STATUS
        }
      );
    }
  • Registers the 'add' tool with MCP server, including its name, description, and input schema for tool listing.
    {
      name: 'add',
      description: 'Stage files',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: `Path to repository. ${PATH_DESCRIPTION}`,
          },
          files: {
            type: 'array',
            items: {
              type: 'string',
              description: FILE_PATH_DESCRIPTION,
            },
            description: 'Files to stage',
          },
        },
        required: ['files'],
      },
    },
  • TypeScript interface defining the input parameters for the 'add' tool.
    export interface AddOptions extends GitOptions, BasePathOptions {
      /**
       * Array of absolute paths to files to stage
       * Example: /Users/username/projects/my-repo/src/file.js
       */
      files: string[];
    }
  • Type guard function used to validate arguments for the 'add' tool before execution.
    export function isAddOptions(obj: any): obj is AddOptions {
      return obj && 
        validatePath(obj.path) && 
        Array.isArray(obj.files) &&
        obj.files.every((f: any) => typeof f === 'string' && isAbsolutePath(f));
    }
  • Dispatch handler in the tool executor that validates arguments and delegates to GitOperations.add.
    case 'add': {
      const validArgs = this.validateArguments(operation, args, isAddOptions);
      return await GitOperations.add(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