Skip to content

Fix generic error for oversized MCP file uploads#1193

Open
ved015 wants to merge 2 commits into
fix/mcp-invalid-container-tagfrom
fix/mcp-widget-error-display
Open

Fix generic error for oversized MCP file uploads#1193
ved015 wants to merge 2 commits into
fix/mcp-invalid-container-tagfrom
fix/mcp-widget-error-display

Conversation

@ved015

@ved015 ved015 commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

  • The MCP transport (agents SDK) rejects JSON-RPC bodies over 4 MiB with a bare HTTP 413 before the tool ever runs, so uploading a large file showed a generic "Something went wrong / Upload failed" in the widget.
  • The upload widget now rejects oversized files at selection time with an inline error stating the file's size and the maximum (~3.0 MB raw, accounting for base64 inflation and the JSON-RPC envelope inside the 4 MiB transport limit), advertises the limit in the dropzone copy, and maps any transport 413 / "payload too large" error that still reaches the error path to the same friendly message.

Stacked on #1192#1189#1120.

@claude

claude Bot commented Jul 3, 2026

Copy link
Copy Markdown

Claude finished @ishaanxgupta's task in 1m 24s —— View job


Review Complete

  • Load review tools
  • Fetch PR diff and existing review comments
  • Analyze changes for bugs, security issues, and logic errors
  • Submit review

Summary: Reviewed the oversized file upload error handling changes. No bugs, security issues, or logic errors found. The file size calculation correctly accounts for base64 inflation and the JSON-RPC envelope. The Graphite style comments about function declarations have been addressed in the latest commit.

Score: 10/10 — Clean fix, ready to ship.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 3, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
supermemory-mcp 521db2b Jul 04 2026, 02:49 PM

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: This PR fixes two UX issues in the MCP widget: showing friendly errors for oversized file uploads (instead of generic "something went wrong"), and returning a properly typed ViewMessage from fetch-graph-data so the widget renders the graph view instead of "unrecognized response."

Issues found: None — this looks good to ship.

Details:

fetch-graph-data.ts:

  • Correctly returns a ViewMessage with view: "graph" discriminant instead of raw API response
  • The containerTag is optional in the type (containerTag?: string), so passing effectiveTag (which could be undefined) is type-safe
  • Text content now provides a human-readable summary instead of raw JSON

Upload.tsx:

  • File size limit calculation is conservative and correct: ((4 MiB - 64 KiB) * 3/4) ≈ 2.95 MB, properly accounting for base64 inflation (~4/3) and the JSON-RPC envelope
  • Client-side validation prevents oversized uploads before they're attempted
  • The regex /413|too large|payload/i for detecting transport errors is broad but safe — worst case it shows a size-related error for a non-size issue, which is better than a generic "Upload failed"
  • The file reference in the catch block is captured in the useCallback closure after the null check, so accessing file.size is safe

Score: 10/10

Clean fix for real UX issues with proper typing and defensive error handling.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 3, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 521db2b Commit Preview URL

Branch Preview URL
Jul 04 2026, 02:49 PM

@ved015 ved015 force-pushed the fix/mcp-widget-error-display branch from 31f77a7 to 3a02393 Compare July 3, 2026 15:15
@ved015 ved015 force-pushed the fix/mcp-invalid-container-tag branch from 500a4b5 to df671c6 Compare July 3, 2026 15:15
@ved015 ved015 mentioned this pull request Jul 3, 2026

ved015 commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: This PR fixes two UX issues in the MCP widget: showing friendly errors for oversized file uploads (instead of generic "something went wrong"), and returning a properly typed ViewMessage from fetch-graph-data so the widget renders the graph view instead of "unrecognized response."

Issues found: None — this looks good to ship.

Details:

fetch-graph-data.ts:

  • Correctly returns a ViewMessage with view: "graph" discriminant instead of raw API response
  • The containerTag is optional in the type (containerTag?: string), so passing effectiveTag (which could be undefined) is type-safe
  • Text content now provides a human-readable summary instead of raw JSON

Upload.tsx:

  • File size limit calculation is conservative and correct: ((4 MiB - 64 KiB) * 3/4) ≈ 2.95 MB, properly accounting for base64 inflation (~4/3) and the JSON-RPC envelope
  • Client-side validation prevents oversized uploads before they're attempted
  • The regex /413|too large|payload/i for detecting transport errors is broad but safe — worst case it shows a size-related error for a non-size issue, which is better than a generic "Upload failed"
  • The file reference in the catch block is captured in the useCallback closure after the null check, so accessing file.size is safe

Score: 10/10

Clean fix for real UX issues with proper typing and defensive error handling.

