remote_add
Enable AI assistants to add a Git remote by specifying the repository path, remote name, and URL for enhanced repository management via the Git MCP Server.
Instructions
Add a remote
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Remote name | |
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) | |
| url | Yes | Remote URL |
Input Schema (JSON Schema)
{
"properties": {
"name": {
"description": "Remote name",
"type": "string"
},
"path": {
"description": "Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)",
"type": "string"
},
"url": {
"description": "Remote URL",
"type": "string"
}
},
"required": [
"name",
"url"
],
"type": "object"
}
Implementation Reference
- src/git-operations.ts:625-660 (handler)The primary handler function in GitOperations class that executes the 'git remote add' command. It validates the repository path, remote name, and URL, runs the git command via CommandExecutor, handles caching invalidation, and formats the success response.static async remoteAdd({ path, name, url }: RemoteOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); PathValidator.validateRemoteName(name); if (!url) { throw ErrorHandler.handleValidationError( new Error('URL is required when adding a remote'), { operation: context.operation, path: repoPath } ); } PathValidator.validateRemoteUrl(url); const result = await CommandExecutor.executeGitCommand( `remote add ${name} ${url}`, context.operation, repoPath ); return { content: [{ type: 'text', text: `Remote '${name}' added successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'remote_add', invalidateCache: true, // Invalidate remote cache stateType: RepoStateType.REMOTE } ); }
- src/tool-handler.ts:643-646 (registration)Registration and dispatch logic in ToolHandler's CallToolRequest handler switch statement. Validates arguments using isRemoteOptions type guard and delegates to GitOperations.remoteAdd.case 'remote_add': { const validArgs = this.validateArguments(operation, args, isRemoteOptions); return await GitOperations.remoteAdd(validArgs, context); }
- src/tool-handler.ts:384-403 (schema)JSON schema definition for the 'remote_add' tool provided to MCP clients via ListToolsRequest. Specifies input parameters: path (optional), name and url (required).name: 'remote_add', description: 'Add a remote', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, name: { type: 'string', description: 'Remote name', }, url: { type: 'string', description: 'Remote URL', }, }, required: ['name', 'url'], },