github-mcp-server icon indicating copy to clipboard operation
github-mcp-server copied to clipboard

Fix list_project_fields JSON unmarshal error for single_select fields

Open Copilot opened this issue 1 month ago • 0 comments

Closes: #1418

list_project_fields fails when projects contain single_select fields with options:

json: cannot unmarshal object into Go struct field ProjectV2FieldOption.options.name of type string

Root cause: go-github v79 expects options.name to be *ProjectV2TextContent (object), but the GitHub API returns a plain string.

Fix: Custom types with flexible JSON unmarshaling that handles both formats:

  • FlexibleString: Custom type with UnmarshalJSON that accepts either "Backlog" or {"raw": "Backlog", "html": "Backlog"}
  • ProjectField types: Local structs using FlexibleString for option names/descriptions
  • Raw API calls: ListProjectFields and GetProjectField now use client.NewRequest/Do with our types instead of go-github's broken types
// FlexibleString handles both string and object formats
func (f *FlexibleString) UnmarshalJSON(data []byte) error {
    var s string
    if err := json.Unmarshal(data, &s); err == nil {
        f.Raw, f.HTML = s, s
        return nil
    }
    // Fall back to object format
    type alias FlexibleString
    return json.Unmarshal(data, (*alias)(f))
}

Tradeoffs: Duplicates some go-github types locally. This is preferable to waiting for an upstream fix or forking the library.

Alternatives: Could have submitted a PR to go-github, but that would leave users broken until a new release. Local fix provides immediate resolution.

Original prompt

This section details on the original issue you should resolve

<issue_title>list_project_fields fails with JSON unmarshal error for single_select fields with options</issue_title> <issue_description>## Bug Description

The list_project_fields tool fails when trying to retrieve project fields that include single_select fields with options (e.g., Status, Priority, Size fields). I found this when creating a custom agent that has been granted the ability to create/update issues and move them around a project board by changing the status.

Error Message

failed to list project fields: json: cannot unmarshal object into Go struct field ProjectV2FieldOption.options.name of type string

Steps to Reproduce

  1. Create or use a GitHub Project (v2) that has a single_select field with options (e.g., Status field with Backlog, In Progress, Done, etc.)

  2. Call list_project_fields tool with the project details:

    owner_type: "user"
    owner: "<username>"
    project_number: <project_number>
    
  3. Observe the JSON unmarshal error

Expected Behavior

The tool should successfully return all project fields, including single_select fields with their options listed.

Actual Behavior

The tool fails with a JSON unmarshal error because it's trying to unmarshal the options structure incorrectly.

Root Cause

The GitHub GraphQL API returns options for single_select fields as an array of objects with this structure:

{
  "options": [
    {
      "id": "aeba538c",
      "name": "Backlog"
    },
    {
      "id": "f75ad846",
      "name": "Ready"
    }
  ]
}

However, the Go struct appears to be expecting options.name to be a simple string type instead of an object with id and name properties.

Workaround

Until this is fixed, I have been using the GitHub GraphQL API directly to retrieve field information and placing the result in the agent definition so that the agent does not need to call the list_project_fields tool:

query {
  user(login: "username") {
    projectV2(number: 4) {
      fields(first: 20) {
        nodes {
          ... on ProjectV2Field {
            id
            name
            dataType
            databaseId
          }
          ... on ProjectV2SingleSelectField {
            id
            name
            dataType
            databaseId
            options {
              id
              name
            }
          }
        }
      }
    }
  }
}

Suggested Fix

Update the Go struct definition for ProjectV2FieldOption to properly handle the options structure where each option is an object containing id and name fields, rather than expecting a simple string.

Environment

  • GitHub MCP Server version: [latest as of November 2025]
  • Affected tool: list_project_fields
  • I get the same error when I test locally in VS CODE and using the Coding Agent in GitHub with the same agent definition. </issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes github/github-mcp-server#1418

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

Copilot avatar Nov 26 '25 07:11 Copilot