-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Optimize token usage in default list_ tools
#2016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 21 commits
9ef46dd
f5291c4
5d28623
7859111
07b71f1
70deafb
77695c7
92e6f44
14dd881
3a1d18d
c960f49
b651887
c75ab7d
2791676
afd1eba
de12f8f
86a41c2
aa635d6
67699f0
c29fcb5
f21b014
a7f3373
671301f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
|
|
||
| ghErrors "github.com/github/github-mcp-server/pkg/errors" | ||
| "github.com/github/github-mcp-server/pkg/inventory" | ||
| "github.com/github/github-mcp-server/pkg/response" | ||
| "github.com/github/github-mcp-server/pkg/sanitize" | ||
| "github.com/github/github-mcp-server/pkg/scopes" | ||
| "github.com/github/github-mcp-server/pkg/translations" | ||
|
|
@@ -1603,9 +1604,21 @@ func ListIssues(t translations.TranslationHelperFunc) inventory.ServerTool { | |
| totalCount = fragment.TotalCount | ||
| } | ||
|
|
||
| // Create response with issues | ||
| response := map[string]any{ | ||
| "issues": issues, | ||
| minimalIssues := make([]MinimalIssue, 0, len(issues)) | ||
| for _, issue := range issues { | ||
| if issue != nil { | ||
| minimalIssues = append(minimalIssues, convertToMinimalIssue(issue)) | ||
| } | ||
| } | ||
|
|
||
| optimizedIssues, err := response.OptimizeList(minimalIssues) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to optimize issues: %w", err) | ||
| } | ||
|
|
||
| // Wrap optimized issues with pagination metadata | ||
| issueResponse := map[string]any{ | ||
| "issues": json.RawMessage(optimizedIssues), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For empty issues list we used to return an empty list
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a |
||
| "pageInfo": map[string]any{ | ||
| "hasNextPage": pageInfo.HasNextPage, | ||
| "hasPreviousPage": pageInfo.HasPreviousPage, | ||
|
|
@@ -1614,7 +1627,7 @@ func ListIssues(t translations.TranslationHelperFunc) inventory.ServerTool { | |
| }, | ||
| "totalCount": totalCount, | ||
| } | ||
| out, err := json.Marshal(response) | ||
| out, err := json.Marshal(issueResponse) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to marshal issues: %w", err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different from
list_pull_requests, where if a call to OptimizeList fails we returnif err != nil { return utils.NewToolResultErrorFromErr("failed to marshal response", err), nil, nil }