@@ -25,12 +25,15 @@ import {
2525 GitHubCreateUpdateFileResponseSchema ,
2626 GitHubForkSchema ,
2727 GitHubIssueSchema ,
28+ GitHubListCommits ,
29+ GitHubListCommitsSchema ,
2830 GitHubPullRequestSchema ,
2931 GitHubReferenceSchema ,
3032 GitHubRepositorySchema ,
3133 GitHubSearchResponseSchema ,
3234 GitHubTreeSchema ,
3335 IssueCommentSchema ,
36+ ListCommitsSchema ,
3437 ListIssuesOptionsSchema ,
3538 PushFilesSchema ,
3639 SearchCodeResponseSchema ,
@@ -54,7 +57,7 @@ import {
5457 type GitHubTree ,
5558 type SearchCodeResponse ,
5659 type SearchIssuesResponse ,
57- type SearchUsersResponse ,
60+ type SearchUsersResponse
5861} from './schemas.js' ;
5962
6063const server = new Server (
@@ -487,6 +490,40 @@ async function createRepository(
487490 return GitHubRepositorySchema . parse ( await response . json ( ) ) ;
488491}
489492
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+
490527async function listIssues (
491528 owner : string ,
492529 repo : string ,
@@ -705,6 +742,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
705742 description : "Create a new branch in a GitHub repository" ,
706743 inputSchema : zodToJsonSchema ( CreateBranchSchema ) ,
707744 } ,
745+ {
746+ name : "list_commits" ,
747+ description : "Get list of commits of a branch in a GitHub repository" ,
748+ inputSchema : zodToJsonSchema ( ListCommitsSchema )
749+ } ,
708750 {
709751 name : "list_issues" ,
710752 description : "List issues in a GitHub repository with filtering options" ,
@@ -924,6 +966,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
924966 return { toolResult : comment } ;
925967 }
926968
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+
927975 default :
928976 throw new Error ( `Unknown tool: ${ request . params . name } ` ) ;
929977 }
0 commit comments