Skip to content

Commit 0c77296

Browse files
iulia-bCopilot
andauthored
Upgrade go-github from v86 to v87
Breaking changes resolved: - NewClient now uses functional options pattern (returns (*Client, error)) - BaseURL/UploadURL/UserAgent are no longer settable fields - Use WithHTTPClient, WithAuthToken, WithEnterpriseURLs, WithUserAgent opts - Use UserAgentTransport for mutable user agent in middleware Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8da9972 commit 0c77296

57 files changed

Lines changed: 270 additions & 221 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/github/github-mcp-server/internal/ghmcp"
1919
"github.com/github/github-mcp-server/pkg/github"
2020
"github.com/github/github-mcp-server/pkg/translations"
21-
gogithub "github.com/google/go-github/v86/github"
21+
gogithub "github.com/google/go-github/v87/github"
2222
"github.com/modelcontextprotocol/go-sdk/mcp"
2323
"github.com/stretchr/testify/require"
2424
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.25.0
55
require (
66
github.com/go-chi/chi/v5 v5.2.5
77
github.com/go-viper/mapstructure/v2 v2.5.0
8-
github.com/google/go-github/v86 v86.0.0
8+
github.com/google/go-github/v87 v87.0.0
99
github.com/google/jsonschema-go v0.4.2
1010
github.com/josephburnett/jd/v2 v2.5.0
1111
github.com/lithammer/fuzzysearch v1.1.8

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArs
1616
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1717
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1818
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
19-
github.com/google/go-github/v86 v86.0.0 h1:S/6aANJhwRm8EQmGKVML3j41yq0h2BsTP8FnDkO7kcA=
20-
github.com/google/go-github/v86 v86.0.0/go.mod h1:zKv1l4SwDXNFMGByi2FWkq71KwSXqj/eQRZuqtmcot8=
19+
github.com/google/go-github/v87 v87.0.0 h1:9Ck3dcOxWJyfsN8tzdah4YvmqB/7ZsstMglv/PkOsl0=
20+
github.com/google/go-github/v87 v87.0.0/go.mod h1:hGUoT5pwm/ck5uLL+wroSVQfg8mpe+buxllCcGV4VaM=
2121
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
2222
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
2323
github.com/google/jsonschema-go v0.4.2 h1:tmrUohrwoLZZS/P3x7ex0WAVknEkBZM46iALbcqoRA8=

internal/ghmcp/server.go

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ import (
2424
"github.com/github/github-mcp-server/pkg/scopes"
2525
"github.com/github/github-mcp-server/pkg/translations"
2626
"github.com/github/github-mcp-server/pkg/utils"
27-
gogithub "github.com/google/go-github/v86/github"
27+
gogithub "github.com/google/go-github/v87/github"
2828
"github.com/modelcontextprotocol/go-sdk/mcp"
2929
"github.com/shurcooL/githubv4"
3030
)
3131

3232
// githubClients holds all the GitHub API clients created for a server instance.
3333
type githubClients struct {
34-
rest *gogithub.Client
35-
gql *githubv4.Client
36-
gqlHTTP *http.Client // retained for middleware to modify transport
37-
raw *raw.Client
38-
repoAccess *lockdown.RepoAccessCache
34+
rest *gogithub.Client
35+
restUATransp *transport.UserAgentTransport // retained for middleware to modify user agent
36+
gql *githubv4.Client
37+
gqlHTTP *http.Client // retained for middleware to modify transport
38+
raw *raw.Client
39+
repoAccess *lockdown.RepoAccessCache
3940
}
4041

4142
// createGitHubClients creates all the GitHub API clients needed by the server.
@@ -60,11 +61,22 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolv
6061
return nil, fmt.Errorf("failed to get Raw URL: %w", err)
6162
}
6263

64+
// Create a mutable user agent transport for the REST client so we can
65+
// update the user agent after MCP initialization.
66+
restUATransport := &transport.UserAgentTransport{
67+
Transport: http.DefaultTransport,
68+
Agent: fmt.Sprintf("github-mcp-server/%s", cfg.Version),
69+
}
70+
6371
// Construct REST client
64-
restClient := gogithub.NewClient(nil).WithAuthToken(cfg.Token)
65-
restClient.UserAgent = fmt.Sprintf("github-mcp-server/%s", cfg.Version)
66-
restClient.BaseURL = restURL
67-
restClient.UploadURL = uploadURL
72+
restClient, err := gogithub.NewClient(
73+
gogithub.WithHTTPClient(&http.Client{Transport: restUATransport}),
74+
gogithub.WithAuthToken(cfg.Token),
75+
gogithub.WithEnterpriseURLs(restURL.String(), uploadURL.String()),
76+
)
77+
if err != nil {
78+
return nil, fmt.Errorf("failed to create REST client: %w", err)
79+
}
6880

