push_files_content
Push multiple files with direct content to a GitHub repository in a single commit, enabling batch file updates without local file management.
Instructions
Push multiple files with direct content 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 with their content | |
| message | Yes | Commit message |
Implementation Reference
- operations/files.ts:217-234 (handler)Core handler function that implements the logic to push multiple files' content to GitHub repo by creating a Git tree, commit, and updating the branch reference.export async function pushFilesContent( owner: string, repo: string, branch: string, files: FileContent[], message: string ) { const refResponse = await githubRequest( `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(owner, repo, files, commitSha); const commit = await createCommit(owner, repo, message, tree.sha, [commitSha]); return await updateReference(owner, repo, `heads/${branch}`, commit.sha); }
- operations/files.ts:41-47 (schema)Zod input schema defining parameters for the push_files_content tool: owner, repo, branch, files array, and commit message.export const PushFilesContentSchema = 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(FileContentSchema).describe("Array of files to push with their content"), message: z.string().describe("Commit message"), });
- index.ts:88-92 (registration)Registration of the push_files_content tool in the MCP server tools list, specifying name, description, and schema.{ name: "push_files_content", description: "Push multiple files with direct content to a GitHub repository in a single commit", inputSchema: zodToJsonSchema(files.PushFilesContentSchema), },
- index.ts:239-251 (handler)MCP request handler case for push_files_content: parses arguments, calls the implementation function, and formats response.case "push_files_content": { const args = files.PushFilesContentSchema.parse(request.params.arguments); const result = await files.pushFilesContent( args.owner, args.repo, args.branch, args.files, args.message ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }