googleapis/mcp-toolbox · error
error listing databases: %w
Error message
error listing databases: %w
What it means
Thrown in ListDatabase when the sqladmin Databases.List call (projects.instances.databases.list) fails. Listing databases for an instance returned an API error before the code could normalize resp.Items to an empty slice.
Source
Thrown at internal/sources/cloudsqladmin/cloud_sql_admin.go:249
return nil, err
}
resp, err := service.Instances.Get(projectId, instanceId).Do()
if err != nil {
return nil, fmt.Errorf("error getting instance: %w", err)
}
return resp, nil
}
func (s *Source) ListDatabase(ctx context.Context, project, instance, accessToken string) (any, error) {
service, err := s.GetService(ctx, accessToken)
if err != nil {
return nil, err
}
resp, err := service.Databases.List(project, instance).Do()
if err != nil {
return nil, fmt.Errorf("error listing databases: %w", err)
}
if resp.Items == nil {
return []any{}, nil
}
type databaseInfo struct {
Name string `json:"name"`
Charset string `json:"charset"`
Collation string `json:"collation"`
}
var databases []databaseInfo
for _, item := range resp.Items {
databases = append(databases, databaseInfo{
Name: item.Name,
Charset: item.Charset,
Collation: item.Collation,View on GitHub (pinned to 8cc6e09de2)
Solutions
- Confirm the instance exists and is runnable (get_instance).
- Fix the project ID and re-run.
- Grant roles/cloudsql.viewer to the calling principal.
- Retry on transient 5xx errors with backoff.
- Inspect the wrapped googleapi.Error code for the exact failure reason.
Example fix
null
Defensive patterns
Strategy: retry
Validate before calling
if instance == "" {
return fmt.Errorf("instance is required to list databases")
}
// verify instance exists first
if _, err := src.GetInstance(ctx, project, instance, token); err != nil {
return fmt.Errorf("cannot list databases; instance unavailable: %w", err)
} Type guard
func isRetryable(err error) bool {
var gerr *googleapi.Error
if errors.As(err, &gerr) {
return gerr.Code == 429 || gerr.Code >= 500
}
return false
} Try / catch
var out any
var err error
for attempt := 0; attempt < 3; attempt++ {
out, err = src.ListDatabase(ctx, project, instance, token)
if err == nil || !isRetryable(err) {
break
}
time.Sleep(time.Duration(1<<attempt) * time.Second)
}
if err != nil {
return fmt.Errorf("list databases failed after retries: %w", err)
} Prevention
- Retry transient 429/5xx with exponential backoff.
- Verify the instance exists and is RUNNABLE before listing.
- Grant roles/cloudsql.viewer to the calling principal.
- Handle empty result gracefully — the library already returns []any{} when there are no databases.
When it happens
Trigger: Calling the list_databases tool against a non-existent instance, wrong project, or with a principal lacking cloudsql.databases.list permission.
Common situations: Instance deleted between tool selection and invocation; project ID mismatch; service account missing roles/cloudsql.viewer; transient 500/503 from the Cloud SQL API.
Related errors
- error listing instances: %w
- error cloning instance: %w
- error creating database: %w
- error creating user: %w
- error getting instance: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/ea693d7e95a144f3.
Report an issue: GitHub.