googleapis/mcp-toolbox · error

failed to list materialized views: %w

Error message

failed to list materialized views: %w

What it means

ListMaterializedViews wraps any error returned by the Cloud Bigtable InstanceAdmin client's MaterializedViews() call with context. It means the admin RPC listing materialized views for the instance failed (auth, permissions, network, or unknown instance). The original gRPC/API error is preserved via %w for errors.Is/As inspection.

Source

Thrown at internal/sources/bigtable/admin_wrappers.go:200

	view, err := s.InstanceAdmin.LogicalViewInfo(ctx, instanceId, logicalViewId)
	if err != nil {
		return nil, fmt.Errorf("failed to get logical view: %w", err)
	}
	return view, nil
}

func (s *Source) ListLogicalViews(ctx context.Context, instanceId string) (any, error) {
	views, err := s.InstanceAdmin.LogicalViews(ctx, instanceId)
	if err != nil {
		return nil, fmt.Errorf("failed to list logical views: %w", err)
	}
	return views, nil
}

func (s *Source) ListMaterializedViews(ctx context.Context, instanceId string) (any, error) {
	views, err := s.InstanceAdmin.MaterializedViews(ctx, instanceId)
	if err != nil {
		return nil, fmt.Errorf("failed to list materialized views: %w", err)
	}
	return views, nil
}

func (s *Source) CreateLogicalView(ctx context.Context, instanceId, logicalViewId, query string) (any, error) {
	conf := &bigtable.LogicalViewInfo{
		LogicalViewID: logicalViewId,
		Query:         query,
	}
	err := s.InstanceAdmin.CreateLogicalView(ctx, instanceId, conf)
	if err != nil {
		return nil, fmt.Errorf("failed to create logical view: %w", err)
	}
	return map[string]string{"status": "logical view created successfully"}, nil
}

func (s *Source) UpdateLogicalView(ctx context.Context, instanceId, logicalViewId, query string) (any, error) {
	conf := bigtable.LogicalViewInfo{ // MUST be value per bigtable SDK

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Unwrap the wrapped error with errors.As(*googleapi.Error) or status.Code to see the underlying gRPC status and address its cause
  2. Verify the instance ID and project in the toolbox config match an existing Bigtable instance (gcloud bigtable instances list)
  3. Grant the caller service account roles/bigtable.admin or at minimum bigtable.tables.get/list on the instance
  4. Ensure Application Default Credentials are set (GOOGLE_APPLICATION_CREDENTIALS or gcloud auth application-default login)
  5. Retry on transient codes (Unavailable, DeadlineExceeded)

Example fix

// before: opaque listing failure
views, err := s.InstanceAdmin.MaterializedViews(ctx, instanceId)
if err != nil { return nil, fmt.Errorf("failed to list materialized views: %w", err) }
// after: surface status code for actionable handling
views, err := s.InstanceAdmin.MaterializedViews(ctx, instanceId)
if err != nil {
    if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {
        return nil, fmt.Errorf("instance %q not found: %w", instanceId, err)
    }
    return nil, fmt.Errorf("failed to list materialized views: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

// pre-flight: confirm instance is reachable before calling the tool
import "cloud.google.com/go/bigtable"
admin, err := bigtable.NewInstanceAdminClient(ctx, project)
if err != nil { return err }
instances, err := admin.Instances(ctx)
for _, i := range instances { if i.Name == instanceId { return nil } }
return fmt.Errorf("instance %q not found in project %s", instanceId, project)

Type guard

func isNotFound(err error) bool {
    st, ok := status.FromError(errors.Unwrap(err))
    return ok && st.Code() == codes.NotFound
}

Try / catch

views, err := src.ListMaterializedViews(ctx, instanceId)
if err != nil {
    if isNotFound(err) {
        return nil, fmt.Errorf("instance %q not found", instanceId)
    }
    if status.Code(err) == codes.Unavailable {
        // retry with backoff
    }
    return err
}

Prevention

When it happens

Trigger: Calling ListMaterializedViews (bigtable_list_materialized_views tool) when: the project/instance ID does not exist, the credentials lack bigtable.tables.list / materialized view list permission, ADC are missing, or a transient gRPC/network failure occurs during the InstanceAdmin.MaterializedViews RPC.

Common situations: Typo'd instance ID in tool parameters; service account without the Bigtable Admin role; running locally without GOOGLE_APPLICATION_CREDENTIALS; regional outages or timeouts; listing views on an instance in a different project than configured in the source config.

Related errors


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