Skip to content

MCP: Support chunked uploads to request_file_upload URLs #1132

Open

Description

@kyasbal

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 RecordUploadFailure as today.
  • request_file_upload returns SuggestedChunkSize, the same chunk size as the Web UI, and its template shows a dd | curl loop.
  • Use chunkedupload.ValidateReceivedRanges to decide completion, because ReceivedBytes counts 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
done

Affected files

  • pkg/server/uploadurl/handler.go, issuer.go and their tests
  • pkg/server/chunkedupload/manager.go if a completion check is added
  • pkg/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-Range keeps 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.

Activity

  1. added
    type:feature
    area:backend-core
    on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backend-coretype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions