googleapis/mcp-toolbox · error

unable to create new client: %w

Error message

unable to create new client: %w

What it means

initSpannerClient (internal/sources/spanner/spanner.go:217) calls spanner.NewClientWithConfig to build a database client. Failure here — typically from connectivity, authentication, or an invalid database path — is wrapped as "unable to create new client". The client is created during source Initialize, so this error usually surfaces at server/toolbox startup.

Source

Thrown at internal/sources/spanner/spanner.go:217

	return results, nil
}

func initSpannerClient(ctx context.Context, tracer trace.Tracer, name, project, instance, dbname string) (*spanner.Client, error) {
	//nolint:all // Reassigned ctx
	ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
	defer span.End()

	// Configure the connection to the database
	db := fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instance, dbname)

	// Create spanner client
	userAgent, err := util.UserAgentFromContext(ctx)
	if err != nil {
		return nil, err
	}
	client, err := spanner.NewClientWithConfig(ctx, db, spanner.ClientConfig{UserAgent: userAgent})
	if err != nil {
		return nil, fmt.Errorf("unable to create new client: %w", err)
	}

	return client, nil
}

func (s *Source) InvokeSearchCatalog(ctx context.Context, params map[string]any, tokenStr string) ([]searchcatalog.DataplexSearchResponse, error) {
	typeMap := map[string]string{
		"cloud-spanner-instance": "SERVICE",
		"cloud-spanner-database": "DATABASE",
		"cloud-spanner-table":    "TABLE",
		"cloud-spanner-view":     "VIEW",
	}
	return searchcatalog.InvokeSearchCatalog(
		ctx,
		params,
		tokenStr,
		"CLOUD_SPANNER",
		"databaseIds",

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the database path format: projects/<proj>/instances/<inst>/database/<db> fields all exist
  2. Authenticate: run `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account key
  3. Confirm the project/instance/database exist via `gcloud spanner databases list --instance=<inst>`
  4. Check network/DNS egress to spanner.googleapis.com:443
  5. Enable the Spanner Admin/Data APIs on the project
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight before Initialize
matches := regexp.MustCompile(`^projects/[^/]+/instances/[^/]+/databases/[^/]+$`).FindString(dsn)
if matches == "" { log.Fatal("invalid spanner database path") }
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" { log.Fatal("no ADC credentials configured") }

Prevention

When it happens

Trigger: Calling Initialize for the Spanner source where spanner.NewClientWithConfig fails: wrong project/instance/database in the DSN, missing Application Default Credentials, network egress blocked, or the database does not exist.

Common situations: Misconfigured project/instance/db names in the toolbox config; GOOGLE_APPLICATION_CREDENTIALS unset or pointing to a bad keyfile; running on-prem without access to Google APIs; typo in database path format projects/p/instances/i/databases/d.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/fe4e7712c6fae02f. Report an issue: GitHub.