push_files_content
Push multiple files with their content to a GitHub repository in a single commit, specifying owner, repo, branch, and commit message for streamlined file updates.
Instructions
Push multiple files with direct content to a GitHub repository in a single commit
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| 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 | |
| owner | Yes | Repository owner (username or organization) | |
| repo | Yes | Repository name |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"branch": {
"description": "Branch to push to (e.g., 'main' or 'master')",
"type": "string"
},
"files": {
"description": "Array of files to push with their content",
"items": {
"additionalProperties": false,
"properties": {
"content": {
"type": "string"
},
"path": {
"type": "string"
}
},
"required": [
"path",
"content"
],
"type": "object"
},
"type": "array"
},
"message": {
"description": "Commit message",
"type": "string"
},
"owner": {
"description": "Repository owner (username or organization)",
"type": "string"
},
"repo": {
"description": "Repository name",
"type": "string"
}
},
"required": [
"owner",
"repo",
"branch",
"files",
"message"
],
"type": "object"
}
Implementation Reference
- index.ts:239-251 (handler)Handler for the 'push_files_content' tool call in the MCP server, which parses input arguments using the schema and invokes the core pushFilesContent function from files module.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) }], }; }
- operations/files.ts:41-47 (schema)Zod schema defining the input parameters for the push_files_content tool.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's list of available tools, including name, description, and input schema reference.{ name: "push_files_content", description: "Push multiple files with direct content to a GitHub repository in a single commit", inputSchema: zodToJsonSchema(files.PushFilesContentSchema), },
- operations/files.ts:217-234 (helper)Core helper function that implements the logic to push multiple files to GitHub 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); }