{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/tools/validation.go#L128-L164","documentation":"prepareValidationValue enforces a size budget on values being validated (tool arguments or structured output): the JSON serialization must not exceed maxToolValueBytes (8 MiB). Oversized values are rejected up front to keep schema validation cheap and predictable.","triggerScenarios":"ValidateInputContext receives arguments whose JSON encoding exceeds 8 MiB, or ValidateOutputContext receives StructuredContent whose encoding exceeds 8 MiB — e.g. embedding large file contents, base64 blobs, or dumping whole documents into a tool call.","commonSituations":"Agents passing whole-file contents through tool arguments instead of paths; handlers echoing large query results in structured output; accidental inclusion of binary data as base64 strings.","solutions":["Pass file paths or asset references instead of inlining large contents in tool arguments.","Truncate, paginate, or summarize large result sets in structured output.","Check the JSON size of the payload before the call (len of json.Marshal) and split it.","Move bulk data to a dedicated upload/download mechanism outside the tool arguments."],"exampleFix":"// before\nargs := map[string]any{\"content\": string(hugeFileBytes)} // > 8 MiB\n// after\nargs := map[string]any{\"path\": \"assets/data.json\"} // reference the file by workspace-relative path","handlingStrategy":"validation","validationCode":"const size = new Blob([JSON.stringify(arguments)]).size;\nif (size > 8 * 1024 * 1024) throw new Error(\"tool arguments exceed 8 MiB limit\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass file/asset paths instead of inlining large contents in tool arguments.","Check payload JSON size client-side before invoking the tool.","Never embed base64 binaries or whole documents in tool calls.","Split bulk data transfers into chunked or multi-step operations."],"tags":["mcp","size-limit","validation"],"backgroundTag":"payload-too-large","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}