MCPcopy
hub / github.com/github/github-mcp-server / GetClient

Method GetClient

pkg/github/dependencies.go:305–332  ·  view source on GitHub ↗

GetClient implements ToolDependencies.

(ctx context.Context)

Source from the content-addressed store, hash-verified

303
304// GetClient implements ToolDependencies.
305func (d *RequestDeps) GetClient(ctx context.Context) (*gogithub.Client, error) {
306 // extract the token from the context
307 tokenInfo, ok := ghcontext.GetTokenInfo(ctx)
308 if !ok {
309 return nil, fmt.Errorf("no token info in context")
310 }
311 token := tokenInfo.Token
312
313 baseRestURL, err := d.apiHosts.BaseRESTURL(ctx)
314 if err != nil {
315 return nil, fmt.Errorf("failed to get base REST URL: %w", err)
316 }
317 uploadURL, err := d.apiHosts.UploadURL(ctx)
318 if err != nil {
319 return nil, fmt.Errorf("failed to get upload URL: %w", err)
320 }
321
322 // Construct REST client
323 restClient, err := gogithub.NewClient(
324 gogithub.WithAuthToken(token),
325 gogithub.WithUserAgent(fmt.Sprintf("github-mcp-server/%s", d.version)),
326 gogithub.WithEnterpriseURLs(baseRestURL.String(), uploadURL.String()),
327 )
328 if err != nil {
329 return nil, fmt.Errorf("failed to create REST client: %w", err)
330 }
331 return restClient, nil
332}
333
334// GetGQLClient implements ToolDependencies.
335func (d *RequestDeps) GetGQLClient(ctx context.Context) (*githubv4.Client, error) {

Callers 2

GetRawClientMethod · 0.95
GetRepoAccessCacheMethod · 0.95

Calls 3

BaseRESTURLMethod · 0.65
UploadURLMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected