push_files
Push multiple files to a GitHub repository in a single commit, specifying the owner, repo, branch, and commit message using the input schema.
Instructions
Push multiple files to a GitHub repository in a single commit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | Yes | Branch to push to (e.g., 'main' or 'master') | |
| files | Yes | Array of files to push | |
| message | Yes | Commit message | |
| owner | Yes | Repository owner (username or organization) | |
| repo | Yes | Repository name |
Implementation Reference
- operations/files.ts:202-219 (handler)Core handler function implementing the push_files tool logic: fetches current branch ref, creates a new git tree with the files, creates a commit, and updates the branch reference.export async function pushFiles( owner: string, repo: string, branch: string, files: FileOperation[], 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:35-41 (schema)Zod schema defining the input parameters for the push_files tool, including repo details, branch, files array, and commit message.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"), });
- index.ts:90-94 (registration)Registers the push_files tool in the MCP server's listTools response, providing name, description, and JSON schema derived from PushFilesSchema.{ name: "push_files", description: "Push multiple files to a GitHub repository in a single commit", inputSchema: zodToJsonSchema(files.PushFilesSchema), },
- index.ts:386-398 (handler)MCP server request handler for callTool requests to push_files: parses arguments with schema and delegates to files.pushFiles function.case "push_files": { const args = files.PushFilesSchema.parse(request.params.arguments); const result = await files.pushFiles( args.owner, args.repo, args.branch, args.files, args.message ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }
- operations/files.ts:13-16 (schema)Supporting schema for individual file operations (path and content) used within PushFilesSchema's files array.export const FileOperationSchema = z.object({ path: z.string(), content: z.string(), });