{"record":{"id":"300bf8384fcbd405","repo":"siyuan-note/siyuan","slug":"value-exceeds-d-bytes","errorCode":null,"errorMessage":"value exceeds %d bytes","messagePattern":"value exceeds (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/tools/validation.go","lineNumber":146,"sourceCode":"\t\treturn fmt.Errorf(\"structured content is required when an output schema is defined\")\n\t}\n\tvalue, err := prepareValidationValue(result.StructuredContent)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"prepare structured content: %w\", err)\n\t}\n\treturn validateResolved(ctx, validator.validationSlots, validator.output, value)\n}\n\nfunc prepareValidationValue(value any) (any, error) {\n\tif err := validateJSONComplexity(value, maxToolValueDepth, maxToolValueNodes); err != nil {\n\t\treturn nil, err\n\t}\n\tdata, err := json.Marshal(value)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(data) > maxToolValueBytes {\n\t\treturn nil, fmt.Errorf(\"value exceeds %d bytes\", maxToolValueBytes)\n\t}\n\tvar canonical any\n\tif err = json.Unmarshal(data, &canonical); err != nil {\n\t\treturn nil, err\n\t}\n\tif err = validateJSONComplexity(canonical, maxToolValueDepth, maxToolValueNodes); err != nil {\n\t\treturn nil, err\n\t}\n\treturn canonical, nil\n}\n\nfunc validateResolved(ctx context.Context, validationSlots chan struct{}, schema *jsonschema.Resolved, value any) error {\n\tif ctx == nil {\n\t\tctx = context.Background()\n\t}\n\ttimer := time.NewTimer(toolValidationTime)\n\tdefer timer.Stop()\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/mcp/tools/validation.go#L128-L164","documentation":"Thrown by prepareValidationValue when the marshaled JSON of an input arguments map or an output structured-content value exceeds maxToolValueBytes (8 MiB, 8<<20). This is a hard ceiling protecting the validator from allocations and OOM when a client submits, or a tool returns, an enormous payload.","triggerScenarios":"ValidateInputContext with an arguments map whose JSON encoding is >8 MiB, or ValidateOutputContext with a StructuredContent whose JSON encoding is >8 MiB.","commonSituations":"A tool argument receives a huge base64 blob or an embedded file; a tool returns a full database dump as structured content; a client streams a giant array of records in one call instead of paginating.","solutions":["Reduce the payload: paginate large lists, store big binaries as file assets and pass a path/URL instead of inlining.","Stream or chunk the operation rather than passing the full dataset through one tool invocation.","If a higher limit is truly required, reconsider the design — 8 MiB is generous for structured JSON; a need to exceed it usually signals the wrong abstraction.","Compress or deduplicate redundant repeated fields before marshaling."],"exampleFix":"// before: inlining a large blob\narguments := map[string]any{\"data\": hugeBase64String}\n// after: pass a reference, fetch content server-side\narguments := map[string]any{\"assetPath\": \"/data/file.bin\"}","handlingStrategy":"validation","validationCode":"data, err := json.Marshal(value)\nif err != nil { return err }\nif len(data) > 8<<20 {\n    return fmt.Errorf(\"value is %d bytes, max %d\", len(data), 8<<20)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Paginate large collections rather than passing them in one call.","Pass big binaries by file reference (asset path/URL), not inline.","Measure payload size in integration tests for tools known to move bulk data."],"tags":["mcp","validation","size-limit","memory"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}