git_archive
Create compressed archives (zip or tar) from Git repositories to package code for distribution, backup, or sharing.
Instructions
Create a git archive (zip or tar).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | The path to the local Git repository | |
| output_path | Yes | Output path for the archive | |
| format | No | Archive format (zip or tar) | zip |
| prefix | No | Prefix for files in the archive | |
| treeish | No | Tree-ish to archive (default: HEAD) | HEAD |
Implementation Reference
- src/handlers/other-operations.js:867-962 (handler)The core handler function implementing git archive creation using simpleGit to generate zip or tar archives from a repository tree-ish.export async function handleGitArchive({ repo_path, output_path, format = "zip", prefix = "", treeish = "HEAD", }) { try { const git = simpleGit(repo_path); // Validate format if (!["zip", "tar"].includes(format)) { return { content: [ { type: "text", text: JSON.stringify( { error: `Invalid archive format: ${format}. Use 'zip' or 'tar'.`, }, null, 2 ), }, ], isError: true, }; } // Build archive command const archiveArgs = ["archive", `--format=${format}`]; if (prefix) { archiveArgs.push(`--prefix=${prefix}/`); } archiveArgs.push("-o", output_path, treeish); // Create archive await git.raw(archiveArgs); // Check if archive was created if (!(await fs.pathExists(output_path))) { return { content: [ { type: "text", text: JSON.stringify( { error: "Failed to create archive: output file not found" }, null, 2 ), }, ], isError: true, }; } // Get file size const stats = await fs.stat(output_path); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Created ${format} archive at ${output_path}`, format: format, output_path: output_path, size_bytes: stats.size, treeish: treeish, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to create archive: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:622-653 (schema)The input schema definition for the git_archive tool, including parameters, types, descriptions, defaults, and required fields.name: "git_archive", description: "Create a git archive (zip or tar).", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, output_path: { type: "string", description: "Output path for the archive", }, format: { type: "string", description: "Archive format (zip or tar)", default: "zip", enum: ["zip", "tar"], }, prefix: { type: "string", description: "Prefix for files in the archive", }, treeish: { type: "string", description: "Tree-ish to archive (default: HEAD)", default: "HEAD", }, }, required: ["repo_path", "output_path"], }, },
- src/server.js:919-919 (registration)Registration of the git_archive tool handler in the central handlersMap used by the MCP server to route tool calls.git_archive: handleGitArchive,
- src/server.js:30-38 (registration)Import of the handleGitArchive handler function into the main server file.handleGitArchive, handleGitAttributes, handleGitBlame, handleGitClean, handleGitHooks, handleGitLFS, handleGitLFSFetch, handleGitRevert, } from "./handlers/index.js";
- src/handlers/index.js:79-86 (registration)Re-export of handleGitArchive from other-operations.js via the handlers index module for centralized access.handleGitArchive, handleGitAttributes, handleGitBlame, handleGitClean, handleGitHooks, handleGitLFS, handleGitLFSFetch, handleGitRevert,