Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding Case-insensitive matching and fields + field_names guard
  • Loading branch information
veralizeth committed Jul 6, 2026
commit 8051819b450ee24c1c7977b3c3475614c2c3aed1
6 changes: 6 additions & 0 deletions pkg/github/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ Use this tool to get details about individual projects, project fields, and proj
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
if len(fields) > 0 && len(fieldNames) > 0 {
return utils.NewToolResultError("provide either 'fields' or 'field_names', not both"), nil, nil
}
if len(fieldNames) > 0 {
gqlClient, gqlErr := deps.GetGQLClient(ctx)
if gqlErr != nil {
Expand Down Expand Up @@ -955,6 +958,9 @@ func listProjectItems(ctx context.Context, client *github.Client, gqlClient *git
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
if len(fields) > 0 && len(fieldNames) > 0 {
return utils.NewToolResultError("provide either 'fields' or 'field_names', not both"), nil, nil
}
if len(fieldNames) > 0 {
resolvedIDs, resolveErr := resolveFieldNamesToIDs(ctx, gqlClient, owner, ownerType, projectNumber, fieldNames)
if resolveErr != nil {
Expand Down
11 changes: 7 additions & 4 deletions pkg/github/projects_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strconv"
"strings"

ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/shurcooL/githubv4"
Expand Down Expand Up @@ -160,7 +161,7 @@ func resolveProjectFieldByName(ctx context.Context, gqlClient *githubv4.Client,

var matches []ResolvedField
for _, f := range all {
if f.Name == fieldName {
if strings.EqualFold(f.Name, fieldName) {
matches = append(matches, f)
}
}
Expand Down Expand Up @@ -228,7 +229,7 @@ func resolveSingleSelectOptionByName(field *ResolvedField, optionName string) (s

var matchIDs []string
for _, o := range field.Options {
if o.Name == optionName {
if strings.EqualFold(o.Name, optionName) {
matchIDs = append(matchIDs, o.ID)
}
}
Expand Down Expand Up @@ -343,14 +344,16 @@ func resolveFieldNamesToIDs(ctx context.Context, gqlClient *githubv4.Client, own
}

// Build a name -> []ResolvedField map so we can detect duplicates per name.
// Matching is case-insensitive to align with the GraphQL API's behaviour.
byName := make(map[string][]ResolvedField, len(all))
for _, f := range all {
byName[f.Name] = append(byName[f.Name], f)
key := strings.ToLower(f.Name)
byName[key] = append(byName[key], f)
}

out := make([]int64, 0, len(names))
for _, name := range names {
matches := byName[name]
matches := byName[strings.ToLower(name)]
switch len(matches) {
case 0:
candidates := make([]any, 0, len(all))
Expand Down
47 changes: 47 additions & 0 deletions pkg/github/projects_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,53 @@ func Test_ResolveFieldNamesToIDs_Success(t *testing.T) {
assert.Equal(t, []int64{100, 200}, ids)
}

// Field and single-select option name matching is case-insensitive so agents passing lowercase
// names like "status" or "in progress" resolve to "Status" and "In Progress" respectively.
func Test_ResolveProjectFieldByName_CaseInsensitive(t *testing.T) {
mocked := githubv4mock.NewMockedHTTPClient(
githubv4mock.NewQueryMatcher(
projectFieldsTestQuery{},
fieldsQueryVars("octo-org", 7),
githubv4mock.DataResponse(fieldsResponse([]map[string]any{
statusFieldNode("PVTSSF_lADOBBcDeFg123", 12345, "Status", []map[string]any{
{"id": "OPT_a", "name": "Todo"},
{"id": "OPT_b", "name": "In Progress"},
}),
})),
),
)
gql := githubv4.NewClient(mocked)

field, err := resolveProjectFieldByName(context.Background(), gql, "octo-org", "org", 7, "status", "")
require.NoError(t, err)
require.NotNil(t, field)
assert.Equal(t, "12345", field.ID)

optionID, err := resolveSingleSelectOptionByName(field, "in progress")
require.NoError(t, err)
assert.Equal(t, "OPT_b", optionID)
}

// Test_ResolveFieldNamesToIDs_CaseInsensitive verifies bulk name resolution
// also matches case-insensitively.
func Test_ResolveFieldNamesToIDs_CaseInsensitive(t *testing.T) {
mocked := githubv4mock.NewMockedHTTPClient(
githubv4mock.NewQueryMatcher(
projectFieldsTestQuery{},
fieldsQueryVars("octo-org", 1),
githubv4mock.DataResponse(fieldsResponse([]map[string]any{
statusFieldNode("PVTSSF_lADOBBcDeFg100", 100, "Status", nil),
statusFieldNode("PVTSSF_lADOBBcDeFg200", 200, "Priority", nil),
})),
),
)
gql := githubv4.NewClient(mocked)

ids, err := resolveFieldNamesToIDs(context.Background(), gql, "octo-org", "org", 1, []string{"status", "PRIORITY"})
require.NoError(t, err)
assert.Equal(t, []int64{100, 200}, ids)
}

// Test_ProjectsWrite_UpdateProjectItem_ByName is the acceptance test for the
// write side: set Status = "In Progress" using only names plus an issue number.
func Test_ProjectsWrite_UpdateProjectItem_ByName(t *testing.T) {
Expand Down
47 changes: 47 additions & 0 deletions pkg/github/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,29 @@ func Test_ProjectsList_ListProjectItems(t *testing.T) {
require.True(t, ok)
assertMinimalPullRequestProjectItem(t, textContent.Text, item)
})

t.Run("rejects fields and field_names together", func(t *testing.T) {
mockedClient := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{})
client := mustNewGHClient(t, mockedClient)
deps := BaseDeps{
Client: client,
}
handler := toolDef.Handler(deps)
request := createMCPRequest(map[string]any{
"method": "list_project_items",
"owner": "octo-org",
"owner_type": "org",
"project_number": float64(1),
"fields": []any{"100"},
"field_names": []any{"Status"},
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)

require.NoError(t, err)
require.True(t, result.IsError)
textContent := getTextResult(t, result)
assert.Contains(t, textContent.Text, "provide either 'fields' or 'field_names', not both")
})
}

func Test_detectOwnerType(t *testing.T) {
Expand Down Expand Up @@ -811,6 +834,30 @@ func Test_ProjectsGet_GetProjectItem(t *testing.T) {
textContent := getTextResult(t, result)
assert.Contains(t, textContent.Text, "missing required parameter: item_id")
})

t.Run("rejects fields and field_names together", func(t *testing.T) {
mockedClient := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{})
client := mustNewGHClient(t, mockedClient)
deps := BaseDeps{
Client: client,
}
handler := toolDef.Handler(deps)
request := createMCPRequest(map[string]any{
"method": "get_project_item",
"owner": "octo-org",
"owner_type": "org",
"project_number": float64(1),
"item_id": float64(1001),
"fields": []any{"100"},
"field_names": []any{"Status"},
})
result, err := handler(ContextWithDeps(context.Background(), deps), &request)

require.NoError(t, err)
require.True(t, result.IsError)
textContent := getTextResult(t, result)
assert.Contains(t, textContent.Text, "provide either 'fields' or 'field_names', not both")
})
}

func Test_ProjectsWrite(t *testing.T) {
Expand Down
Loading