@@ -36,12 +36,32 @@ type githubClients struct {
3636}
3737
3838// createGitHubClients creates all the GitHub API clients needed by the server.
39- func createGitHubClients (cfg github.MCPServerConfig , apiHost utils.APIHost ) (* githubClients , error ) {
39+ func createGitHubClients (cfg github.MCPServerConfig , apiHost utils.APIHostResolver ) (* githubClients , error ) {
40+ restURL , err := apiHost .BaseRESTURL (context .Background ())
41+ if err != nil {
42+ return nil , fmt .Errorf ("failed to get base REST URL: %w" , err )
43+ }
44+
45+ uploadURL , err := apiHost .UploadURL (context .Background ())
46+ if err != nil {
47+ return nil , fmt .Errorf ("failed to get upload URL: %w" , err )
48+ }
49+
50+ graphQLURL , err := apiHost .GraphqlURL (context .Background ())
51+ if err != nil {
52+ return nil , fmt .Errorf ("failed to get GraphQL URL: %w" , err )
53+ }
54+
55+ rawURL , err := apiHost .RawURL (context .Background ())
56+ if err != nil {
57+ return nil , fmt .Errorf ("failed to get Raw URL: %w" , err )
58+ }
59+
4060 // Construct REST client
4161 restClient := gogithub .NewClient (nil ).WithAuthToken (cfg .Token )
4262 restClient .UserAgent = fmt .Sprintf ("github-mcp-server/%s" , cfg .Version )
43- restClient .BaseURL = apiHost . BaseRESTURL
44- restClient .UploadURL = apiHost . UploadURL
63+ restClient .BaseURL = restURL
64+ restClient .UploadURL = uploadURL
4565
4666 // Construct GraphQL client
4767 // We use NewEnterpriseClient unconditionally since we already parsed the API host
@@ -51,10 +71,11 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHost) (*gi
5171 Token : cfg .Token ,
5272 },
5373 }
54- gqlClient := githubv4 .NewEnterpriseClient (apiHost .GraphqlURL .String (), gqlHTTPClient )
74+
75+ gqlClient := githubv4 .NewEnterpriseClient (graphQLURL .String (), gqlHTTPClient )
5576
5677 // Create raw content client (shares REST client's HTTP transport)
57- rawClient := raw .NewClient (restClient , apiHost . RawURL )
78+ rawClient := raw .NewClient (restClient , rawURL )
5879
5980 // Set up repo access cache for lockdown mode
6081 var repoAccessCache * lockdown.RepoAccessCache
@@ -78,7 +99,7 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHost) (*gi
7899}
79100
80101func NewStdioMCPServer (cfg github.MCPServerConfig ) (* mcp.Server , error ) {
81- apiHost , err := utils .ParseAPIHost (cfg .Host )
102+ apiHost , err := utils .NewAPIHost (cfg .Host )
82103 if err != nil {
83104 return nil , fmt .Errorf ("failed to parse API host: %w" , err )
84105 }
@@ -308,13 +329,18 @@ func addUserAgentsMiddleware(cfg github.MCPServerConfig, restClient *gogithub.Cl
308329// fetchTokenScopesForHost fetches the OAuth scopes for a token from the GitHub API.
309330// It constructs the appropriate API host URL based on the configured host.
310331func fetchTokenScopesForHost (ctx context.Context , token , host string ) ([]string , error ) {
311- apiHost , err := utils .ParseAPIHost (host )
332+ apiHost , err := utils .NewAPIHost (host )
312333 if err != nil {
313334 return nil , fmt .Errorf ("failed to parse API host: %w" , err )
314335 }
315336
337+ baseRestURL , err := apiHost .BaseRESTURL (ctx )
338+ if err != nil {
339+ return nil , fmt .Errorf ("failed to get base REST URL: %w" , err )
340+ }
341+
316342 fetcher := scopes .NewFetcher (scopes.FetcherOptions {
317- APIHost : apiHost . BaseRESTURL .String (),
343+ APIHost : baseRestURL .String (),
318344 })
319345
320346 return fetcher .FetchTokenScopes (ctx , token )
0 commit comments