git-remote
Manage Git remote repositories by adding, removing, renaming, displaying, updating URLs, and pruning stale references to organize your project's remote connections.
Instructions
Git remote management tool for managing remote repositories. Supports add, remove, rename, show, set-url, and prune operations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | The remote operation to perform | |
| all | No | Show all remotes (for show action) | |
| dryRun | No | Show what would be pruned without actually pruning (for prune action) | |
| fetch | No | Fetch after adding remote (for add action) | |
| name | No | Remote name (required for most operations) | |
| newName | No | New remote name (required for rename operation) | |
| projectPath | Yes | Absolute path to the project directory | |
| push | No | Set push URL instead of fetch URL (for set-url action) | |
| url | No | Remote URL (required for add and set-url operations) | |
| verbose | No | Show verbose output with URLs (for show action) |
Implementation Reference
- src/tools/git-remote.ts:41-117 (handler)Main handler function of GitRemoteTool class that validates parameters, checks Git repository, and routes to specific operation handlers (add, remove, rename, show, set-url, prune, list).async execute(params: GitRemoteParams): Promise<ToolResult> { const startTime = Date.now(); try { // Validate basic parameters const validation = ParameterValidator.validateToolParams('git-remote', params); if (!validation.isValid) { return OperationErrorHandler.createToolError( 'VALIDATION_ERROR', `Parameter validation failed: ${validation.errors.join(', ')}`, params.action, { validationErrors: validation.errors }, validation.suggestions ); } // Validate operation-specific parameters const operationValidation = this.validateOperationParams(params); if (!operationValidation.isValid) { return OperationErrorHandler.createToolError( 'VALIDATION_ERROR', `Operation validation failed: ${operationValidation.errors.join(', ')}`, params.action, { validationErrors: operationValidation.errors }, operationValidation.suggestions ); } // Check if it's a Git repository const isRepo = await this.gitExecutor.isGitRepository(params.projectPath); if (!isRepo) { return OperationErrorHandler.createToolError( 'NOT_A_GIT_REPOSITORY', 'The specified path is not a Git repository', params.action, { projectPath: params.projectPath }, ['Initialize a Git repository first with: git init'] ); } // Route to appropriate handler switch (params.action) { case 'add': return await this.handleAdd(params, startTime); case 'remove': return await this.handleRemove(params, startTime); case 'rename': return await this.handleRename(params, startTime); case 'show': return await this.handleShow(params, startTime); case 'set-url': return await this.handleSetUrl(params, startTime); case 'prune': return await this.handlePrune(params, startTime); case 'list': return await this.handleList(params, startTime); default: return OperationErrorHandler.createToolError( 'UNSUPPORTED_OPERATION', `Operation '${params.action}' is not supported`, params.action, {}, ['Use one of: add, remove, rename, show, set-url, prune, list'] ); } } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; return OperationErrorHandler.createToolError( 'EXECUTION_ERROR', `Failed to execute ${params.action}: ${errorMessage}`, params.action, { error: errorMessage }, ['Check the error details and try again'] ); } }
- src/tools/git-remote.ts:655-707 (schema)Static method providing the complete tool schema for MCP protocol registration, including name, description, and detailed input schema with all parameters and enums.static getToolSchema() { return { name: 'git-remote', description: 'Git remote management tool for managing remote repositories. Supports add, remove, rename, show, set-url, and prune operations.', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['add', 'remove', 'rename', 'show', 'set-url', 'prune', 'list'], description: 'The remote operation to perform' }, projectPath: { type: 'string', description: 'Absolute path to the project directory' }, name: { type: 'string', description: 'Remote name (required for most operations)' }, url: { type: 'string', description: 'Remote URL (required for add and set-url operations)' }, newName: { type: 'string', description: 'New remote name (required for rename operation)' }, fetch: { type: 'boolean', description: 'Fetch after adding remote (for add action)' }, push: { type: 'boolean', description: 'Set push URL instead of fetch URL (for set-url action)' }, all: { type: 'boolean', description: 'Show all remotes (for show action)' }, verbose: { type: 'boolean', description: 'Show verbose output with URLs (for show action)' }, dryRun: { type: 'boolean', description: 'Show what would be pruned without actually pruning (for prune action)' } }, required: ['action', 'projectPath'] } }; }
- src/server.ts:123-132 (registration)Tool registration in MCP server's ListToolsRequestSchema handler, where GitRemoteTool.getToolSchema() is included in the returned list of available tools.return { tools: [ GitWorkflowTool.getToolSchema(), GitFilesTool.getToolSchema(), GitBranchesTool.getToolSchema(), GitIssuesTool.getToolSchema(), GitPullsTool.getToolSchema(), GitTagsTool.getToolSchema(), GitReleaseTool.getToolSchema(), GitRemoteTool.getToolSchema(),
- src/server.ts:484-485 (registration)Execution dispatch in the server's CallToolRequestSchema handler switch statement, routing 'git-remote' calls to the tool instance's execute method.case 'git-remote': return await this.gitRemoteTool.execute(args);
- src/tools/git-remote.ts:122-184 (helper)Operation-specific parameter validation helper method used by the main handler to ensure required parameters for each git-remote action.private validateOperationParams(params: GitRemoteParams): { isValid: boolean; errors: string[]; suggestions: string[] } { const errors: string[] = []; const suggestions: string[] = []; switch (params.action) { case 'add': if (!params.name) { errors.push('Remote name is required for add operation'); suggestions.push('Provide a remote name (e.g., "origin", "upstream")'); } if (!params.url) { errors.push('Remote URL is required for add operation'); suggestions.push('Provide a remote URL (e.g., "https://github.com/user/repo.git")'); } break; case 'remove': if (!params.name) { errors.push('Remote name is required for remove operation'); suggestions.push('Provide the name of the remote to remove'); } break; case 'rename': if (!params.name) { errors.push('Current remote name is required for rename operation'); suggestions.push('Provide the current remote name'); } if (!params.newName) { errors.push('New remote name is required for rename operation'); suggestions.push('Provide the new remote name'); } break; case 'set-url': if (!params.name) { errors.push('Remote name is required for set-url operation'); suggestions.push('Provide the remote name to update'); } if (!params.url) { errors.push('Remote URL is required for set-url operation'); suggestions.push('Provide the new remote URL'); } break; case 'prune': if (!params.name) { errors.push('Remote name is required for prune operation'); suggestions.push('Provide the remote name to prune (e.g., "origin")'); } break; case 'show': // Show operation can work without parameters (shows all remotes) break; } return { isValid: errors.length === 0, errors, suggestions }; }