Fix list_project_fields JSON unmarshal error for single_select fields
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 withUnmarshalJSONthat accepts either"Backlog"or{"raw": "Backlog", "html": "Backlog"}ProjectFieldtypes: Local structs usingFlexibleStringfor option names/descriptions- Raw API calls:
ListProjectFieldsandGetProjectFieldnow useclient.NewRequest/Dowith 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_fieldstool fails when trying to retrieve project fields that includesingle_selectfields 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 stringSteps to Reproduce
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.)
Call
list_project_fieldstool with the project details:owner_type: "user" owner: "<username>" project_number: <project_number>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.nameto be a simple string type instead of an object withidandnameproperties.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_fieldstool: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
ProjectV2FieldOptionto properly handle the options structure where each option is an object containingidandnamefields, 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.