push_files
Push multiple files to a GitHub repository in a single commit, simplifying batch file uploads and version control management.
Instructions
Push multiple files to a GitHub repository in a single commit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner (username or organization) | |
| repo | Yes | Repository name | |
| branch | Yes | Branch to push to (e.g., 'main' or 'master') | |
| files | Yes | Array of files to push | |
| message | Yes | Commit message |
Implementation Reference
- src/operations/files.ts:222-241 (handler)The core handler function implementing the push_files tool logic, which creates a new Git tree, commit, and updates the branch reference on GitHub.export async function pushFiles( github_pat: string, owner: string, repo: string, branch: string, files: FileOperation[], message: string ) { const refResponse = await githubRequest( github_pat, `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/${branch}` ); const ref = GitHubReferenceSchema.parse(refResponse); const commitSha = ref.object.sha; const tree = await createTree(github_pat, owner, repo, files, commitSha); const commit = await createCommit(github_pat, owner, repo, message, tree.sha, [commitSha]); return await updateReference(github_pat, owner, repo, `heads/${branch}`, commit.sha); }
- src/operations/files.ts:44-50 (schema)Zod schema defining the public input parameters for the push_files tool.export const PushFilesSchema = z.object({ owner: z.string().describe("Repository owner (username or organization)"), repo: z.string().describe("Repository name"), branch: z.string().describe("Branch to push to (e.g., 'main' or 'master')"), files: z.array(FileOperationSchema).describe("Array of files to push"), message: z.string().describe("Commit message"), });
- src/index.ts:98-102 (registration)Tool registration in the MCP server's listTools response, specifying name, description, and input schema.{ name: "push_files", description: "Push multiple files to a GitHub repository in a single commit", inputSchema: zodToJsonSchema(files.PushFilesSchema), },
- src/index.ts:422-435 (handler)Top-level dispatch handler in the MCP CallToolRequestSchema that validates arguments with internal schema and invokes the pushFiles function.case "push_files": { const args = files._PushFilesSchema.parse(params.arguments); const result = await files.pushFiles( args.github_pat, args.owner, args.repo, args.branch, args.files, args.message ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }
- src/operations/files.ts:13-16 (helper)Helper schema for individual file operations used within PushFilesSchema's 'files' array.export const FileOperationSchema = z.object({ path: z.string(), content: z.string(), });