Skip to main content
Glama

push_files

Push multiple files to a GitHub repository in a single commit by providing owner, repo, branch, an array of file objects with path and content, and a commit message.

Instructions

Push multiple files to a GitHub repository in a single commit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesRepository owner
repoYesRepository name
branchYesBranch to push to
filesYesArray of file objects to push, each object with path (string) and content (string)
messageYesCommit message

Implementation Reference

  • Registration of the 'push_files' tool on the MCP server, defining its name, description, input schema, and async handler.
    // Tool: Push Files
    server.tool(
    	"push_files",
    	"Push multiple files to a GitHub repository in a single commit",
    	{
    		owner: z.string().describe("Repository owner"),
    		repo: z.string().describe("Repository name"),
    		branch: z.string().describe("Branch to push to"),
    		files: z
    			.array(z.object({ path: z.string(), content: z.string() }))
    			.describe(
    				"Array of file objects to push, each object with path (string) and content (string)",
    			),
    		message: z.string().describe("Commit message"),
    	},
    	async ({ owner, repo, branch, files, message }) => {
    		try {
    			// Get the reference for the branch
    			const refResp = await octokit.rest.git.getRef({
    				owner,
    				repo,
    				ref: `heads/${branch}`,
    			})
    			const baseSha = refResp.data.object.sha
    
    			// Get the commit object that the branch points to
    			const baseCommit = await octokit.rest.git.getCommit({
    				owner,
    				repo,
    				commit_sha: baseSha,
    			})
    
    			// Create tree entries for all files
    			const treeItems = files.map(file => ({
    				path: file.path,
    				mode: "100644" as const, // Regular file mode
    				type: "blob" as const,
    				content: file.content,
    			}))
    
    			// Create a new tree with the file entries
    			const newTree = await octokit.rest.git.createTree({
    				owner,
    				repo,
    				base_tree: baseCommit.data.tree.sha,
    				tree: treeItems,
    			})
    
    			// Create a new commit
    			const newCommit = await octokit.rest.git.createCommit({
    				owner,
    				repo,
    				message,
    				tree: newTree.data.sha,
    				parents: [baseSha],
    			})
    
    			// Update the reference to point to the new commit
    			const updatedRef = await octokit.rest.git.updateRef({
    				owner,
    				repo,
    				ref: `heads/${branch}`,
    				sha: newCommit.data.sha,
    				force: false,
    			})
    
    			return {
    				content: [{ type: "text", text: `Files pushed successfully to **${owner}/${repo}** branch \`${branch}\`\nCommit SHA: ${newCommit.data.sha}\nMessage: ${message}\nFiles: ${files.map((f: any) => f.path).join(", ")}` }],
    			}
    		} catch (e: any) {
    			return {
    				content: [{ type: "text", text: `Error: ${e.message}` }],
    			}
    		}
    	},
    )
  • Handler function for 'push_files' that pushes multiple files to a GitHub repository: gets branch ref, creates tree entries, creates a commit, and updates the branch ref.
    	async ({ owner, repo, branch, files, message }) => {
    		try {
    			// Get the reference for the branch
    			const refResp = await octokit.rest.git.getRef({
    				owner,
    				repo,
    				ref: `heads/${branch}`,
    			})
    			const baseSha = refResp.data.object.sha
    
    			// Get the commit object that the branch points to
    			const baseCommit = await octokit.rest.git.getCommit({
    				owner,
    				repo,
    				commit_sha: baseSha,
    			})
    
    			// Create tree entries for all files
    			const treeItems = files.map(file => ({
    				path: file.path,
    				mode: "100644" as const, // Regular file mode
    				type: "blob" as const,
    				content: file.content,
    			}))
    
    			// Create a new tree with the file entries
    			const newTree = await octokit.rest.git.createTree({
    				owner,
    				repo,
    				base_tree: baseCommit.data.tree.sha,
    				tree: treeItems,
    			})
    
    			// Create a new commit
    			const newCommit = await octokit.rest.git.createCommit({
    				owner,
    				repo,
    				message,
    				tree: newTree.data.sha,
    				parents: [baseSha],
    			})
    
    			// Update the reference to point to the new commit
    			const updatedRef = await octokit.rest.git.updateRef({
    				owner,
    				repo,
    				ref: `heads/${branch}`,
    				sha: newCommit.data.sha,
    				force: false,
    			})
    
    			return {
    				content: [{ type: "text", text: `Files pushed successfully to **${owner}/${repo}** branch \`${branch}\`\nCommit SHA: ${newCommit.data.sha}\nMessage: ${message}\nFiles: ${files.map((f: any) => f.path).join(", ")}` }],
    			}
    		} catch (e: any) {
    			return {
    				content: [{ type: "text", text: `Error: ${e.message}` }],
    			}
    		}
    	},
    )
  • Input schema for 'push_files': owner (string), repo (string), branch (string), files (array of {path, content} objects), and message (string).
    {
    	owner: z.string().describe("Repository owner"),
    	repo: z.string().describe("Repository name"),
    	branch: z.string().describe("Branch to push to"),
    	files: z
    		.array(z.object({ path: z.string(), content: z.string() }))
    		.describe(
    			"Array of file objects to push, each object with path (string) and content (string)",
    		),
    	message: z.string().describe("Commit message"),
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must fully disclose behavior. It uses 'push' ambiguously without confirming whether it creates a commit or directly pushes, nor does it mention atomicity, overwriting behavior, or required permissions. This vagueness is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The single sentence is concise but excessively terse, lacking necessary detail. While it avoids verbosity, it sacrifices completeness for brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the absence of annotations and output schema, and the tool's complexity (5 required parameters), the description fails to cover critical aspects like error conditions, file overwrite behavior, or commit details. It is insufficient for an agent to use confidently.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with each parameter described adequately. The description adds no extra meaning beyond 'multiple files' which is already implied by the array type. Baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states it pushes multiple files to a GitHub repository in a single commit. It clearly distinguishes from sibling tools like create_or_update_file which handle single files, making the purpose specific and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for pushing multiple files in one commit but does not explicitly contrast with single-file alternatives (e.g., create_or_update_file) or mention conditions like branch existence. No when-to-use or when-not-to-use guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/hithereiamaliff/mcp-github'

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