Skip to main content
Glama

git_lfs

Manage Git Large File Storage (LFS) by installing, tracking, untracking, or listing large files in Git repositories to handle binary assets efficiently.

Instructions

Manage Git LFS (Large File Storage).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
actionYesLFS action (install, track, untrack, list)list
patternsNoFile patterns for track/untrack

Implementation Reference

  • Main handler function that executes the git_lfs tool logic. Handles actions: install, track, untrack, list for Git LFS.
    export async function handleGitLFS({ repo_path, action, patterns = [] }) { try { // Make sure patterns is an array const patternsArray = Array.isArray(patterns) ? patterns : [patterns]; switch (action) { case "install": // Install Git LFS in the repository const { stdout: installOutput } = await execPromise( `cd "${repo_path}" && git lfs install` ); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: "Git LFS installed successfully", output: installOutput.trim(), }, null, 2 ), }, ], }; case "track": if (patternsArray.length === 0) { return { content: [ { type: "text", text: JSON.stringify( { error: "At least one pattern is required for track action", }, null, 2 ), }, ], isError: true, }; } // Track files with LFS const trackResults = []; for (const pattern of patternsArray) { const { stdout: trackOutput } = await execPromise( `cd "${repo_path}" && git lfs track "${pattern}"` ); trackResults.push({ pattern: pattern, output: trackOutput.trim(), }); } return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Tracked ${patternsArray.length} pattern(s) with Git LFS`, patterns: patternsArray, results: trackResults, }, null, 2 ), }, ], }; case "untrack": if (patternsArray.length === 0) { return { content: [ { type: "text", text: JSON.stringify( { error: "At least one pattern is required for untrack action", }, null, 2 ), }, ], isError: true, }; } // Untrack files from LFS const untrackResults = []; for (const pattern of patternsArray) { const { stdout: untrackOutput } = await execPromise( `cd "${repo_path}" && git lfs untrack "${pattern}"` ); untrackResults.push({ pattern: pattern, output: untrackOutput.trim(), }); } return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Untracked ${patternsArray.length} pattern(s) from Git LFS`, patterns: patternsArray, results: untrackResults, }, null, 2 ), }, ], }; case "list": // List tracked patterns const { stdout: listOutput } = await execPromise( `cd "${repo_path}" && git lfs track` ); // Parse the output to extract patterns const trackedPatterns = listOutput .split("\n") .filter((line) => line.includes("(")) .map((line) => { const match = line.match(/Tracking "([^"]+)"/); return match ? match[1] : null; }) .filter(Boolean); return { content: [ { type: "text", text: JSON.stringify( { success: true, tracked_patterns: trackedPatterns, }, null, 2 ), }, ], }; default: return { content: [ { type: "text", text: JSON.stringify( { error: `Unknown LFS action: ${action}` }, null, 2 ), }, ], isError: true, }; } } catch (error) { // Special handling for "git lfs not installed" error if (error.message.includes("git: lfs is not a git command")) { return { content: [ { type: "text", text: JSON.stringify( { error: "Git LFS is not installed on the system" }, null, 2 ), }, ], isError: true, }; } return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to perform LFS operation: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
  • Input schema definition and tool metadata for the git_lfs tool used in MCP tool listing.
    { name: "git_lfs", description: "Manage Git LFS (Large File Storage).", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, action: { type: "string", description: "LFS action (install, track, untrack, list)", default: "list", enum: ["install", "track", "untrack", "list"], }, patterns: { type: "array", description: "File patterns for track/untrack", items: { type: "string" }, }, }, required: ["repo_path", "action"], }, },
  • src/server.js:924-925 (registration)
    Maps the 'git_lfs' tool name to its handler function handleGitLFS in the server's handlersMap.
    git_lfs: handleGitLFS, git_lfs_fetch: handleGitLFSFetch,
  • src/server.js:35-38 (registration)
    Imports the handleGitLFS handler into the server module.
    handleGitLFS, handleGitLFSFetch, handleGitRevert, } from "./handlers/index.js";
  • Re-exports the handleGitLFS function from other-operations.js for use in server.js.
    handleGitLFS, handleGitLFSFetch, handleGitRevert, } from "./other-operations.js";

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