6981
// Construct GraphQL client
7082
// We use NewEnterpriseClient unconditionally since we already parsed the API host
@@ -80,7 +92,10 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolv
8092
gqlClient := githubv4.NewEnterpriseClient(graphQLURL.String(), gqlHTTPClient)
8193

8294
// Create raw content client (shares REST client's HTTP transport)
83-
rawClient := raw.NewClient(restClient, rawURL)
95+
rawClient, err := raw.NewClient(restClient, rawURL)
96+
if err != nil {
97+
return nil, fmt.Errorf("failed to create raw client: %w", err)
98+
}
8499

85100
// Set up repo access cache for lockdown mode
86101
var repoAccessCache *lockdown.RepoAccessCache
@@ -95,11 +110,12 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolv
95110
}
96111

97112
return &githubClients{
98-
rest: restClient,
99-
gql: gqlClient,
100-
gqlHTTP: gqlHTTPClient,
101-
raw: rawClient,
102-
repoAccess: repoAccessCache,
113+
rest: restClient,
114+
restUATransp: restUATransport,
115+
gql: gqlClient,
116+
gqlHTTP: gqlHTTPClient,
117+
raw: rawClient,
118+
repoAccess: repoAccessCache,
103119
}, nil
104120
}
105121

@@ -170,7 +186,7 @@ func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Se
170186
github.RegisterUIResources(ghServer)
171187
}
172188

173-
ghServer.AddReceivingMiddleware(addUserAgentsMiddleware(cfg, clients.rest, clients.gqlHTTP))
189+
ghServer.AddReceivingMiddleware(addUserAgentsMiddleware(cfg, clients.restUATransp, clients.gqlHTTP))
174190

175191
return ghServer, nil
176192
}
@@ -345,7 +361,7 @@ func createFeatureChecker(enabledFeatures []string, insidersMode bool) inventory
345361
}
346362
}
347363

348-
func addUserAgentsMiddleware(cfg github.MCPServerConfig, restClient *gogithub.Client, gqlHTTPClient *http.Client) func(next mcp.MethodHandler) mcp.MethodHandler {
364+
func addUserAgentsMiddleware(cfg github.MCPServerConfig, restUATransport *transport.UserAgentTransport, gqlHTTPClient *http.Client) func(next mcp.MethodHandler) mcp.MethodHandler {
349365
return func(next mcp.MethodHandler) mcp.MethodHandler {
350366
return func(ctx context.Context, method string, request mcp.Request) (result mcp.Result, err error) {
351367
if method != "initialize" {
@@ -368,7 +384,7 @@ func addUserAgentsMiddleware(cfg github.MCPServerConfig, restClient *gogithub.Cl
368384
userAgent += " (insiders)"
369385
}
370386

371-
restClient.UserAgent = userAgent
387+
restUATransport.Agent = userAgent
372388

373389
gqlHTTPClient.Transport = &transport.UserAgentTransport{
374390
Transport: gqlHTTPClient.Transport,

pkg/errors/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77

88
"github.com/github/github-mcp-server/pkg/utils"
9-
"github.com/google/go-github/v86/github"
9+
"github.com/google/go-github/v87/github"
1010
"github.com/modelcontextprotocol/go-sdk/mcp"
1111
)
1212

pkg/errors/error_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
"testing"
88

9-
"github.com/google/go-github/v86/github"
9+
"github.com/google/go-github/v87/github"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
)

pkg/github/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/github/github-mcp-server/pkg/scopes"
1717
"github.com/github/github-mcp-server/pkg/translations"
1818
"github.com/github/github-mcp-server/pkg/utils"
19-
"github.com/google/go-github/v86/github"
19+
"github.com/google/go-github/v87/github"
2020
"github.com/google/jsonschema-go/jsonschema"
2121
"github.com/modelcontextprotocol/go-sdk/mcp"
2222
)

pkg/github/actions_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/github/github-mcp-server/internal/toolsnaps"
1010
"github.com/github/github-mcp-server/pkg/translations"
11-
"github.com/google/go-github/v86/github"
11+
"github.com/google/go-github/v87/github"
1212
"github.com/google/jsonschema-go/jsonschema"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
@@ -86,7 +86,7 @@ func Test_ActionsList_ListWorkflows(t *testing.T) {
8686

8787
for _, tc := range tests {
8888
t.Run(tc.name, func(t *testing.T) {
89-
client := github.NewClient(tc.mockedClient)
89+
client := mustNewGHClient(t, tc.mockedClient)
9090
deps := BaseDeps{
9191
Client: client,
9292
}
@@ -136,7 +136,7 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
136136
}),
137137
})
138138

139-
client := github.NewClient(mockedClient)
139+
client := mustNewGHClient(t, mockedClient)
140140
deps := BaseDeps{
141141
Client: client,
142142
}
@@ -185,7 +185,7 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
185185
}),
186186
})
187187