@ved015 ved015 force-pushed the fix/mcp-widget-error-display branch from 3a02393 to f7fc662 Compare July 3, 2026 15:21
@ved015 ved015 mentioned this pull request Jul 3, 2026
@ved015 ved015 changed the title Fix MCP widget error display for large uploads and fetch-graph-data Fix generic error for oversized MCP file uploads Jul 3, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: This PR fixes UX issues in the Upload widget by showing friendly errors for oversized file uploads and properly handling transport-level 413 errors.

Issues found: None — this looks good to ship.

Details:

  • File size limit calculation is correct: ((4 MiB - 64 KiB) * 3/4) ≈ 2.95 MB, properly accounting for base64 inflation (~4/3) and the JSON-RPC envelope
  • Client-side validation in handleFileSelect prevents oversized uploads before they're attempted
  • The file reference in the catch block is safe — it's captured in the closure after the null check at line 86, so file.size access is guaranteed valid
  • The regex /413|too large|payload/i for detecting transport errors is broad but safe — worst case it shows a size-related error for a non-size issue, which is better than a generic "Upload failed"
  • Error display includes role="alert" for accessibility

Score: 10/10

Clean fix for real UX issues with proper typing and defensive error handling.

Comment thread apps/mcp/src/widget/views/Upload.tsx Outdated
Comment on lines +42 to +43
const FILE_TOO_LARGE_MESSAGE = (size: number) =>
`This file is ${formatFileSize(size)}. The maximum upload size is ${formatFileSize(MAX_UPLOAD_BYTES)} — please choose a smaller file.`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule 'Use function declarations over function expressions' is violated here. FILE_TOO_LARGE_MESSAGE is defined as a const arrow function expression:

const FILE_TOO_LARGE_MESSAGE = (size: number) =>
  `This file is ...`

This should be rewritten as a function declaration:

function fileTooLargeMessage(size: number): string {
  return `This file is ${formatFileSize(size)}. The maximum upload size is ${formatFileSize(MAX_UPLOAD_BYTES)} — please choose a smaller file.`
}
Suggested change
const FILE_TOO_LARGE_MESSAGE = (size: number) =>
`This file is ${formatFileSize(size)}. The maximum upload size is ${formatFileSize(MAX_UPLOAD_BYTES)} — please choose a smaller file.`
function fileTooLargeMessage(size: number): string {
return `This file is ${formatFileSize(size)}. The maximum upload size is ${formatFileSize(MAX_UPLOAD_BYTES)} — please choose a smaller file.`
}

