github/github-mcp-server · info

failed to marshal labels: %w

Error message

failed to marshal labels: %w

What it means

The list_labels tool failed to JSON-encode its response map ({labels: [...], totalCount: n}) whose leaves are all strings and ints. This guard is effectively unreachable; hitting it indicates an internal serialization defect, not a caller mistake.

Source

Thrown at pkg/github/labels.go:217

			labels := make([]map[string]any, len(query.Repository.Labels.Nodes))
			for i, labelNode := range query.Repository.Labels.Nodes {
				labels[i] = map[string]any{
					"id":          fmt.Sprintf("%v", labelNode.ID),
					"name":        string(labelNode.Name),
					"color":       string(labelNode.Color),
					"description": string(labelNode.Description),
				}
			}

			response := map[string]any{
				"labels":     labels,
				"totalCount": int(query.Repository.Labels.TotalCount),
			}

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

			result := utils.NewToolResultText(string(out))
			// Labels are structural repo metadata defined by collaborators
			// (trusted); confidentiality follows repo visibility.
			result = attachRepoVisibilityIFCLabelLazy(ctx, deps, owner, repo, result, ifc.LabelRepoMetadata)
			return result, nil, nil
		},
	)
}

// LabelWrite handles create, update, and delete operations for GitHub labels
func LabelWrite(t translations.TranslationHelperFunc) inventory.ServerTool {
	return NewTool(
		ToolsetLabels,
		mcp.Tool{
			Name:        "label_write",
			Description: t("TOOL_LABEL_WRITE_DESCRIPTION", "Perform write operations on repository labels. To set labels on issues, use the 'update_issue' tool."),

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Report as an internal bug with the server version and repository details
  2. Retry the call once — the label listing query already succeeded
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil && strings.Contains(err.Error(), "failed to marshal labels") {
    // Unreachable-in-practice guard; treat as internal bug, not input error.
}

Prevention

When it happens

Trigger: Not triggerable via arguments; would require internal changes that introduce non-serializable values into the response map.

Common situations: Practically unseen; only appears after server-side code changes to the response shape.

Related errors


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