diff --git a/src/index.ts b/src/index.ts --- a/src/index.ts 2024-01-29 17:00:00.000000000 +0000 +++ b/src/index.ts 2024-01-29 17:00:00.000000000 +0000 @@ -25,6 +25,14 @@ branch?: string; } +interface UpdateFileArgs extends RepoArgs { + path: string; + content: string; + message: string; + branch?: string; + sha: string; +} + interface GetContentsArgs extends RepoArgs { path: string; ref?: string; @@ -214,6 +222,41 @@ required: ['owner', 'repo', 'path', 'message'], }, }, + { + name: 'update_file', + description: 'Update an existing file in a repository', + inputSchema: { + type: 'object', + properties: { + owner: { + type: 'string', + description: 'Repository owner', + }, + repo: { + type: 'string', + description: 'Repository name', + }, + path: { + type: 'string', + description: 'Path to file', + }, + content: { + type: 'string', + description: 'New file content (will be base64 encoded)', + }, + message: { + type: 'string', + description: 'Commit message', + }, + branch: { + type: 'string', + description: 'Branch name', + }, + sha: { + type: 'string', + description: 'SHA of the file being replaced', + }, + }, + required: ['owner', 'repo', 'path', 'content', 'message', 'sha'], + }, + }, { name: 'create_branch', description: 'Create a new branch in a repository', @@ -432,6 +475,41 @@ }; } + case 'update_file': { + const args = request.params.arguments as unknown as UpdateFileArgs; + const response = await this.api.put( + `/repos/${args.owner}/${args.repo}/contents/${args.path}`, + { + content: Buffer.from(args.content).toString('base64'), + message: args.message, + sha: args.sha, + branch: args.branch, + } + ); + + // Verify the file after update + const verifyResponse = await this.api.get( + `/repos/${args.owner}/${args.repo}/contents/${args.path}`, + { + params: { ref: args.branch }, + } + ); + + return { + content: [ + { + type: 'text', + text: JSON.stringify({ + success: true, + message: 'File updated successfully', + file: { + path: args.path, + commit: response.data.commit, + }, + content: verifyResponse.data, + }, null, 2), + }, + ], + }; + } + case 'create_branch': { const { owner, repo, branch, from } = request.params.arguments as unknown as CreateBranchArgs;