github/github-mcp-server · error

failed to get GitHub client: %w

Error message

failed to get GitHub client: %w

What it means

deps.GetGQLClient(ctx) failed while starting the assign_copilot_to_issue tool. RequestDeps.GetGQLClient reads TokenInfo from the request context and resolves the GraphQL endpoint from the configured API host; it returns an error when the token is missing from the context (auth middleware did not attach it) or when the GraphQL URL cannot be derived (misconfigured GHES host / GITHUB_API_URL). The Copilot assignment never starts — no GraphQL query is sent.

Source

Thrown at pkg/github/copilot.go:218

				Required: []string{"owner", "repo", "issue_number"},
			},
		},
		[]scopes.Scope{scopes.Repo},
		func(ctx context.Context, deps ToolDependencies, request *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
			var params struct {
				Owner              string `mapstructure:"owner"`
				Repo               string `mapstructure:"repo"`
				IssueNumber        int32  `mapstructure:"issue_number"`
				BaseRef            string `mapstructure:"base_ref"`
				CustomInstructions string `mapstructure:"custom_instructions"`
			}
			if err := mapstructure.WeakDecode(args, &params); err != nil {
				return utils.NewToolResultError(err.Error()), nil, nil
			}

			client, err := deps.GetGQLClient(ctx)
			if err != nil {
				return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
			}

			// Firstly, we try to find the copilot bot in the suggested actors for the repository.
			// Although as I write this, we would expect copilot to be at the top of the list, in future, maybe
			// it will not be on the first page of responses, thus we will keep paginating until we find it.
			type botAssignee struct {
				ID       githubv4.ID
				Login    string
				TypeName string `graphql:"__typename"`
			}

			type suggestedActorsQuery struct {
				Repository struct {
					SuggestedActors struct {
						Nodes []struct {
							Bot botAssignee `graphql:"... on Bot"`
						}
						PageInfo struct {

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Set a valid token: export GITHUB_PERSONAL_ACCESS_TOKEN=ghp_... (or configure GitHub App / OAuth credentials) and restart the server
  2. Verify the API host configuration — for GHES check --gh-host/GITHUB_API_URL resolve to a reachable instance with GraphQL enabled
  3. If embedding, ensure the request context flows through the auth transport that attaches ghcontext.TokenInfo before tool handlers run
  4. Confirm with a REST-based tool (e.g. get_me) that auth works at all; if every tool fails the same way it is server-level auth, not Copilot

Example fix

# before
$ ./github-mcp-server stdio   # no token configured -> assign_copilot_to_issue fails with 'failed to get GitHub client: no token info in context'

# after
$ export GITHUB_PERSONAL_ACCESS_TOKEN="ghp_xxx"
$ ./github-mcp-server stdio
Defensive patterns

Strategy: validation

Validate before calling

// before invoking Copilot tools, confirm the server has a token source configured
func requireTokenEnv() error {
	if os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN") == "" &&
		os.Getenv("GITHUB_APP_ID") == "" {
		return fmt.Errorf("no GitHub token configured: set GITHUB_PERSONAL_ACCESS_TOKEN or App credentials before using Copilot tools")
	}
	return nil
}

Try / catch

client, err := deps.GetGQLClient(ctx)
if err != nil {
	switch {
	case strings.Contains(err.Error(), "no token info in context"):
		// fix auth configuration/server startup, do not retry
	case strings.Contains(err.Error(), "failed to get GraphQL URL"):
		// fix GHES host / GITHUB_API_URL configuration
	default:
		return fmt.Errorf("failed to get GitHub client: %w", err)
	}
}

Prevention

When it happens

Trigger: Invoking assign_copilot_to_issue when the server was started without a usable token source (no GITHUB_PERSONAL_ACCESS_TOKEN, GitHub App credentials failed to mint an installation token, OAuth exchange failure), or with an enterprise host whose GraphQL endpoint cannot be resolved (bad --gh-host / GITHUB_API_URL for GHES).

Common situations: Empty or missing GITHUB_PERSONAL_ACCESS_TOKEN env var, expired GitHub App installation, GHES hostname without API endpoints configured, embedding the server and dispatching tools with a context that never went through the auth transport that calls ghcontext.WithTokenInfo.

Related errors


AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15). Data as JSON: /api/errors/9dad54a5bc130587. Report an issue: GitHub.