git_tag
Manage Git tags by creating annotated tags, listing existing tags, or deleting tags from your repository to mark release points and organize version history.
Instructions
Create, list, or delete tags
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Repository directory | |
| action | No | Tag action | list |
| name | No | Tag name (required for create/delete) | |
| message | No | Tag message (for annotated tags) | |
| commit | No | Commit to tag (defaults to HEAD) |
Implementation Reference
- src/tools/git.ts:424-451 (handler)Main handler function that implements git tag operations: list tags, create lightweight or annotated tags, delete tags using git commands.export async function gitTag(args: z.infer<typeof gitTagSchema>): Promise<ToolResponse> { switch (args.action) { case 'list': return executeGitCommand('git tag -l', args.cwd); case 'create': if (!args.name) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Tag name required for create action' }, null, 2) }], isError: true }; } const messageFlag = args.message ? `-a -m "${args.message}"` : ''; const commit = args.commit || ''; return executeGitCommand(`git tag ${messageFlag} ${args.name} ${commit}`.trim(), args.cwd); case 'delete': if (!args.name) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Tag name required for delete action' }, null, 2) }], isError: true }; } return executeGitCommand(`git tag -d ${args.name}`, args.cwd); default: return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Invalid tag action' }, null, 2) }], isError: true }; }
- src/tools/git.ts:189-195 (schema)Zod input schema for validating git_tag tool arguments.export const gitTagSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), action: z.enum(['list', 'create', 'delete']).optional().default('list').describe('Tag action'), name: z.string().optional().describe('Tag name (required for create/delete)'), message: z.string().optional().describe('Tag message (for annotated tags)'), commit: z.string().optional().describe('Commit to tag (defaults to HEAD)') });
- src/tools/git.ts:736-748 (registration)Tool definition/registration in the gitTools array exported for MCP server.name: 'git_tag', description: 'Create, list, or delete tags', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, action: { type: 'string', enum: ['list', 'create', 'delete'], default: 'list', description: 'Tag action' }, name: { type: 'string', description: 'Tag name (required for create/delete)' }, message: { type: 'string', description: 'Tag message (for annotated tags)' }, commit: { type: 'string', description: 'Commit to tag (defaults to HEAD)' } } } },
- src/index.ts:429-432 (registration)Dispatch handler in main MCP server that validates arguments and calls the gitTag handler for 'git_tag' tool invocations.if (name === 'git_tag') { const validated = gitTagSchema.parse(args); return await gitTag(validated); }
- src/tools/git.ts:21-61 (helper)Shared helper function used by all git tools to execute git commands with proper error handling and JSON response formatting.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 }; } }