Repository navigation
Open
Labels
area:backend-coreCore backend frameworks, DAG task runner, and server APItype:featureNew feature or request
Description
Background
request_file_upload (added in #1131 for #1047) returns an upload URL that accepts the whole file in a single PUT request. Some environments put a proxy in front of KHI that rejects large request bodies. The Web UI works there because it uploads files in chunks through FileParameterUploadService, but MCP clients cannot upload files larger than the proxy limit.
Proposal
Let the same upload URL accept multiple PUT requests with a Content-Range header, similar to the GCS resumable upload.
PUT /api/v3/upload/<urlToken>
Content-Range: bytes <start>-<end>/<total>
Content-Length: <end-start+1>
<chunk bytes>
| Situation | Status | Body |
|---|---|---|
No Content-Range |
Same as today: the body is the whole file | {"fieldId","status":"PROCESSING","sizeBytes"} |
| An intermediate chunk is stored | 202 Accepted | {"fieldId","status":"UPLOADING","receivedBytes","totalBytes"} |
| The last missing range is stored | 200 OK | {"fieldId","status":"PROCESSING","sizeBytes"} |
total differs from the first chunk |
409 Conflict | {"error": ...} |
| The chunk is larger than the limit | 413 | {"error": ...} |
- The first chunk starts a chunk session bound to the URL token. The URL token is removed when all ranges are received and the session completes. A URL accepts one file instead of one request.
- The 30-minute URL expiry applies until the first chunk. After that, the chunk session TTL, which is refreshed on every chunk, applies.
- A chunk whose body ends early is rejected with 400 and the session is kept, so the client can resend it. Server-side failures abort the session and are recorded with
RecordUploadFailureas today. request_file_uploadreturnsSuggestedChunkSize, the same chunk size as the Web UI, and its template shows add | curlloop.- Use
chunkedupload.ValidateReceivedRangesto decide completion, becauseReceivedBytescounts resent chunks twice.
Example client loop:
FILE=<file>; URL='<url>'; CHUNK=26214400
TOTAL=$(wc -c < "$FILE"); N=$(( (TOTAL + CHUNK - 1) / CHUNK ))
for ((i = 0; i < N; i++)); do
START=$(( i * CHUNK )); END=$(( START + CHUNK - 1 < TOTAL - 1 ? START + CHUNK - 1 : TOTAL - 1 ))
dd if="$FILE" bs=$CHUNK skip=$i count=1 2>/dev/null |
curl -sf -X PUT -H "Content-Range: bytes $START-$END/$TOTAL" --data-binary @- "$URL" || break
doneAffected files
pkg/server/uploadurl/handler.go,issuer.goand their testspkg/server/chunkedupload/manager.goif a completion check is addedpkg/server/mcp/inspection_upload.go,templates/request_file_upload.md.tmpl,testdata/request_file_upload.golden.md
Acceptance criteria
- A file larger than the chunk size can be uploaded over MCP with chunks no larger than
SuggestedChunkSize. - A single PUT without
Content-Rangekeeps working. - A chunk for a different total size is rejected with 409.
- A resent chunk after a failed request completes the upload.
- An upload that takes longer than the URL expiry in total succeeds as long as chunks keep arriving.
Metadata
Metadata
Assignees
Labels
area:backend-coreCore backend frameworks, DAG task runner, and server APItype:featureNew feature or request
Activity