Repository navigation
feat(den-api): binary-safe capability content + MCP image delivery lanes - #3441
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
benjaminshafii
enabled auto-merge (squash)
August 3, 2026 06:04
Drive/OneDrive file reads decoded fetched bytes as UTF-8 text, irreversibly corrupting binary files (PNG etc). Native and external MCP results were also flattened to text-only parts, so agents could never receive images. - capability-sources/binary-content.ts: shared strict-UTF-8-or-base64 decoder (content sniffing, 10 MiB binary cap) + relocated truncateText - google-workspace drive-file route: dual-lane response (content | contentBase64 + encoding + contentUnavailableReason) with metadata size pre-gate before the content fetch - microsoft-365 drive-file route: same contract; binary returned as base64 instead of unsupported_content_type; cap raised to 10 MiB - mcp/tool-content.ts: execute_capability now emits MCP image parts for native image payloads (sharp downscale >1 MiB to <=1568px JPEG, base64 redacted from the text part) and passes through downstream text|image content instead of stringifying it
benjaminshafii
force-pushed
the
feat/capability-binary-lane
branch
from
August 3, 2026 09:18
ca75031 to
ccf38dc
Compare
Contributor
There was a problem hiding this comment.
Warden security clearance: clear. No new security issues found in this diff (ccf38dcc89a205ed399cb47346ab61acbc4ff2cb). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
This was referenced Aug 3, 2026
benjaminshafii
pushed a commit
that referenced
this pull request
Aug 3, 2026
…ext, storage-free (#3458) Revives #3354 by @reachjalil onto current dev. - apps/server: new openwork-cloud-uploads extension (drive_upload_file, gmail_create_draft_with_attachments) — authorized workspace paths in, multipart FormData out to Den; 4 MiB total enforced before network I/O; realpath containment incl. symlink escapes. - den-api: POST /v1/direct-uploads/google-workspace/{drive-files,gmail-drafts} behind new cloudTransportRoute() (MCP bearer + mcp:write + org membership); bytes forward straight to Google, never persisted. - Removes the model-facing base64 lanes: gmail-draft attachments field and the drive-files base64 upload capability. Gmail draft logic extracted into executeGmailDraft, shared by the JSON capability and the multipart route, preserving dev behavior (#3441 binary read lanes and #3449 formatting kept). - Legacy flow deleted per the frozen corpus; successor proof is evals/specs/google-workspace-direct-uploads.slow.test.ts (real Den boot, mock-Google byte-exact witness, pre-network 413, no bytes in results). - evals/tsconfig.json stops typechecking the frozen flow corpus, fixing the pre-existing red evals:typecheck (FlowContext.page in den-trim-page-headers). Co-authored-by: Jalil <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
execute_capabilityruns on Den; results ride back to agents as JSON text. The Drive read capability fetches raw bytes correctly (alt=media) and then destroys them:.text()UTF-8-decodes binary, replacing invalid sequences with U+FFFD — measured live this session: a 52,223-byte PNG came back as 49,126 characters of unrecoverable mush. OneDrive reads refused binary outright (unsupported_content_type). And even clean base64 could never reach an agent as an image: the MCP wrapper hard-codes text-only parts and stringifies any downstream result containing image content.What changed
L1 — shared dual-lane decoder (
capability-sources/binary-content.ts)Strict UTF-8 sniffing (
TextDecoder(..., { fatal: true })) → text lane (existing truncation); otherwise base64 lane capped at 10 MiB. Content sniffing beats MIME checking: DXF (image/vnd.dxf, actually ASCII) stays text.drive-file/{fileId}: response gainscontentBase64,encoding: "text"|"base64"|"none",contentUnavailableReason: "file_too_large"|null; metadata size pre-gate skips the content fetch entirely for oversized files.contentunchanged for text files.drive-file/{itemId}: same contract; binary now returned instead of refused; byte-limited streaming kept; cap raised 5 MB → 10 MiB for parity.L2 — MCP wrapper image lanes (
mcp/tool-content.ts, used byinvoke.ts+agent.ts)contentBase64+mimeType: image/*emit a real MCP{type:"image"}part; >1 MiB images are downscaled with sharp (≤1568px, JPEG q80; sharp already a dep); the base64 is redacted from the text part (never double-shipped).Upload symmetry note: the platform already accepts
dataBase64(Gmail attachments, Drive upload); this PR makes the read side match. Signed upload/download URLs for >10 MiB are a deliberate follow-up.Tests run (all from
ee/apps/den-api,bun test --conditions=development ...)test/google-workspace-capabilities.test.tstest/microsoft-365-routes.test.tstest/mcp-tool-content.test.ts(new)test/mcp-invoke-body.test.tstest/mcp-agent-timeouts.test.ts+test/agent-mcp-routes.test.tspnpm --filter @openwork-ee/den-api exec tsc --noEmitKnown pre-existing failures (not this PR — verified via
git stash -ubaseline on dev tip06225346f):test/mcp-agent-config-policy.test.ts: 14 pass / 2 fail on clean baseline and identically with this diff (expectations drifted from the import-mcps body schema, e.g.marketplaceIdno longer required — the live API confirms).bun testruns of DB-backed suites intermittently fail with mysql2 pool errors on baseline too (shared-process collision); every suite above passes solo.Validation scope
Server-API change only — no UI surface, so no video; runtime behavior is proven by the HTTP-level integration tests above (real Hono app, fake Google/Graph upstreams, byte-exact assertions). After deploy to OpenWork Cloud, the end-to-end demo this was built for becomes runnable live: draw on a Daylight tablet → PNG syncs to Drive → agent says "use my latest drawing" → sees it → recreates it in Paper. Happy to record that as follow-up proof once deployed.
Follow-ups (deliberately out of scope)
admin-capabilities.tsimage-part paritymcp-agent-config-policyexpectations