| 398 | } |
| 399 | |
| 400 | func addUserAgentsMiddleware(cfg github.MCPServerConfig, restUATransp *transport.UserAgentTransport, gqlHTTPClient *http.Client) func(next mcp.MethodHandler) mcp.MethodHandler { |
| 401 | return func(next mcp.MethodHandler) mcp.MethodHandler { |
| 402 | return func(ctx context.Context, method string, request mcp.Request) (result mcp.Result, err error) { |
| 403 | if method != "initialize" { |
| 404 | return next(ctx, method, request) |
| 405 | } |
| 406 | |
| 407 | initializeRequest, ok := request.(*mcp.InitializeRequest) |
| 408 | if !ok { |
| 409 | return next(ctx, method, request) |
| 410 | } |
| 411 | |
| 412 | message := initializeRequest |
| 413 | userAgent := fmt.Sprintf( |
| 414 | "github-mcp-server/%s (%s/%s)", |
| 415 | cfg.Version, |
| 416 | message.Params.ClientInfo.Name, |
| 417 | message.Params.ClientInfo.Version, |
| 418 | ) |
| 419 | if cfg.InsidersMode { |
| 420 | userAgent += " (insiders)" |
| 421 | } |
| 422 | |
| 423 | restUATransp.Agent = userAgent |
| 424 | |
| 425 | gqlHTTPClient.Transport = &transport.UserAgentTransport{ |
| 426 | Transport: gqlHTTPClient.Transport, |
| 427 | Agent: userAgent, |
| 428 | } |
| 429 | |
| 430 | return next(ctx, method, request) |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | // fetchTokenScopesForHost fetches the OAuth scopes for a token from the GitHub API. |
| 436 | // It constructs the appropriate API host URL based on the configured host. |