siyuan-note/siyuan · error

JSON node count exceeds %d

Error message

JSON node count exceeds %d

What it means

Thrown by validateJSONComplexity when the total node count (every map, array element, and scalar visited by the recursive walk) exceeds maxNodes. For schemas the limit is maxToolSchemaNodes=16384 (16<<10); for values it is maxToolValueNodes=262144 (256<<10). This bounds the work the validator must perform.

Source

Thrown at kernel/mcp/tools/validation.go:199

	case err := <-result:
		return err
	case <-ctx.Done():
		return ctx.Err()
	case <-timer.C:
		return fmt.Errorf("validation exceeded %s", toolValidationTime)
	}
}

func validateJSONComplexity(value any, maxDepth, maxNodes int) error {
	nodes := 0
	var walk func(any, int) error
	walk = func(current any, depth int) error {
		if depth > maxDepth {
			return fmt.Errorf("JSON depth exceeds %d", maxDepth)
		}
		nodes++
		if nodes > maxNodes {
			return fmt.Errorf("JSON node count exceeds %d", maxNodes)
		}
		switch typed := current.(type) {
		case map[string]any:
			for _, child := range typed {
				if err := walk(child, depth+1); err != nil {
					return err
				}
			}
		case []any:
			for _, child := range typed {
				if err := walk(child, depth+1); err != nil {
					return err
				}
			}
		}
		return nil
	}
	return walk(value, 0)

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Paginate or chunk large arrays so each call stays under the node budget.
  2. Prune unused properties from auto-generated schemas; split a monolithic schema into per-resource schemas.
  3. If returning a large collection, return a summary plus a cursor/offset and a separate fetch tool.

Example fix

// before: return 300000 records as one structured value
result.StructuredContent = allRecords
// after: paginate
result.StructuredContent = map[string]any{"items": page, "nextCursor": cursor}
Defensive patterns

Strategy: validation

Validate before calling

func countNodes(v any) int {
    n := 1
    switch t := v.(type) {
    case map[string]any: for _, c := range t { n += countNodes(c) }
    case []any: for _, c := range t { n += countNodes(c) }
    }
    return n
}
if countNodes(value) > 256<<10 { return errors.New("too many nodes") }

Prevention

When it happens

Trigger: Submitting a schema or value with more than 16384 (schema) or 262144 (value) JSON nodes. Each object/array/scalar counts as one node.

Common situations: A schema with thousands of properties or a huge enum; a value that is a very long array of records (e.g., 300k entries each counting as a node); auto-generated schemas from large data models.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/c54f1fe55d6300b9. Report an issue: GitHub.