188-
client := github.NewClient(mockedClient)
188+
client := mustNewGHClient(t, mockedClient)
189189
deps := BaseDeps{
190190
Client: client,
191191
}
@@ -241,7 +241,7 @@ func Test_ActionsGet_GetWorkflow(t *testing.T) {
241241
}),
242242
})
243243

244-
client := github.NewClient(mockedClient)
244+
client := mustNewGHClient(t, mockedClient)
245245
deps := BaseDeps{
246246
Client: client,
247247
}
@@ -284,7 +284,7 @@ func Test_ActionsGet_GetWorkflowRun(t *testing.T) {
284284
}),
285285
})
286286

287-
client := github.NewClient(mockedClient)
287+
client := mustNewGHClient(t, mockedClient)
288288
deps := BaseDeps{
289289
Client: client,
290290
}
@@ -381,7 +381,7 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
381381

382382
for _, tc := range tests {
383383
t.Run(tc.name, func(t *testing.T) {
384-
client := github.NewClient(tc.mockedClient)
384+
client := mustNewGHClient(t, tc.mockedClient)
385385
deps := BaseDeps{
386386
Client: client,
387387
}
@@ -418,7 +418,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
418418
}),
419419
})
420420

421-
client := github.NewClient(mockedClient)
421+
client := mustNewGHClient(t, mockedClient)
422422
deps := BaseDeps{
423423
Client: client,
424424
}
@@ -449,7 +449,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
449449
}),
450450
})
451451

452-
client := github.NewClient(mockedClient)
452+
client := mustNewGHClient(t, mockedClient)
453453
deps := BaseDeps{
454454
Client: client,
455455
}
@@ -473,7 +473,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
473473
t.Run("missing run_id for non-run_workflow methods", func(t *testing.T) {
474474
mockedClient := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{})
475475

476-
client := github.NewClient(mockedClient)
476+
client := mustNewGHClient(t, mockedClient)
477477
deps := BaseDeps{
478478
Client: client,
479479
}
@@ -525,7 +525,7 @@ func Test_ActionsGetJobLogs_SingleJob(t *testing.T) {
525525
}),
526526
})
527527

528-
client := github.NewClient(mockedClient)
528+
client := mustNewGHClient(t, mockedClient)
529529
deps := BaseDeps{
530530
Client: client,
531531
ContentWindowSize: 5000,
@@ -587,7 +587,7 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
587587
}),
588588
})
589589

590-
client := github.NewClient(mockedClient)
590+
client := mustNewGHClient(t, mockedClient)
591591
deps := BaseDeps{
592592
Client: client,
593593
ContentWindowSize: 5000,
@@ -637,7 +637,7 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
637637
}),
638638
})
639639

640-
client := github.NewClient(mockedClient)
640+
client := mustNewGHClient(t, mockedClient)
641641
deps := BaseDeps{
642642
Client: client,
643643
ContentWindowSize: 5000,

pkg/github/code_scanning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/github/github-mcp-server/pkg/scopes"
1212
"github.com/github/github-mcp-server/pkg/translations"
1313
"github.com/github/github-mcp-server/pkg/utils"
14-
"github.com/google/go-github/v86/github"
14+
"github.com/google/go-github/v87/github"
1515
"github.com/google/jsonschema-go/jsonschema"
1616
"github.com/modelcontextprotocol/go-sdk/mcp"
1717
)

pkg/github/code_scanning_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/github/github-mcp-server/internal/toolsnaps"
1010
"github.com/github/github-mcp-server/pkg/translations"
11-
"github.com/google/go-github/v86/github"
11+
"github.com/google/go-github/v87/github"
1212
"github.com/google/jsonschema-go/jsonschema"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
@@ -80,7 +80,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
8080
for _, tc := range tests {
8181
t.Run(tc.name, func(t *testing.T) {
8282
// Setup client with mock
83-
client := github.NewClient(tc.mockedClient)
83+
client := mustNewGHClient(t, tc.mockedClient)
8484
deps := BaseDeps{
8585
Client: client,
8686
}
@@ -206,7 +206,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
206206
for _, tc := range tests {
207207
t.Run(tc.name, func(t *testing.T) {
208208
// Setup client with mock
209-
client := github.NewClient(tc.mockedClient)
209+
client := mustNewGHClient(t, tc.mockedClient)
210210
deps := BaseDeps{
211211
Client: client,
212212
}

0 commit comments

Comments
 (0)