feat(mcp): add content_upload_media tool for image uploads - #314
Open
hectorcanaimero wants to merge 1 commit into
Open
feat(mcp): add content_upload_media tool for image uploads#314hectorcanaimero wants to merge 1 commit into
hectorcanaimero wants to merge 1 commit into
Conversation
Adds a server-resolved MCP tool that uploads an image into the Media library, closing the gap where connectors could list and assign media but never create it. Bytes arrive inline (base64) or via an https sourceUrl the host downloads under the plugin network layer's SSRF blocklist (https-only, DNS-resolved, per-hop redirect revalidation, size-capped). Reuses the shared acceptUploadedMedia core for magic-byte sniffing, SVG sanitisation, storage dispatch, and responsive variants. Hoists the 50MB limit to MAX_MEDIA_BYTES in the upload core so the HTTP route and the tool share one source of truth.
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.
What
Adds
content_upload_media, a server-resolved MCP tool that uploads an image into the Media library and returns itsid+publicPath.Why
The MCP surface could list and assign media but never create it — an external agent building a page had no way to get an image into the library. This closes that gap.
How
data:URI prefix tolerated) or via an httpssourceUrlthe host downloads.sourceUrlbranch is SSRF-guarded exactly like the plugin network layer: https-only, DNS-resolved, every resolved address checked against the sharedisBlockedAddressblocklist, redirects followed manually and re-validated per hop, and the download size-capped while streaming. Loopback / private / link-local (incl.169.254.169.254) targets are refused.acceptUploadedMediacore — magic-byte MIME sniffing, SVG sanitisation, storage dispatch, responsive variants. No new byte-handling path is introduced.MAX_MEDIA_BYTESin the upload core so the HTTP media route and the tool share one source of truth.ai.tools.write+media.write, following thesite_publishserver-tool precedent.Impact
content_list_media's description was corrected (it claimed uploads were impossible).Verification
bun test server/ai/mcp/tools/uploadMediaTool.test.ts server/ai/mcp/registry.test.ts— 11/11 pass, including SSRF-blocklist rejection cases (127.0.0.1,169.254.169.254,10.x,::1), non-https rejection, source XOR, and non-image rejection.bun run build/bun run lintleft to CI (dev toolchain not available in the author's environment).Docs updated:
docs/features/mcp-connectors.md.