github/github-mcp-server · warning

failed to marshal advisory: %w

Error message

failed to marshal advisory: %w

What it means

json.Marshal of the *github.GlobalAdvisory value returned by the API failed. Marshaling plain data structs essentially never fails; an error means the value contains an unsupported type (chan/func), a cycle, NaN/Inf floats, or a custom MarshalJSON that returned an error.

Source

Thrown at pkg/github/security_advisories.go:380

			}

			advisory, resp, err := client.SecurityAdvisories.GetGlobalSecurityAdvisories(ctx, ghsaID)
			if err != nil {
				return nil, nil, fmt.Errorf("failed to get advisory: %w", err)
			}
			defer func() { _ = resp.Body.Close() }()

			if resp.StatusCode != http.StatusOK {
				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 advisory", resp, body), nil, nil
			}

			r, err := json.Marshal(advisory)
			if err != nil {
				return nil, nil, fmt.Errorf("failed to marshal advisory: %w", err)
			}

			result := utils.NewToolResultText(string(r))
			// A global advisory is world-readable (public) but externally
			// authored (untrusted).
			result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelGlobalSecurityAdvisory())
			return result, nil, nil
		},
	)
}

func ListOrgRepositorySecurityAdvisories(t translations.TranslationHelperFunc) inventory.ServerTool {
	return NewTool(
		ToolsetMetadataSecurityAdvisories,
		mcp.Tool{
			Name:        "list_org_repository_security_advisories",
			Description: t("TOOL_LIST_ORG_REPOSITORY_SECURITY_ADVISORIES_DESCRIPTION", "List repository security advisories for a GitHub organization."),
			Annotations: &mcp.ToolAnnotations{

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Log the underlying error - it names the offending type or field
  2. Align the go-github dependency version with the one this server build expects
  3. Add a unit test that unmarshals a sample advisory JSON and re-marshals it to catch regressions
Defensive patterns

Strategy: fallback

Try / catch

r, err := json.Marshal(advisory)
if err != nil {
	// log the offending payload shape and degrade rather than fail the whole tool call
	slog.Error("marshal advisory failed", "error", err)
	r, err = json.Marshal(struct{ Error string }{"advisory could not be serialized"})
}

Prevention

When it happens

Trigger: Upstream go-github type changes introducing unsupported fields or a failing MarshalJSON; advisory payloads containing values the local Go version cannot encode.

Common situations: Version skew after upgrading go-github without regenerating/aligning types; locally patched structs.

Related errors


AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15). Data as JSON: /api/errors/106d879f4b46ef8a. Report an issue: GitHub.