git_fetch
Download objects and refs from remote Git repositories to update your local copy with changes from team members or upstream sources.
Instructions
Download objects and refs from remote repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Repository directory | |
| remote | No | Remote name | origin |
| prune | No | Remove deleted remote branches |
Implementation Reference
- src/tools/git.ts:344-347 (handler)The main handler function that executes the git fetch command by calling the shared executeGitCommand helper with constructed git fetch arguments.export async function gitFetch(args: z.infer<typeof gitFetchSchema>): Promise<ToolResponse> { const pruneFlag = args.prune ? '--prune' : ''; return executeGitCommand(`git fetch ${pruneFlag} ${args.remote}`.trim(), args.cwd); }
- src/tools/git.ts:156-160 (schema)Zod schema used for input validation of the git_fetch tool parameters in the dispatcher.export const gitFetchSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), remote: z.string().optional().default('origin').describe('Remote name'), prune: z.boolean().optional().default(false).describe('Remove deleted remote branches') });
- src/tools/git.ts:671-682 (registration)MCP protocol tool registration definition for git_fetch, including name, description, and JSON schema for tool listing.{ name: 'git_fetch', description: 'Download objects and refs from remote repository', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, remote: { type: 'string', default: 'origin', description: 'Remote name' }, prune: { type: 'boolean', default: false, description: 'Remove deleted remote branches' } } } },
- src/index.ts:409-411 (registration)Server request handler dispatcher that routes 'git_fetch' tool calls by parsing arguments with schema and invoking the gitFetch handler.if (name === 'git_fetch') { const validated = gitFetchSchema.parse(args); return await gitFetch(validated);
- src/tools/git.ts:21-61 (helper)Core helper function that executes any git command via child_process.execAsync, handles errors, and returns standardized ToolResponse format used by all git tools including gitFetch.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 }; } }