Skip to main content
Glama

git_archive

Generate a Git repository archive in zip or tar format by specifying the repository path, output path, and optional parameters like prefix and tree-ish.

Instructions

Create a git archive (zip or tar).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoArchive format (zip or tar)zip
output_pathYesOutput path for the archive
prefixNoPrefix for files in the archive
repo_pathYesThe path to the local Git repository
treeishNoTree-ish to archive (default: HEAD)HEAD

Implementation Reference

  • Core handler function that executes git archive command to create zip or tar files from the repository.
    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, }; } }
  • Input schema definition and tool metadata for git_archive in the MCP tools list.
    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:898-928 (registration)
    Maps the 'git_archive' tool name to its handler function handleGitArchive in the server's handler lookup object.
    this.handlersMap = { // Primary handlers git_directory_structure: handleGitDirectoryStructure, git_read_files: handleGitReadFiles, git_branch_diff: handleGitBranchDiff, git_commit_history: handleGitCommitHistory, git_commits_details: handleGitCommitsDetails, git_local_changes: handleGitLocalChanges, git_search_code: handleGitSearchCode, git_commit: handleGitCommit, git_track: handleGitTrack, git_checkout_branch: handleGitCheckoutBranch, git_delete_branch: handleGitDeleteBranch, git_merge_branch: handleGitMergeBranch, git_push: handleGitPush, git_pull: handleGitPull, git_stash: handleGitStash, git_create_tag: handleGitCreateTag, git_rebase: handleGitRebase, git_config: handleGitConfig, git_reset: handleGitReset, git_archive: handleGitArchive, git_attributes: handleGitAttributes, git_blame: handleGitBlame, git_clean: handleGitClean, git_hooks: handleGitHooks, git_lfs: handleGitLFS, git_lfs_fetch: handleGitLFSFetch, git_revert: handleGitRevert, };
  • Imports the handleGitArchive handler from its implementation file.
    import { handleGitArchive, handleGitAttributes, handleGitBlame, handleGitClean, handleGitHooks, handleGitLFS, handleGitLFSFetch, handleGitRevert, } from "./other-operations.js";
  • Re-exports the handleGitArchive handler for use by server.js.
    handleGitArchive, handleGitAttributes, handleGitBlame, handleGitClean, handleGitHooks, handleGitLFS, handleGitLFSFetch, handleGitRevert, } from "./other-operations.js"; // Re-export all handlers export { // Directory operations handleGitDirectoryStructure, handleGitReadFiles, handleGitSearchCode, handleGitLocalChanges, // Commit operations handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack, // Branch operations handleGitBranchDiff, handleGitCheckoutBranch, handleGitDeleteBranch, handleGitMergeBranch, // Remote operations handleGitPush, handleGitPull, handleGitRemote, // Stash operations handleGitStash, // Tag operations handleGitCreateTag, // Advanced operations handleGitRebase, handleGitReset, // Config operations handleGitConfig, // Other operations

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