Skip to main content
Glama

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
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
output_pathYesOutput path for the archive
formatNoArchive format (zip or tar)zip
prefixNoPrefix for files in the archive
treeishNoTree-ish to archive (default: HEAD)HEAD

Implementation Reference

  • 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, }; } }
  • 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";
  • Re-export of handleGitArchive from other-operations.js via the handlers index module for centralized access.
    handleGitArchive, handleGitAttributes, handleGitBlame, handleGitClean, handleGitHooks, handleGitLFS, handleGitLFSFetch, handleGitRevert,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bsreeram08/git-commands-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server