GetClient implements ToolDependencies.
(ctx context.Context)
| 303 | |
| 304 | // GetClient implements ToolDependencies. |
| 305 | func (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. |
| 335 | func (d *RequestDeps) GetGQLClient(ctx context.Context) (*githubv4.Client, error) { |
no test coverage detected