-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add raw client error annotation and annotate GetFileContents #1570
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package errors | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/github/github-mcp-server/pkg/utils" | ||
| "github.com/google/go-github/v79/github" | ||
|
|
@@ -44,10 +45,25 @@ func (e *GitHubGraphQLError) Error() string { | |
| return fmt.Errorf("%s: %w", e.Message, e.Err).Error() | ||
| } | ||
|
|
||
| type GitHubRawAPIError struct { | ||
| Message string `json:"message"` | ||
| Response *http.Response `json:"-"` | ||
| Err error `json:"-"` | ||
| } | ||
|
|
||
| func newGitHubRawAPIError(message string, resp *http.Response, err error) *GitHubRawAPIError { | ||
| return &GitHubRawAPIError{ | ||
| Message: message, | ||
| Response: resp, | ||
| Err: err, | ||
|
Comment on lines
+48
to
+58
|
||
| } | ||
| } | ||
|
|
||
| type GitHubErrorKey struct{} | ||
| type GitHubCtxErrors struct { | ||
| api []*GitHubAPIError | ||
| graphQL []*GitHubGraphQLError | ||
| raw []*GitHubRawAPIError | ||
| } | ||
|
|
||
| // ContextWithGitHubErrors updates or creates a context with a pointer to GitHub error information (to be used by middleware). | ||
|
|
@@ -107,6 +123,15 @@ func addGitHubGraphQLErrorToContext(ctx context.Context, err *GitHubGraphQLError | |
| return nil, fmt.Errorf("context does not contain GitHubCtxErrors") | ||
| } | ||
|
|
||
| func addRawAPIErrorToContext(ctx context.Context, err *GitHubRawAPIError) (context.Context, error) { | ||
| if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok { | ||
| val.raw = append(val.raw, err) | ||
| return ctx, nil | ||
| } | ||
|
|
||
|
Comment on lines
124
to
+131
|
||
| return nil, fmt.Errorf("context does not contain GitHubCtxErrors") | ||
| } | ||
|
|
||
| // NewGitHubAPIErrorResponse returns an mcp.NewToolResultError and retains the error in the context for access via middleware | ||
| func NewGitHubAPIErrorResponse(ctx context.Context, message string, resp *github.Response, err error) *mcp.CallToolResult { | ||
| apiErr := newGitHubAPIError(message, resp, err) | ||
|
|
@@ -124,3 +149,11 @@ func NewGitHubGraphQLErrorResponse(ctx context.Context, message string, err erro | |
| } | ||
| return utils.NewToolResultErrorFromErr(message, err) | ||
| } | ||
|
|
||
| func NewGitHubRawAPIErrorResponse(ctx context.Context, message string, resp *http.Response, err error) *mcp.CallToolResult { | ||
| rawAPIErr := newGitHubRawAPIError(message, resp, err) | ||
| if ctx != nil { | ||
| _, _ = addRawAPIErrorToContext(ctx, rawAPIErr) // Explicitly ignore error for graceful handling | ||
| } | ||
|
Comment on lines
151
to
+157
|
||
| return utils.NewToolResultErrorFromErr(message, 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.
The
GitHubRawAPIErrortype is missing anError() stringmethod for consistency withGitHubAPIErrorandGitHubGraphQLError. This method should be implemented to satisfy the error interface properly.Add: