Skip to content

Commit de06a7c

Browse files
quiloos39claude
andcommitted
feat: add since and until date filters to list_commits
Add optional `since` and `until` parameters to the list_commits tool, allowing users to filter commits by date range using ISO 8601 format. This enables more efficient commit queries for time-based workflows like calculating working hours or reviewing activity within specific periods, reducing unnecessary context from historical commits. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1820a0f commit de06a7c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pkg/github/repositories.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"net/url"
1010
"strings"
11+
"time"
1112

1213
ghErrors "github.com/github/github-mcp-server/pkg/errors"
1314
"github.com/github/github-mcp-server/pkg/inventory"
@@ -147,6 +148,14 @@ func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool {
147148
Type: "string",
148149
Description: "Author username or email address to filter commits by",
149150
},
151+
"since": {
152+
Type: "string",
153+
Description: "Only show commits after this date (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ)",
154+
},
155+
"until": {
156+
Type: "string",
157+
Description: "Only show commits before this date (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ)",
158+
},
150159
},
151160
Required: []string{"owner", "repo"},
152161
}),
@@ -169,6 +178,27 @@ func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool {
169178
if err != nil {
170179
return utils.NewToolResultError(err.Error()), nil, nil
171180
}
181+
sinceStr, err := OptionalParam[string](args, "since")
182+
if err != nil {
183+
return utils.NewToolResultError(err.Error()), nil, nil
184+
}
185+
untilStr, err := OptionalParam[string](args, "until")
186+
if err != nil {
187+
return utils.NewToolResultError(err.Error()), nil, nil
188+
}
189+
var sinceTime, untilTime time.Time
190+
if sinceStr != "" {
191+
sinceTime, err = time.Parse(time.RFC3339, sinceStr)
192+
if err != nil {
193+
return utils.NewToolResultError(fmt.Sprintf("invalid 'since' date format, expected ISO 8601 (YYYY-MM-DDTHH:MM:SSZ): %s", err.Error())), nil, nil
194+
}
195+
}
196+
if untilStr != "" {
197+
untilTime, err = time.Parse(time.RFC3339, untilStr)
198+
if err != nil {
199+
return utils.NewToolResultError(fmt.Sprintf("invalid 'until' date format, expected ISO 8601 (YYYY-MM-DDTHH:MM:SSZ): %s", err.Error())), nil, nil
200+
}
201+
}
172202
pagination, err := OptionalPaginationParams(args)
173203
if err != nil {
174204
return utils.NewToolResultError(err.Error()), nil, nil
@@ -181,6 +211,8 @@ func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool {
181211
opts := &github.CommitsListOptions{
182212
SHA: sha,
183213
Author: author,
214+
Since: sinceTime,
215+
Until: untilTime,
184216
ListOptions: github.ListOptions{
185217
Page: pagination.Page,
186218
PerPage: perPage,

0 commit comments

Comments
 (0)