Skip to content

Replace context-based error handling with CallToolResult.SetError#2038

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/update-error-handling-methods
Draft

Replace context-based error handling with CallToolResult.SetError#2038
Copilot wants to merge 2 commits intomainfrom
copilot/update-error-handling-methods

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Summary

Replaces the context-based GitHub API error storage mechanism with the Go SDK v1.3.0 CallToolResult.SetError()/GetError() API, embedding typed errors directly in tool results.

Why

The Go SDK v1.3.0 added SetError/GetError on CallToolResult, providing a cleaner, type-safe way to pass errors through tool results. The previous approach stored errors in context via middleware as a workaround for SDK limitations that no longer exist.

What changed

  • pkg/errors/error.go: NewGitHubAPIErrorResponse, NewGitHubGraphQLErrorResponse, NewGitHubRawAPIErrorResponse now call result.SetError(typedErr) instead of storing in context. Removed all context-based infrastructure (ContextWithGitHubErrors, GetGitHubAPIErrors, GitHubCtxErrors, etc.). Exported error constructors. Added Unwrap() to all error types.
  • pkg/github/server.go: Removed addGitHubAPIErrorToContext middleware function and its registration.
  • internal/ghmcp/server.go: Removed ContextWithGitHubErrors setup before server run.
  • pkg/github/repositories_helper.go, pkg/github/actions.go: Removed NewGitHubAPIErrorToCtx calls from helper functions (these only existed for context-based observability).
  • pkg/errors/error_test.go: Rewrote tests to verify SetError/GetError + errors.As extraction.
  • docs/error-handling.md: Updated to document new approach.

Consumers extract typed errors from results:

if err := result.GetError(); err != nil {
    var apiErr *errors.GitHubAPIError
    if errors.As(err, &apiErr) {
        // apiErr.Response.StatusCode, apiErr.Message, etc.
    }
}

MCP impact

  • No tool or API changes — error response text format is unchanged; the typed error is only accessible server-side via GetError().

Prompts tested (tool changes only)

N/A — no tool schema or behavior changes.

Security / limits

  • No security or limits impact

Tool renaming

  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Updated (README / docs / examples) — docs/error-handling.md updated to reflect SetError/GetError pattern.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • golangci-lint.run
    • Triggering command: /usr/bin/curl curl -sSfL REDACTED x64/pkg/tool/lin/tmp/go-build1142153451/b110/vet.cfg -uns�� pkg/mod/github.com/spf13/afero@v. pkg/mod/github.com/spf13/afero@v--gdwarf2 de/node/bin/as (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Migrate from storing GitHub API errors in context via middleware to
embedding typed errors directly in CallToolResult using the Go SDK
v1.3.0 SetError/GetError API.

Key changes:
- NewGitHubAPIErrorResponse/NewGitHubGraphQLErrorResponse/
  NewGitHubRawAPIErrorResponse now use result.SetError() with typed
  errors instead of storing in context
- Add Unwrap() to all error types for errors.As/errors.Is support
- Export error constructors (NewGitHubAPIError, etc.) for direct use
- Remove context-based error infrastructure (ContextWithGitHubErrors,
  GetGitHubAPIErrors, GitHubCtxErrors, etc.)
- Remove addGitHubAPIErrorToContext middleware from server.go
- Remove NewGitHubAPIErrorToCtx/NewGitHubGraphQLErrorToCtx and their
  callers in repositories_helper.go and actions.go
- Update tests to verify SetError/GetError and errors.As extraction
- Update error-handling.md documentation

Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Copilot AI changed the title [WIP] Update error handling in CallToolResult Replace context-based error handling with CallToolResult.SetError Feb 18, 2026
Copilot AI requested a review from SamMorrowDrums February 18, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments