push_files_from_path
Push multiple files from local paths to a GitHub repository in one commit. Upload files to a specified branch with a commit message.
Instructions
Push multiple files from filesystem paths 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 from filesystem paths | |
| message | Yes | Commit message |
Implementation Reference
- operations/files.ts:236-282 (handler)The primary handler function for the 'push_files_from_path' tool. It validates local file existence, reads their contents, converts to FileContent format, and pushes to GitHub repository using pushFilesContent.export async function pushFilesFromPath( owner: string, repo: string, branch: string, files: FilePath[], message: string ) { try { // First verify all files exist before attempting any operations await Promise.all( files.map(async (file) => { try { await fs.access(file.filepath); } catch (err) { const error = err as Error; throw new Error(`File not accessible: ${file.filepath} - ${error.toString()}`); } }) ); // Convert FilePath objects to FileContent objects by reading the files const fileContents: FileContent[] = await Promise.all( files.map(async (file) => { try { const content = await fs.readFile(file.filepath, 'utf8'); return { path: file.path, content, }; } catch (err) { const error = err as Error; throw new Error(`Failed to read file ${file.filepath}: ${error.toString()}`); } }) ); if (!fileContents.length) { throw new Error('No files were successfully read'); } // Use the existing pushFilesContent function with the read content return pushFilesContent(owner, repo, branch, fileContents, message); } catch (err) { const error = err as Error; throw new Error(`Failed to push files: ${error.toString()}`); } }
- operations/files.ts:49-55 (schema)Zod schema defining the input parameters for the push_files_from_path tool, including owner, repo, branch, files array (with path and filepath), and commit message.export const PushFilesFromPathSchema = 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(FilePathSchema).describe("Array of files to push from filesystem paths"), message: z.string().describe("Commit message"), });
- index.ts:253-265 (registration)Registration and dispatching in the CallToolRequestHandler switch statement: parses arguments using the schema and invokes the pushFilesFromPath handler.case "push_files_from_path": { const args = files.PushFilesFromPathSchema.parse(request.params.arguments); const result = await files.pushFilesFromPath( args.owner, args.repo, args.branch, args.files, args.message ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }
- index.ts:94-97 (registration)Tool metadata registration in the ListToolsRequestHandler: defines name, description, and input schema for discovery.name: "push_files_from_path", description: "Push multiple files from filesystem paths to a GitHub repository in a single commit", inputSchema: zodToJsonSchema(files.PushFilesFromPathSchema), },