github/github-mcp-server · warning

failed to marshal comments: %w

Error message

failed to marshal comments: %w

What it means

list_discussion_comments builds a response map (comments slice, pageInfo, totalCount) and json.Marshals it after a successful query. Identical defensive pattern to the other discussions list endpoints: all constituent values are primitives from GraphQL scalars, and json.Marshal's only error conditions (unsupported types, cycles, NaN) cannot arise from them. Encountering it means the response composition code changed to include something unmarshalable.

Source

Thrown at pkg/github/discussions.go:589

				pageInfo = q.Repository.Discussion.Comments.PageInfo
				totalCount = q.Repository.Discussion.Comments.TotalCount
			}

			// Create response with pagination info
			response := map[string]any{
				"comments": comments,
				"pageInfo": map[string]any{
					"hasNextPage":     pageInfo.HasNextPage,
					"hasPreviousPage": pageInfo.HasPreviousPage,
					"startCursor":     string(pageInfo.StartCursor),
					"endCursor":       string(pageInfo.EndCursor),
				},
				"totalCount": totalCount,
			}

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

			result := utils.NewToolResultText(string(out))
			// Discussion comments are user-authored (untrusted); confidentiality
			// follows repo visibility.
			result = attachRepoVisibilityIFCLabelLazy(ctx, deps, params.Owner, params.Repo, result, ifc.LabelRepoUserContent)
			return result, nil, nil
		},
	)
}

func DiscussionCommentWrite(t translations.TranslationHelperFunc) inventory.ServerTool {
	return NewTool(
		ToolsetMetadataDiscussions,
		mcp.Tool{
			Name: "discussion_comment_write",
			Description: t("TOOL_DISCUSSION_COMMENT_WRITE_DESCRIPTION", `Write operations for discussion comments.
Supports adding top-level comments, replying to existing comments, updating comment content, deleting comments, and marking or unmarking comments as the answer.`),

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Project every nested GraphQL object into maps of primitives before insertion, as the current code does
  2. Write a table-driven marshal test covering comments with and without optional fields
  3. On occurrence, diff the response construction block; the defect is local to this handler
  4. Guard tool availability: since the query already succeeded, retrying the tool will not change the marshal outcome; fix code instead
Defensive patterns

Strategy: try-catch

Try / catch

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

Prevention

When it happens

Trigger: A refactor embedding raw githubv4 structs (which may carry func fields or unusual types) instead of projected plain values; NaN/Inf if numeric float fields are ever added; cyclic comment/reaction graphs. Not producible by GitHub data through the current code.

Common situations: Extending the comment payload with reaction or author objects by direct struct inclusion; version upgrades changing embedded types; test harnesses substituting fake comment objects with unmarshalable fields.

Related errors


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