googleapis/mcp-toolbox · error

failed to count relationship type %q: %w

Error message

failed to count relationship type %q: %w

What it means

This error occurs in extractRelationships when counting edges of a specific relationship type. After listing relationship types, the tool runs 'MATCH ()-[r:`<type>`]->() RETURN count(r)' per type; any query failure is wrapped with the failing relationship type name. The type name is escaped into backticks, so the underlying cause is a driver/query error, not a naming issue.

Source

Thrown at internal/tools/falkordb/falkordbschema/falkordbschema.go:338

	return nodeLabels, nil
}

// extractRelationships lists the relationship types and derives each type's
// count, most common connectivity pattern, and property shapes from a sample
// of relationships.
func (t Tool) extractRelationships(ctx context.Context, source compatibleSource) ([]types.Relationship, error) {
	typesResult, err := runReadQuery(ctx, source, "CALL db.relationshipTypes()")
	if err != nil {
		return nil, fmt.Errorf("failed to list relationship types: %w", err)
	}

	var relationships []types.Relationship
	for _, relType := range helpers.FirstColumnStrings(typesResult) {
		escaped := escapeIdentifier(relType)

		countResult, err := runReadQuery(ctx, source, fmt.Sprintf("MATCH ()-[r:`%s`]->() RETURN count(r) AS count", escaped))
		if err != nil {
			return nil, fmt.Errorf("failed to count relationship type %q: %w", relType, err)
		}

		sampleResult, err := runReadQuery(ctx, source, fmt.Sprintf(
			"MATCH (a)-[r:`%s`]->(b) RETURN labels(a) AS startLabels, labels(b) AS endLabels, r LIMIT %d", escaped, t.Cfg.SampleSize))
		if err != nil {
			return nil, fmt.Errorf("failed to sample relationship type %q: %w", relType, err)
		}

		accumulator := make(map[string]map[string]bool)
		connectivity := make(map[types.RelConnectivityInfo]int64)
		for _, row := range helpers.Rows(sampleResult) {
			if edge, ok := row["r"].(map[string]any); ok {
				if properties, ok := edge["properties"].(map[string]any); ok {
					helpers.MergeProperties(accumulator, properties)
				}
			}
			pattern := types.RelConnectivityInfo{
				StartNode: firstString(row["startLabels"]),

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check server logs and the wrapped cause to identify the driver-level failure.
  2. Increase query timeout settings if the count times out on large graphs.
  3. Verify connection stability/auth between toolbox and FalkorDB.
  4. Re-run the schema tool; consider sampling instead of exact counts for very large graphs.

Example fix

// before: timeout counting large relationship type
// after: increase client timeout in source config
source:
  kind: falkordb
  address: localhost:6379
  # ensure adequate timeout for count(r) on large graphs
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check the relationship type count query manually
// MATCH ()-[r:`TYPE`]->() RETURN count(r) LIMIT 1 — verify it executes under your timeout budget

Type guard

func isTimeout(err error) bool {
    var ne net.Error
    return errors.As(err, &ne) && ne.Timeout()
}

Try / catch

rel, err := extractOne(ctx, src, relType)
if err != nil {
    if isTimeout(err) {
        rel, err = retryWithBackoff(3, func() error { _, err = extractOne(ctx, src, relType); return err })
    }
    if err != nil { return fmt.Errorf("type %s: %w", relType, err) }
}

Prevention

When it happens

Trigger: runReadQuery fails on the count query for a relationship type returned by db.relationshipTypes(): connection drop mid-schema-extraction, auth failure, server timeout, or backend error executing the count aggregation.

Common situations: Large graphs where the count query times out; connection pool exhaustion while iterating many relationship types; server restarted between queries; read-only replica rejecting the query.

Related errors


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