{"record":{"id":"9277aed0ed5c1204","repo":"googleapis/mcp-toolbox","slug":"object-q-d-bytes-exceeds-d-byte-limit-w","errorCode":null,"errorMessage":"object %q: %d bytes exceeds %d byte limit: %w","messagePattern":"object %q: (.+?) bytes exceeds (.+?) byte limit: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudstorage/cloudstorage.go","lineNumber":259,"sourceCode":"// narrow the range. Objects whose bytes are not valid UTF-8 are rejected\n// with cloudstoragecommon.ErrBinaryContent.\n//\n// TODO: MCP tool results only carry text today, so we gate this tool on\n// utf8.Valid. When the toolbox supports non-text MCP content (embedded\n// resources, images, blobs), expand this to detect content type and return\n// binary payloads natively.\nfunc (s *Source) ReadObject(ctx context.Context, bucket, object string, offset, length int64) (map[string]any, error) {\n\tif err := s.validateBucket(bucket); err != nil {\n\t\treturn nil, err\n\t}\n\treader, err := s.client.Bucket(bucket).Object(object).NewRangeReader(ctx, offset, length)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open object %q in bucket %q: %w\", object, bucket, err)\n\t}\n\tdefer reader.Close()\n\n\tif remain := reader.Remain(); remain > defaultMaxReadBytes {\n\t\treturn nil, fmt.Errorf(\"object %q: %d bytes exceeds %d byte limit: %w\",\n\t\t\tobject, remain, defaultMaxReadBytes,\n\t\t\tcloudstoragecommon.ErrReadSizeLimitExceeded)\n\t}\n\n\tdata, err := io.ReadAll(reader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read object %q in bucket %q: %w\", object, bucket, err)\n\t}\n\n\tif !utf8.Valid(data) {\n\t\treturn nil, fmt.Errorf(\"object %q in bucket %q: %w\", object, bucket,\n\t\t\tcloudstoragecommon.ErrBinaryContent)\n\t}\n\n\treturn map[string]any{\n\t\t\"content\":     string(data),\n\t\t\"contentType\": reader.Attrs.ContentType,\n\t\t\"size\":        len(data),","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudstorage/cloudstorage.go#L241-L277","documentation":"The remaining bytes of the opened range reader exceed the source's configured read limit (defaultMaxReadBytes), so the source aborts instead of buffering an oversized object into memory, wrapping ErrReadSizeLimitExceeded. This is an intentional guard, not a transport failure.","triggerScenarios":"ReadObject called (usually with length -1, i.e. whole object) on an object whose readable size is greater than defaultMaxReadBytes; also range reads whose requested length exceeds the limit.","commonSituations":"Reading large log/dataset/video files that were fine when the limit was chosen but have grown; users pointing the tool at a multi-GB object expecting a full text read; raising the range length beyond the cap.","solutions":["Read only a byte range within the limit by passing a smaller offset/length to ReadObject.","Read the object in chunks by looping with offset += chunkSize until the whole object is consumed.","Export the object out-of-band (gsutil/gcloud storage or the GCS client directly) for files that should not be size-limited.","Increase defaultMaxReadBytes in the source configuration if the policy allows larger reads (mind memory cost)."],"exampleFix":"// before\nres, err := source.ReadObject(ctx, \"bkt\", \"big.json\", 0, -1) // > defaultMaxReadBytes\n// after\nres, err := source.ReadObject(ctx, \"bkt\", \"big.json\", 0, 1<<20) // read first 1 MiB chunk","handlingStrategy":"validation","validationCode":"// read only within the limit, or chunk\nconst maxChunk = 1 << 20 // must stay <= defaultMaxReadBytes\nif length < 0 || length > maxChunk {\n    length = maxChunk\n}\nres, err := source.ReadObject(ctx, bucket, object, offset, length)","typeGuard":null,"tryCatchPattern":"if errors.Is(err, cloudstoragecommon.ErrReadSizeLimitExceeded) {\n    // switch to chunked/out-of-band read\n}","preventionTips":["Check object sizes via metadata before full reads.","Read large objects in bounded chunks via offset/length.","Use gsutil/the GCS client for objects that legitimately exceed the limit.","Document the read limit to tool users in the tool description."],"tags":["size-limit","read-object","gcs","cloudstorage"],"backgroundTag":"read-size-limit-exceeded","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}