github/github-mcp-server · error

failed to initialize tool scope map: %w

Error message

failed to initialize tool scope map: %w

What it means

initGlobalToolScopeMap failed while building the tool inventory (inventory.NewBuilder().SetTools(github.AllTools(...)).Build()) that feeds the global OAuth scope map. Build() validates every tool definition; a duplicate tool name, a tool missing required scope/annotation metadata, or an invalid definition makes the whole startup abort.

Source

Thrown at pkg/http/server.go:165

	if err != nil {
		return fmt.Errorf("failed to create observability exporters: %w", err)
	}

	deps := github.NewRequestDeps(
		apiHost,
		cfg.Version,
		cfg.LockdownMode,
		repoAccessOpts,
		t,
		cfg.ContentWindowSize,
		featureChecker,
		obs,
	)

	// Initialize the global tool scope map
	err = initGlobalToolScopeMap(t, hostType)
	if err != nil {
		return fmt.Errorf("failed to initialize tool scope map: %w", err)
	}

	// Register OAuth protected resource metadata endpoints
	oauthCfg := &oauth.Config{
		BaseURL:           cfg.BaseURL,
		ResourcePath:      cfg.ResourcePath,
		TrustProxyHeaders: cfg.TrustProxyHeaders,
	}

	serverOptions := []HandlerOption{}
	if cfg.ScopeChallenge {
		scopeFetcher := scopes.NewFetcher(apiHost, scopes.FetcherOptions{})
		serverOptions = append(serverOptions, WithScopeFetcher(scopeFetcher))
	}

	r := chi.NewRouter()
	handler := NewHTTPMcpHandler(ctx, &cfg, deps, t, logger, apiHost, append(serverOptions, WithFeatureChecker(featureChecker), WithOAuthConfig(oauthCfg))...)
	oauthHandler, err := oauth.NewAuthHandler(oauthCfg, apiHost)

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Read the wrapped 'failed to build inventory' error - it names the invalid tool
  2. Check recently added/modified tool definitions for duplicate names or missing required fields
  3. Run the server's tool inventory tests (go test ./pkg/...) before shipping
Defensive patterns

Strategy: try-catch

Validate before calling

// run as part of CI/startup smoke test
if err := initGlobalToolScopeMap(t, hostType); err != nil {
	log.Fatalf("tool inventory invalid, refusing to deploy: %v", err)
}

Try / catch

if err := initGlobalToolScopeMap(t, hostType); err != nil {
	// startup bug: log loudly and abort instead of serving a broken scope map
	logger.Error("tool scope map init failed", "error", err)
	return err
}

Prevention

When it happens

Trigger: Adding a new tool whose name collides with an existing one; registering a tool with incomplete scope metadata; a host-type filter producing an invalid tool set; programming errors introduced by tool-list refactors.

Common situations: Contributors adding tools to pkg/github without unique names or full definitions; vendors maintaining a forked tool inventory.

Related errors


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