git_remote
Manage Git remote repositories by listing, adding, removing, or showing remote connections to control version control collaboration and repository links.
Instructions
Manage remote repositories
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Repository directory | |
| action | No | Remote action | list |
| name | No | Remote name (required for add/remove/show) | |
| url | No | Remote URL (required for add) |
Implementation Reference
- src/tools/git.ts:349-382 (handler)The main handler function for the 'git_remote' tool. Executes git remote commands (list, add, remove, show) using the shared executeGitCommand helper, with input validation via gitRemoteSchema.export async function gitRemote(args: z.infer<typeof gitRemoteSchema>): Promise<ToolResponse> { switch (args.action) { case 'list': return executeGitCommand('git remote -v', args.cwd); case 'add': if (!args.name || !args.url) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Name and URL required for add action' }, null, 2) }], isError: true }; } return executeGitCommand(`git remote add ${args.name} ${args.url}`, args.cwd); case 'remove': if (!args.name) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Name required for remove action' }, null, 2) }], isError: true }; } return executeGitCommand(`git remote remove ${args.name}`, args.cwd); case 'show': if (!args.name) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Name required for show action' }, null, 2) }], isError: true }; } return executeGitCommand(`git remote show ${args.name}`, args.cwd); default: return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Invalid remote action' }, null, 2) }], isError: true }; }
- src/tools/git.ts:162-167 (schema)Zod schema for validating inputs to the git_remote tool, used in the dispatch handler in index.ts.export const gitRemoteSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), action: z.enum(['list', 'add', 'remove', 'show']).optional().default('list').describe('Remote action'), name: z.string().optional().describe('Remote name (required for add/remove/show)'), url: z.string().optional().describe('Remote URL (required for add)') });
- src/index.ts:413-416 (registration)Dispatch registration in the main MCP server handler. Matches tool name, validates args with schema, and calls the gitRemote handler.if (name === 'git_remote') { const validated = gitRemoteSchema.parse(args); return await gitRemote(validated); }
- src/tools/git.ts:683-694 (schema)MCP tool definition in gitTools array, including inputSchema for tool listing. Mirrors the Zod schema.{ name: 'git_remote', description: 'Manage remote repositories', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, action: { type: 'string', enum: ['list', 'add', 'remove', 'show'], default: 'list', description: 'Remote action' }, name: { type: 'string', description: 'Remote name (required for add/remove/show)' }, url: { type: 'string', description: 'Remote URL (required for add)' } } }
- src/tools/git.ts:21-60 (helper)Shared helper function used by all git tools, including gitRemote, to execute git commands and format responses.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 }; }