@@ -25,12 +25,15 @@ import {
25
25
GitHubCreateUpdateFileResponseSchema ,
26
26
GitHubForkSchema ,
27
27
GitHubIssueSchema ,
28
+ GitHubListCommits ,
29
+ GitHubListCommitsSchema ,
28
30
GitHubPullRequestSchema ,
29
31
GitHubReferenceSchema ,
30
32
GitHubRepositorySchema ,
31
33
GitHubSearchResponseSchema ,
32
34
GitHubTreeSchema ,
33
35
IssueCommentSchema ,
36
+ ListCommitsSchema ,
34
37
ListIssuesOptionsSchema ,
35
38
PushFilesSchema ,
36
39
SearchCodeResponseSchema ,
@@ -54,7 +57,7 @@ import {
54
57
type GitHubTree ,
55
58
type SearchCodeResponse ,
56
59
type SearchIssuesResponse ,
57
- type SearchUsersResponse ,
60
+ type SearchUsersResponse
58
61
} from './schemas.js' ;
59
62
60
63
const server = new Server (
@@ -487,6 +490,40 @@ async function createRepository(
487
490
return GitHubRepositorySchema . parse ( await response . json ( ) ) ;
488
491
}
489
492
493
+ async function listCommits (
494
+ owner : string ,
495
+ repo : string ,
496
+ page : number = 1 ,
497
+ perPage : number = 30 ,
498
+ sha ? : string ,
499
+ ) : Promise < GitHubListCommits > {
500
+ const url = new URL ( `https://api.github.com/repos/${ owner } /${ repo } /commits` ) ;
501
+ url . searchParams . append ( "page" , page . toString ( ) ) ;
502
+ url . searchParams . append ( "per_page" , perPage . toString ( ) ) ;
503
+ if ( sha ) {
504
+ url . searchParams . append ( "sha" , sha ) ;
505
+ }
506
+
507
+ const response = await fetch (
508
+ url . toString ( ) ,
509
+ {
510
+ method : "GET" ,
511
+ headers : {
512
+ "Authorization" : `token ${ GITHUB_PERSONAL_ACCESS_TOKEN } ` ,
513
+ "Accept" : "application/vnd.github.v3+json" ,
514
+ "User-Agent" : "github-mcp-server" ,
515
+ "Content-Type" : "application/json"
516
+ } ,
517
+ }
518
+ ) ;
519
+
520
+ if ( ! response . ok ) {
521
+ throw new Error ( `GitHub API error: ${ response . statusText } ` ) ;
522
+ }
523
+
524
+ return GitHubListCommitsSchema . parse ( await response . json ( ) ) ;
525
+ }
526
+
490
527
async function listIssues (
491
528
owner : string ,
492
529
repo : string ,
@@ -705,6 +742,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
705
742
description : "Create a new branch in a GitHub repository" ,
706
743
inputSchema : zodToJsonSchema ( CreateBranchSchema ) ,
707
744
} ,
745
+ {
746
+ name : "list_commits" ,
747
+ description : "Get list of commits of a branch in a GitHub repository" ,
748
+ inputSchema : zodToJsonSchema ( ListCommitsSchema )
749
+ } ,
708
750
{
709
751
name : "list_issues" ,
710
752
description : "List issues in a GitHub repository with filtering options" ,
@@ -924,6 +966,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
924
966
return { toolResult : comment } ;
925
967
}
926
968
969
+ case "list_commits" : {
970
+ const args = ListCommitsSchema . parse ( request . params . arguments ) ;
971
+ const results = await listCommits ( args . owner , args . repo , args . page , args . perPage , args . sha ) ;
972
+ return { content : [ { type : "text" , text : JSON . stringify ( results , null , 2 ) } ] } ;
973
+ }
974
+
927
975
default :
928
976
throw new Error ( `Unknown tool: ${ request . params . name } ` ) ;
929
977
}
0 commit comments