Spotted by Graphite (based on custom rule: TypeScript style guide (Google))

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment thread apps/mcp/src/widget/views/Upload.tsx Outdated
Comment on lines +64 to +76
const handleFileSelect = (selected: File) => {
if (selected.size > MAX_UPLOAD_BYTES) {
log(
"warning",
`[upload] rejected oversized file: ${selected.name} (${selected.size}B > ${MAX_UPLOAD_BYTES}B)`,
)
setFileError(FILE_TOO_LARGE_MESSAGE(selected.size))
setFile(null)
return
}
setFileError(null)
setFile(selected)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule 'Use function declarations over function expressions' is violated here. handleFileSelect is defined as a const arrow function expression:

const handleFileSelect = (selected: File) => {
  ...
}

Since this is a named function (not a concise callback), it should be rewritten as a function declaration:

function handleFileSelect(selected: File) {
  ...
}
Suggested change
const handleFileSelect = (selected: File) => {
if (selected.size > MAX_UPLOAD_BYTES) {
log(
"warning",
`[upload] rejected oversized file: ${selected.name} (${selected.size}B > ${MAX_UPLOAD_BYTES}B)`,
)
setFileError(FILE_TOO_LARGE_MESSAGE(selected.size))
setFile(null)
return
}
setFileError(null)
setFile(selected)
}
function handleFileSelect(selected: File) {
if (selected.size > MAX_UPLOAD_BYTES) {
log(
"warning",
`[upload] rejected oversized file: ${selected.name} (${selected.size}B > ${MAX_UPLOAD_BYTES}B)`,
)
setFileError(FILE_TOO_LARGE_MESSAGE(selected.size))
setFile(null)
return
}
setFileError(null)
setFile(selected)
}

Spotted by Graphite (based on custom rule: TypeScript style guide (Google))

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@vorflux

vorflux Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Reviewed the live PR diff for apps/mcp/src/widget/views/Upload.tsx, including the oversized upload validation and friendly payload-too-large error handling. The current GitHub PR diff contains only this upload widget change, and I found no actionable correctness, security, data loss, race condition, or breaking-change issues.

Verdict

Reviewed — no issues found. The implementation is scoped and handles the reviewed oversized-file states appropriately.

@vorflux

vorflux Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Testing

Validated the live PR diff for apps/mcp/src/widget/views/Upload.tsx. Browser/UI validation passed for oversized file pre-validation, friendly size-limit messaging, disabled upload state, clearing the error after selecting a valid file, and friendly mapping for mocked 413 Payload Too Large and thrown Payload Too Large errors. Static formatting for Upload.tsx passed; full apps/mcp typecheck still fails in unrelated existing widget hook files.

Commands run:

cd /code/supermemoryai/supermemory/apps/mcp
bun run dev:widget --host 0.0.0.0
__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=gfs7r8i3m2jf.preview.us1.vorflux.com bun run dev:widget --host 0.0.0.0
npx agent-browser upload "input[accept=\".txt,.pdf,.png,.jpg,.jpeg,.mp4\"]" /var/tmp/testing_upload_pr1193/oversized-3_1mb.txt --args "--no-sandbox"
npx agent-browser upload "input[accept=\".txt,.pdf,.png,.jpg,.jpeg,.mp4\"]" /var/tmp/testing_upload_pr1193/small-valid.txt --args "--no-sandbox"
bunx biome ci apps/mcp/src/widget/views/Upload.tsx
cd apps/mcp && bun run check-types

Result:

final_public_preview status=200 type=text/html bytes=827

Oversized upload observed:
This file is 3.0 MB. The maximum upload size is 3.0 MB — please choose a smaller file.

Valid file observed:
small-valid.txt
39 B
Upload file enabled
oversized error cleared

Mocked 413 response observed:
Upload: onError → This file is 39 B. The maximum upload size is 3.0 MB — please choose a smaller file.

Mocked thrown payload error observed:
Upload: onError → This file is 2.0 KB. The maximum upload size is 3.0 MB — please choose a smaller file.

bunx biome ci apps/mcp/src/widget/views/Upload.tsx: passed
cd apps/mcp && bun run check-types: failed only in unrelated existing files:
src/widget/hooks/useHostContext.ts(19,5)
src/widget/hooks/useViewState.ts(78,4)
src/widget/hooks/useViewState.ts(79,4)
src/widget/hooks/useViewState.ts(80,4)
src/widget/hooks/useViewState.ts(81,4)
Filtered for Upload.tsx: no errors

Verdict

⚠️ Issues found. The live upload widget behavior passed targeted validation, but full apps/mcp typecheck is not green due to unrelated existing hook errors.


Attached Images and Videos

pr1193_upload_initial_focused.png

pr1193_upload_oversized_error_focused.png

pr1193_upload_valid_selected_focused.png

pr1193_upload_413_mapping_event_visible.png

pr1193_upload_payload_throw_mapping_event_visible.png

pr1193_studio_initial_verified.png

pr1193_upload_oversized_error.png

pr1193_upload_valid_selected.png

pr1193_upload_error_mapping_event_visible.png

🎥 View recording: pr1193_upload_widget_verified.webm

@ishaanxgupta ishaanxgupta changed the base branch from fix/mcp-invalid-container-tag to graphite-base/1193 July 3, 2026 15:46
@ishaanxgupta ishaanxgupta changed the base branch from graphite-base/1193 to main July 3, 2026 15:46
@ishaanxgupta ishaanxgupta changed the base branch from main to graphite-base/1193 July 3, 2026 16:00
@ishaanxgupta ishaanxgupta changed the base branch from graphite-base/1193 to fix/mcp-invalid-container-tag July 3, 2026 16:00
ved015 and others added 2 commits July 4, 2026 20:14
The MCP transport rejects JSON-RPC bodies over 4 MiB with a bare 413, so
large file uploads died with a generic "Upload failed" widget error. The
upload widget now rejects oversized files at selection time with the size
limit spelled out, advertises the limit in the dropzone copy, and maps any
transport 413 that still occurs to the same friendly message.

Co-authored-by: Cursor <cursoragent@cursor.com>
Address Graphite style review on Upload.tsx.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ishaanxgupta ishaanxgupta force-pushed the fix/mcp-widget-error-display branch from f7fc662 to 521db2b Compare July 4, 2026 14:47

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: This PR improves UX by showing friendly error messages for oversized file uploads instead of generic "Upload failed" errors.

Issues found: None — this looks good to ship.

Details:

  • File size limit calculation is correct: ((4 MiB - 64 KiB) * 3/4) ≈ 2.95 MB, properly accounting for base64 inflation and JSON-RPC envelope
  • Client-side validation in handleFileSelect prevents oversized uploads before network requests
  • The file reference in error handlers is safe — captured after the null check at line 87
  • The regex /413|too large|payload/i for transport errors is intentionally broad — worst case shows a size-related message for a non-size issue, better than a generic failure
  • Error display includes role="alert" for accessibility
  • The Graphite style comments about function declarations have been addressed in the latest commit

Score: 10/10

Clean fix for a real UX issue with correct math and defensive error handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants