@@ -48,6 +48,7 @@ import {
48
48
SearchCodeResponseSchema ,
49
49
SearchCodeSchema ,
50
50
SearchIssuesResponseSchema ,
51
+ UpdatePullRequestBranchSchema ,
51
52
SearchIssuesSchema ,
52
53
SearchRepositoriesSchema ,
53
54
SearchUsersResponseSchema ,
@@ -853,6 +854,31 @@ async function getPullRequestFiles(
853
854
return z . array ( PullRequestFileSchema ) . parse ( await response . json ( ) ) ;
854
855
}
855
856
857
+ async function updatePullRequestBranch (
858
+ owner : string ,
859
+ repo : string ,
860
+ pullNumber : number ,
861
+ expectedHeadSha ? : string
862
+ ) : Promise < void > {
863
+ const response = await fetch (
864
+ `https://api.github.com/repos/${ owner } /${ repo } /pulls/${ pullNumber } /update-branch` ,
865
+ {
866
+ method : "PUT" ,
867
+ headers : {
868
+ Authorization : `token ${ GITHUB_PERSONAL_ACCESS_TOKEN } ` ,
869
+ Accept : "application/vnd.github.v3+json" ,
870
+ "User-Agent" : "github-mcp-server" ,
871
+ "Content-Type" : "application/json" ,
872
+ } ,
873
+ body : expectedHeadSha ? JSON . stringify ( { expected_head_sha : expectedHeadSha } ) : undefined ,
874
+ }
875
+ ) ;
876
+
877
+ if ( ! response . ok ) {
878
+ throw new Error ( `GitHub API error: ${ response . statusText } ` ) ;
879
+ }
880
+ }
881
+
856
882
async function getPullRequestStatus (
857
883
owner : string ,
858
884
repo : string ,
@@ -1017,6 +1043,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1017
1043
name : "get_pull_request_status" ,
1018
1044
description : "Get the combined status of all status checks for a pull request" ,
1019
1045
inputSchema : zodToJsonSchema ( GetPullRequestStatusSchema )
1046
+ } ,
1047
+ {
1048
+ name : "update_pull_request_branch" ,
1049
+ description : "Update a pull request branch with the latest changes from the base branch" ,
1050
+ inputSchema : zodToJsonSchema ( UpdatePullRequestBranchSchema )
1020
1051
}
1021
1052
] ,
1022
1053
} ;
@@ -1261,6 +1292,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1261
1292
return { content : [ { type : "text" , text : JSON . stringify ( status , null , 2 ) } ] } ;
1262
1293
}
1263
1294
1295
+ case "update_pull_request_branch" : {
1296
+ const args = UpdatePullRequestBranchSchema . parse ( request . params . arguments ) ;
1297
+ await updatePullRequestBranch ( args . owner , args . repo , args . pull_number , args . expected_head_sha ) ;
1298
+ return { content : [ { type : "text" , text : "Pull request branch updated successfully" } ] } ;
1299
+ }
1300
+
1264
1301
default :
1265
1302
throw new Error ( `Unknown tool: ${ request . params . name } ` ) ;
1266
1303
}
0 commit comments