- Notifications
You must be signed in to change notification settings - Fork1.2k
Enable use of error middleware#573
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 ourterms of service andprivacy 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?
Conversation
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.
Pull Request Overview
This PR introduces context-based error middleware support by capturing GitHub API and GraphQL errors in the context, exposing them for later inspection rather than returning raw errors. Key changes include:
- Swapping raw
fmt.Errorf
returns forNewGitHubAPIErrorResponse
/NewGitHubGraphQLErrorResponse
to store errors in context. - Updating tests to expect
result.IsError
and extract error text viagetErrorResult
. - Initializing and clearing error context in server hooks (
ContextWithGitHubErrors
).
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pkg/github/secret_scanning.go | Replaced raw error returns withNewGitHubAPIErrorResponse . |
pkg/github/search.go | Same pattern for search endpoints. |
pkg/github/repositories.go | Wrapped repository errors in context and result responses. |
pkg/github/pullrequests.go | Applied context error handling to pull request operations. |
pkg/github/notifications.go | Added context error responses for notifications API calls. |
pkg/github/context_tools.go | Swapped user error return for API error response inGetMe . |
pkg/github/actions.go | Adjusted job log handlers to return and store context errors. |
pkg/github/code_scanning.go | Consistent context error wrapping for code scanning endpoints. |
pkg/errors/error.go | IntroducedGitHubAPIError ,GitHubGraphQLError , and helpers. |
internal/ghmcp/server.go | Added hooks to initialize/clear GitHub error context. |
Various_test.go files | Updated tests to checkresult.IsError and inspect error text. |
Comments suppressed due to low confidence (1)
pkg/github/context_tools.go:32
- [nitpick] Consider renaming the variable
res
toresp
for consistency with other GitHub client calls.
user, res, err := client.Users.Get(ctx, "")
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
ef16fd8
toffd99aa
Compare
Primarily for the remote server, this is the minimal approach@omgitsads and I could find to enable us to store API errors on the context, so that we can use the error types and http status codes etc. to derive the nature of failures, so that we can understand if failed tool calls occur due to:
Without this knowledge it's hard for us to validate if changes break things or not.
This is additionally frustrated by the fact mcp-go currently doesn't propagate context through each next step, and so we have concluded that if we create a value pointer on the context, we can edit the values without needing to propagate the context, and we are using this to be able to implement the aforementioned middleware, which can then extract the errors and inspect them without logging them directly (as that would expose PII sometimes), and so it's best to be able to use
Errors.Is
checks. The middleware is not present in this repo (although we could also provide debug logs on the STDIO server using the server log message protocol, which would be a nice addition and likely a follow-up to this work).Developer facing changes
Instead of directly returning mcp tool error responses, tool authors will call functions that will both return the tool error response, but will also add the actual errors to the context for later inspection.
Additional change
Errors that are ones the user should be able to do something about need to be returned as failed tool calls and not as the error value, so I have fixed a few of those in this PR.
I have left things like failures to marhsall response json, as I would consider that a real error and likely something that requires developers to fix.