Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions internal/ghmcp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"time"

ghcontext "github.com/github/github-mcp-server/v2/pkg/context"
"github.com/github/github-mcp-server/v2/pkg/github"
"github.com/github/github-mcp-server/v2/pkg/observability"
"github.com/github/github-mcp-server/v2/pkg/observability/metrics"
Expand All @@ -36,14 +37,15 @@ func TestCreateGitHubClientsGraphQLUserAgent(t *testing.T) {
var query struct {
Viewer struct{ Login string }
}
require.NoError(t, clients.gql.Query(t.Context(), &query, nil))
require.NoError(t, clients.gql.Query(ghcontext.WithGraphQLFeatures(t.Context(), "test_feature"), &query, nil))
want := "github-mcp-server/v1.2.3"
if insiders {
want += " (insiders)"
}
header := <-headers
assert.Equal(t, want, header.Get("User-Agent"))
assert.Equal(t, "Bearer fixture-token", header.Get("Authorization"))
assert.Equal(t, "test_feature", header.Get("GraphQL-Features"))
})
}
}
Expand Down Expand Up @@ -235,7 +237,6 @@ func TestStdioGraphQLUserAgent(t *testing.T) {
case header := <-headers:
assert.Equal(t, tt.want, header.Get("User-Agent"))
assert.Equal(t, "Bearer fixture-token", header.Get("Authorization"))
assert.Equal(t, "issue_fields, repo_issue_fields", header.Get("GraphQL-Features"))
case <-ctx.Done():
t.Fatal("GraphQL request did not reach the local HTTP server")
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/github/issue_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"strconv"

ghcontext "github.com/github/github-mcp-server/v2/pkg/context"
ghErrors "github.com/github/github-mcp-server/v2/pkg/errors"
"github.com/github/github-mcp-server/v2/pkg/ifc"
"github.com/github/github-mcp-server/v2/pkg/inventory"
Expand Down Expand Up @@ -171,14 +170,13 @@ func ListIssueFields(t translations.TranslationHelperFunc) inventory.ServerTool
// If repo is provided, fields are scoped to that repository (inherited from its
// organization); otherwise fields are returned directly from the organization.
func fetchIssueFields(ctx context.Context, gqlClient *githubv4.Client, owner, repo string) ([]IssueField, error) {
ctxWithFeatures := ghcontext.WithGraphQLFeatures(ctx, "issue_fields", "repo_issue_fields")
if repo != "" {
var query issueFieldsRepoQuery
vars := map[string]any{
"owner": githubv4.String(owner),
"name": githubv4.String(repo),
}
if err := gqlClient.Query(ctxWithFeatures, &query, vars); err != nil {
if err := gqlClient.Query(ctx, &query, vars); err != nil {
return nil, err
}
return issueFieldsFromNodes(query.Repository.IssueFields.Nodes), nil
Expand All @@ -188,7 +186,7 @@ func fetchIssueFields(ctx context.Context, gqlClient *githubv4.Client, owner, re
vars := map[string]any{
"login": githubv4.String(owner),
}
if err := gqlClient.Query(ctxWithFeatures, &query, vars); err != nil {
if err := gqlClient.Query(ctx, &query, vars); err != nil {
return nil, err
}
return issueFieldsFromNodes(query.Organization.IssueFields.Nodes), nil
Expand Down
31 changes: 9 additions & 22 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"
"time"

ghcontext "github.com/github/github-mcp-server/v2/pkg/context"
ghErrors "github.com/github/github-mcp-server/v2/pkg/errors"
"github.com/github/github-mcp-server/v2/pkg/ifc"
"github.com/github/github-mcp-server/v2/pkg/inventory"
Expand Down Expand Up @@ -310,13 +309,12 @@ func resolveIssueRequestFieldValues(ctx context.Context, gqlClient *githubv4.Cli
return nil, nil, nil
}

ctxWithFeatures := ghcontext.WithGraphQLFeatures(ctx, "issue_fields", "repo_issue_fields")
var query issueFieldWriteMetadataQuery
vars := map[string]any{
"owner": githubv4.String(owner),
"repo": githubv4.String(repo),
}
if err := gqlClient.Query(ctxWithFeatures, &query, vars); err != nil {
if err := gqlClient.Query(ctx, &query, vars); err != nil {
return nil, nil, fmt.Errorf("failed to query issue fields metadata: %w", err)
}

Expand Down Expand Up @@ -406,8 +404,6 @@ func resolveIssueRequestFieldValues(ctx context.Context, gqlClient *githubv4.Cli
// fetchExistingIssueFieldValues retrieves the current field values for an issue
// as IssueRequestFieldValue entries, ready to be merged before an update.
func fetchExistingIssueFieldValues(ctx context.Context, gqlClient *githubv4.Client, owner, repo string, issueNumber int) ([]*github.IssueRequestFieldValue, error) {
ctxWithFeatures := ghcontext.WithGraphQLFeatures(ctx, "issue_fields", "repo_issue_fields")

var query struct {
Repository struct {
Issue struct {
Expand All @@ -424,7 +420,7 @@ func fetchExistingIssueFieldValues(ctx context.Context, gqlClient *githubv4.Clie
"number": githubv4.Int(issueNumber), // #nosec G115 - issue numbers are always small positive integers
}

if err := gqlClient.Query(ctxWithFeatures, &query, vars); err != nil {
if err := gqlClient.Query(ctx, &query, vars); err != nil {
return nil, fmt.Errorf("failed to fetch existing issue field values: %w", err)
}

Expand Down Expand Up @@ -2655,11 +2651,11 @@ var issueWriteFormParams = map[string]struct{}{
}

// issueWriteAwaitingFormResult builds the "awaiting form submission" stub
// returned when issue_write hands off to the MCP App form. The body is shared
// by IssueWrite and LegacyIssueWrite. The result is marked IsError=true so
// agents that bail on error don't claim success or chain dependent tool calls
// while the user is still interacting with the form; the host renders the UI
// regardless because rendering is keyed off the tool's _meta.ui resourceUri.
// returned when issue_write hands off to the MCP App form. The result is
// marked IsError=true so agents that bail on error don't claim success or
// chain dependent tool calls while the user is still interacting with the
// form; the host renders the UI regardless because rendering is keyed off the
// tool's _meta.ui resourceUri.
func issueWriteAwaitingFormResult(method, owner, repo string, issueNumber int) *mcp.CallToolResult {
var msg string
if method == "update" {
Expand All @@ -2684,12 +2680,7 @@ func issueWriteAwaitingFormResult(method, owner, repo string, issueNumber int) *
return utils.NewToolResultAwaitingFormSubmission(msg)
}

// IssueWrite is the FeatureFlagIssueFields-enabled variant of issue_write
// (with the issue_fields parameter). LegacyIssueWrite is served when the flag
// is off. Both register under the tool name "issue_write"; exactly one is
// active at a time via mutually exclusive feature-flag annotations. When the
// flag is removed, delete LegacyIssueWrite outright and drop the feature-flag
// fields on IssueWrite.
// IssueWrite creates the consolidated issue_write tool.
func IssueWrite(t translations.TranslationHelperFunc) inventory.ServerTool {
st := NewTool[IssueWriteInput, *IssueWriteOutput](
ToolsetMetadataIssues,
Expand Down Expand Up @@ -3958,11 +3949,7 @@ func ListIssues(t translations.TranslationHelperFunc) inventory.ServerTool {
}

issueQuery := getIssueQueryType(hasLabels, hasSince)
// The list_issues query references the issue_fields-gated IssueFieldValueFilter
// input type unconditionally, so we always opt into the feature via header. This
// is a no-op once the flags are globally rolled out.
ctxWithFeatures := ghcontext.WithGraphQLFeatures(ctx, "issue_fields", "repo_issue_fields")
issueFieldsErr := client.Query(ctxWithFeatures, issueQuery, vars)
issueFieldsErr := client.Query(ctx, issueQuery, vars)

var resp MinimalIssuesResponse
var isPrivate bool
Expand Down
6 changes: 2 additions & 4 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4375,15 +4375,13 @@ func Test_ListIssues_FieldFilters(t *testing.T) {
require.False(t, res.IsError, getTextResult(t, res).Text)
})

t.Run("sends GraphQL-Features: issue_fields, repo_issue_fields header", func(t *testing.T) {
t.Run("does not send a GraphQL-Features header", func(t *testing.T) {
vars := baseVars()
vars["issueFieldValues"] = []any{}
matcher := githubv4mock.NewQueryMatcher(qNoLabels, vars, response)

// Build a transport chain matching production: GraphQLFeaturesTransport
// wraps a header-capturing spy, which forwards to the mock's RoundTripper.
// This verifies the handler sets the issue_fields context value and the
// transport translates it into the outgoing header.
mockClient := githubv4mock.NewMockedHTTPClient(matcher)
spy := &headerCaptureTransport{inner: mockClient.Transport}
httpClient := &http.Client{
Expand All @@ -4397,7 +4395,7 @@ func Test_ListIssues_FieldFilters(t *testing.T) {
res, err := handler(ContextWithDeps(context.Background(), deps), &req)
require.NoError(t, err)
require.False(t, res.IsError, getTextResult(t, res).Text)
assert.Equal(t, "issue_fields, repo_issue_fields", spy.captured.Get(headers.GraphQLFeaturesHeader))
assert.Empty(t, spy.captured.Get(headers.GraphQLFeaturesHeader))
})
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/github/projects_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strconv"
"strings"

ghcontext "github.com/github/github-mcp-server/v2/pkg/context"
ghErrors "github.com/github/github-mcp-server/v2/pkg/errors"
"github.com/shurcooL/githubv4"
)
Expand Down Expand Up @@ -336,15 +335,14 @@ func resolveIssueFieldForUpdate(ctx context.Context, gqlClient *githubv4.Client,
}

var conn projectIssueFieldMetadataConnection
ctxWithFeatures := ghcontext.WithGraphQLFeatures(ctx, "issue_fields")
var queryErr error
if ownerType == "org" {
var q projectIssueFieldMetadataQueryOrg
queryErr = gqlClient.Query(ctxWithFeatures, &q, vars)
queryErr = gqlClient.Query(ctx, &q, vars)
conn = q.Organization.ProjectV2.Fields
} else {
var q projectIssueFieldMetadataQueryUser
queryErr = gqlClient.Query(ctxWithFeatures, &q, vars)
queryErr = gqlClient.Query(ctx, &q, vars)
conn = q.User.ProjectV2.Fields
}
if queryErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/projects_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func Test_ResolveIssueFieldForUpdate(t *testing.T) {
if tt.wantOption.ID != "" {
assert.Equal(t, []ResolvedFieldOption{tt.wantOption}, field.Options)
}
assert.Equal(t, "issue_fields", capture.captured.Get(headers.GraphQLFeaturesHeader))
assert.Empty(t, capture.captured.Get(headers.GraphQLFeaturesHeader))
})
}
}
Expand Down
Loading