github/github-mcp-server · error

failed to get GraphQL URL: %w

Error message

failed to get GraphQL URL: %w

What it means

GetGQLClient resolves the GraphQL endpoint through the injected utils.APIHostResolver; a resolver error becomes this wrap and no githubv4 client can be built. The bundled utils.APIHost computes gqlURL (https://api.github.com/graphql for dotcom, https://api.<host>/graphql for GHEC/GHES) at construction and never fails on lookup, so this error indicts a custom resolver or a misconfigured RequestDeps rather than GitHub itself.

Source

Thrown at pkg/github/dependencies.go:361

	}
	token := tokenInfo.Token

	// Construct GraphQL client
	// We use NewEnterpriseClient unconditionally since we already parsed the API host
	// Wrap transport with GraphQLFeaturesTransport to inject feature flags from context,
	// matching the transport chain used by the remote server.
	gqlHTTPClient := &http.Client{
		Transport: &transport.BearerAuthTransport{
			Transport: &transport.GraphQLFeaturesTransport{
				Transport: http.DefaultTransport,
			},
			Token: token,
		},
	}

	graphqlURL, err := d.apiHosts.GraphqlURL(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to get GraphQL URL: %w", err)
	}

	gqlClient := githubv4.NewEnterpriseClient(graphqlURL.String(), gqlHTTPClient)
	return gqlClient, nil
}

// GetRawClient implements ToolDependencies.
func (d *RequestDeps) GetRawClient(ctx context.Context) (*raw.Client, error) {
	client, err := d.GetClient(ctx)
	if err != nil {
		return nil, err
	}

	rawURL, err := d.apiHosts.RawURL(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to get Raw URL: %w", err)
	}

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. If GraphQL is genuinely unavailable in your environment, disable the GraphQL-dependent toolsets (discussions) rather than letting every call fail
  2. Make GraphqlURL return a pre-parsed absolute URL derived from the base host (api.<host>/graphql) and fail only at construction
  3. Preflight GraphqlURL at startup alongside the other resolver methods
  4. Read the wrapped message to distinguish resolver bugs from environment problems

Example fix

// before
func (r fake) GraphqlURL(ctx context.Context) (*url.URL, error) {
	return nil, errors.New("not implemented") // every GraphQL tool dies
}

// after
type r struct{ gql *url.URL }
func newR(base *url.URL) *r {
	return &r{gql: base.JoinPath("/graphql")} // https://api.example.com -> .../graphql
}
func (x r) GraphqlURL(context.Context) (*url.URL, error) { return x.gql, nil }
Defensive patterns

Strategy: validation

Validate before calling

// startup check for the GraphQL endpoint
gql, err := apiHosts.GraphqlURL(context.Background())
if err != nil || gql == nil || !gql.IsAbs() {
	log.Fatalf("GraphQL URL unusable: %v", err)
}

Type guard

func supportsGraphQL(a utils.APIHostResolver) bool {
	u, err := a.GraphqlURL(context.Background())
	return err == nil && u != nil && u.IsAbs()
}

Prevention

When it happens

Trigger: deps.GetGQLClient(ctx) with a custom APIHostResolver whose GraphqlURL(ctx) errors; resolvers for environments that do not expose GraphQL (some GHES configs have GraphQL disabled and an integrator may model that as an error); per-tenant resolvers failing to map a tenant to a host. Standard NewAPIHost wiring cannot produce it at request time.

Common situations: Internal gateways fronting GitHub where only REST is proxied; test fakes stubbing GraphqlURL with errors; partial implementations of the five-method APIHostResolver interface after adding a new deployment type.

Related errors


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