github/github-mcp-server · warning
failed to marshal response: %w
Error message
failed to marshal response: %w
What it means
After a successful GetCommit, the tool converts the commit to convertToMinimalCommit(commit, detail) and json.Marshals it. Plain data structs cannot make Marshal fail, so this branch is effectively unreachable defensive code; hitting it indicates a type regression (func/chan field, cyclic pointer) in the minimal-commit types rather than bad API data.
Source
Thrown at pkg/github/repositories.go:121
err,
), nil, nil
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != 200 {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, nil, fmt.Errorf("failed to read response body: %w", err)
}
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get commit", resp, body), nil, nil
}
// Convert to minimal commit
minimalCommit := convertToMinimalCommit(commit, detail)
r, err := json.Marshal(minimalCommit)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal response: %w", err)
}
result := utils.NewToolResultText(string(r))
// Commit content is reachable from the repo's history; in public
// repos anyone can land it via a PR (untrusted), in private repos
// only collaborators can (trusted). Confidentiality follows repo
// visibility.
result = attachRepoVisibilityIFCLabel(ctx, deps, client, owner, repo, result, ifc.LabelCommitContents)
return result, nil, nil
},
)
}
// ListCommits creates a tool to get the list of commits of a branch in a GitHub
// repository.
func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool {
schema := &jsonschema.Schema{
Type: "object",View on GitHub (pinned to 0ea1f775a7)
Solutions
- Review recent edits to convertToMinimalCommit and its return type for non-JSON-safe fields
- Add a CI test marshaling a converted commit fixture
- Model derived values as precomputed strings/ints, never closures
Example fix
// before
type MinimalCommit struct {
SHA string `json:"sha"`
Message string `json:"message"`
DiffFn func() string // no json tag, Marshal fails on it
}
// after
type MinimalCommit struct {
SHA string `json:"sha"`
Message string `json:"message"`
DiffPreview string `json:"diff_preview,omitempty"` // precomputed
} Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
var unsupportedType *json.UnsupportedTypeError
if errors.As(err, &unsupportedType) {
// regression in MinimalCommit types — file a bug, no operational fix
} Try / catch
r, err := json.Marshal(minimalCommit)
if err != nil {
log.Error("commit marshal regression", "err", err)
return nil, nil, fmt.Errorf("internal serialization failure: %w", err)
} Prevention
- Keep Minimal* DTOs acyclic with only string/int/bool fields
- Marshal-type coverage tests in CI catch regressions before release
- Do not retry — report as a bug with the stack trace
When it happens
Trigger: A field of unsupported type (func, chan, complex, cyclic pointer) is added to the minimal commit struct family; every get_commit call then fails at marshal time despite the API call succeeding.
Common situations: Refactors embedding raw go-github types that carry func fields; computed helpers accidentally stored as fields instead of methods.
Related errors
- failed to marshal response: %w
- GitHub App authentication and GITHUB_PERSONAL_ACCESS_TOKEN a
- GitHub App ID or client ID is required (GITHUB_APP_ID)
- repo is required
- failed to marshal response: %w
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/09f3b2307ea5fd56.
Report an issue: GitHub.