Repository navigation
Upload document images from the MCP server - #848
Conversation
push and push_docs upload the local images a Markdown file shows on a line of their own and put their docfile:// URIs in the document. The Markdown file is never rewritten. .paca/push.json records the sha256 and file id of each image, so unchanged bytes are not uploaded again and a second push of an unchanged file still prints "unchanged". A new document is written first, gets its images, and is written again with If-Match. pull --images (pull_docs with images: true) downloads the images of the documents it writes to .paca-assets/<document id>/ and names them by that path, so a pulled file can be pushed back without re-uploading. New tools: upload_doc_file, read_doc_file and delete_doc_file. The initiate / PUT / complete upload flow moves to api/upload.ts and is shared with task attachments.
There was a problem hiding this comment.
ℹ️ Minor suggestions only — nothing blocking; three small points inline.
Approach: sound — it reuses the existing doc-file routes and the docfile:// URI the web editor already writes, and keeps sync idempotent with sha256 values recorded in the state files the CLI already owns, rather than adding a new mechanism or touching the API.
Reviewed changes
api/upload.tsextraction — the initiate/PUT/complete flow moved out ofviews-client.tsverbatim and is now shared by task attachments (uploadTaskAttachmentbehaves as before) and document files, including the multipart 5 MiB path.push/push_docsimage upload — local images on a line of their own are uploaded and replaced bydocfile://URIs only in what is sent; the Markdown file is untouched. Reuse is keyed by repo-relative path + sha256 in.paca/push.json, a first push writes placeholders then the content withIf-Match, and missing/empty/out-of-root images abort before any request.--prune-images/pruneImagesdeletes the files the file no longer shows.pull --images/images: true— names each document image.paca-assets/<docId>/<file name>, localizes the Markdown, renames the folder with a moved document, removes it when the document is gone, recordsassetsso a mirror push maps the path back to the same file id, and reports failed downloads for the next run.- New tools —
upload_doc_file(bydocIdorpath, optionalinsertMarkdownappend guarded byIf-Match),read_doc_file(images only, 5 MB) anddelete_doc_file, all gated by the sharedassertAllowedPath. - Path/type helper moves —
assertAllowedPath/realishtoutils/allowed-paths.tsso the CLI and the tools apply one rule, andguessContentTypetoutils/doc-files.tsfor reuse by the new tools. - Docs and tests — README/ALL_TOOLS/CHANGELOG updates plus five new test files covering single/multipart upload, reuse, dry run, pruning, document-deleted conflicts, path/missing-file errors,
pull --imagesround trips, a moved document and that no output leaks a presigned URL.
I verified the docfile://{project}/{doc}/{file} shape against the web editor's resolveFileUrl, the upload contract against the Go handlers (InitiateDocUpload sets no size limit; the multipart threshold and DefaultPartSize are 5 MiB, matching putMultipart), and ran the package suite: 61 files / 1385 tests pass, with lint and typecheck clean for the touched files.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pull kept the .paca-sync.json entry and the file under .paca-assets of an image that had left the document, so a later pull could download it again. A fetched document now keeps only the images it still shows, and the file is removed unless its bytes were changed locally. read_doc_file checked its 5 MB limit after the whole file was in memory. downloadDocFile takes a byte limit, refuses a larger Content-Length before reading, and stops reading once the limit is passed. The README overview counts 84 tools.
There was a problem hiding this comment.
Important
The new stale-image pruning can delete a file that a kept mirror file still references. Details inline.
Reviewed changes
The second commit addresses the three prior notes and adds the pruning and read-cap behavior:
- Capped
read_doc_filereads —downloadDocFilenow takesmaxBytes;readUpTorefuses a file from its declaredContent-Lengthor as soon as the streamed total passes the limit, cancelling the body instead of buffering it, and the tool turnsFileTooLargeErrorinto a text error. - Pruned stale mirror images —
shownAssetsfilters a fetched document'sassetsto the file ids its content still shows;syncAssetFilesthen deletes the matching files under.paca-assets/<docId>/(keeping ones whose bytes were edited locally), drops empty maps and prunes empty folders. - README and tests — the headline tool count is corrected to 84, the asset-removal behavior is documented, and tests cover the size cap and removed-image pruning.
The full apps/mcp suite passes (61 files / 1392 tests); tsc reports only the pre-existing member-tools.ts errors.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
The stale-image cleanup ran before pull decided whether to rewrite the mirror file, so a file it kept or left conflicted could lose an image it still referenced, entry and bytes. The cleanup now runs once the files are in place and lets go of an image only when the document no longer shows it and the mirror file no longer names it. Naming new images against the full previous set also stops a new image from taking the path of a removed one whose local file was edited.
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — the fix moves stale-image pruning to after the mirror files are in place, so it can tell an image a kept file still references from one the document genuinely dropped, and it seeds new-image naming with the full previous set so a same-named image no longer takes a locally edited file's path.
Reviewed changes
The third commit (4105ab2) addresses the pruning regression from the prior review; I read the changed pull.ts paths and ran the package suite.
- Prune moved after the write — stale-image cleanup now runs once
next[id].fileis on disk, keeping an asset when either the fetched content still shows it or the mirror file still names its path. - Same-name images keep their suffix —
nameNewAssetsis seeded with the full previousassetsmap, so a new image sharing a removed image's file name takes the<fileId8>-path instead of overwriting a locally edited file. - Regression tests — merged, conflicted, and same-name cases added to
mirror-images.test.ts; README updated to match.
The full apps/mcp suite passes (61 files / 1395 tests), and the changed files are lint- and typecheck-clean.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Problem
The MCP server cannot put an image in a document.
pushof a Markdown file that showsdrops the line (a relative link has no meaning in Paca), and no tool calls the doc file routes the web editor uploads through, so a folder of wireframes or screenshots reaches Paca as text only. The only way to add the images was to drag them into the editor one by one.Change
Only
apps/mcp. The API and the web app are untouched: this uses the existing doc file routes (initiate-upload,complete-upload,download-url,DELETE) and thedocfile://<project>/<document>/<file>URL the web editor already writes in image blocks.push/push_docsupload the local images a Markdown file shows on a line of their own and put theirdocfile://URIs in the document.png/P1.png..paca/push.jsonrecords each image's sha256 and file id under a new optionalimageskey. The same bytes are not uploaded twice, an image whose bytes changed is uploaded again, and a second push of an unchanged file still printsunchanged.If-Match.PACA_MCP_FILE_ROOTS), stops the push before anything is sent, naming the image and its line.--dry-runlists what would be uploaded and what is already in Paca.--prune-images(pruneImages) deletes those.pull --images/pull_docswithimages: truedownloads the images of the documents it writes to.paca-assets/<document id>/<file name>next to each mirror file and names them by that path in the Markdown..paca-sync.jsonrecords path → file id and sha256 under a new optionalassetskey, so pushing the mirror file back maps the path to the same file and uploads nothing. A mirror file can also show a new local image, whichpushuploads. An image the document no longer shows leaves the mirror on the pull that brings that change, unless its bytes were changed locally or the mirror file still names it (a file pull kept or left conflicted). Without the option the output is byte for byte what it was.New tools
upload_doc_file— a local file to a document bydocIdorpath; returns the URI and a ready Markdown line, andinsertMarkdown: trueappends it to the document.read_doc_file— an image (up to 5 MB) back to the agent as image content, byuriordocId+fileId. A larger file is refused from itsContent-Length, or as soon as the limit is passed, without being read into memory.delete_doc_file.The initiate / PUT (or multipart) / complete flow moved out of
views-client.tsintoapi/upload.tsand is shared by task attachments and doc files;uploadTaskAttachmentbehaves as before.assertAllowedPathmoved toutils/allowed-paths.tsso the CLI and the tools apply the same rule.Presigned URLs are never printed or put in error messages.
Choices worth a look
.paca-assets/<document id>/, not in a folder named after the document. A renamed document keeps its Markdown unchanged, and a moved one takes its images along.InitiateDocUploadsets none, sopushsets none either. Each image is read into memory to be hashed and sent.list_doc_files. The API has no route that lists a document's files.Tests
bun run lint,bun run buildandbun run testpass inapps/mcp(1395 tests; lint reports the 4 warnings that are on master).New:
push-images.test.ts,mirror-images.test.ts,doc-client-files.test.ts,doc-files.test.ts,doc-file-tools.test.ts, with additions todispatch.test.tsanddoc-mirror-tools.test.ts. They cover the single PUT and multipart upload, reuse by sha256, the two writes of a new document, a document deleted between the write and the upload (a conflict, not a crash), dry run, pruning (also on an otherwise unchanged file), missing / empty / out-of-roots images, a path with a space, pull with and without--images, a document moved to another folder, an image removed from the document in Paca, the read limit, and that no output contains a presigned URL.Also run against the stack from
deploy/docker-compose.e2e.yml:pushof a Markdown file with three PNGs (one in a folder with a space):created,images: 3 uploaded. The second push printsunchanged. The stored document has three image blocks withdocfile://URLs, each file downloads with the sha256 recorded in.paca/push.json, and the images render in the web editor.1 uploaded, 2 already in Paca. After removing an image line: reported as left in Paca, then deleted by--prune-images.pull --images, then a push from a mirror file with a new local image and a later text-only edit: one upload, then none.upload_doc_filewithinsertMarkdown,read_doc_file, and a refused path outside the allowed folders, through the MCP server over stdio.Not covered
![alt][ref]) are not read.pull --imageslocalizes the documents that pull writes; a document unchanged since the last pull keeps itsdocfile://URIs until it changes.read_docandpullon a single line (). That is the converter's existing output and reads back as two image blocks, so I left it alone.