Repository navigation
Serve MCP images as public R2 WebP URLs - #19
Merged
Merged
Conversation
Image tools now return a public https image_url (WebP quality 99) instead of inline PNG base64, matching the Grok-style hosted URL that clients can render with a normal img tag. Original PNGs move from KV to R2 for tool chaining; image_id and public URLs do not expire. Co-authored-by: billow <billow.fun@gmail.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
nai | c7c9d77 | Commit Preview URL Branch Preview URL |
Aug 14 2026, 04:38 AM |
wrangler dev serves the custom domain over http and overwrites Host, so public image URLs now use http://127.0.0.1:8787 in that case. Production https://nai.hoshinoaya.com requests are unchanged. Co-authored-by: billow <billow.fun@gmail.com>
b1llow
marked this pull request as ready for review
August 14, 2026 03:19
Keep public WebP image_url results and R2 artifact storage, and take main's nai_render_image_preview data/render split plus Grok OAuth callback. Co-authored-by: billow <billow.fun@gmail.com>
CI failed because worker-configuration.d.ts hash/order was stale after adding IMG_BUCKET and IMAGES. Regenerated without local .dev.vars so the committed types match GitHub Actions. Co-authored-by: billow <billow.fun@gmail.com>
Rate-limit GET/HEAD /i with the existing IP limiter, rewrite the custom domain to localhost only for loopback clients, pin widget img URLs to this Worker's /i/ capability paths, render URL and base64 images in the same gallery, and honor weak or list If-None-Match. Co-authored-by: billow <billow.fun@gmail.com>
Inject the request origin plus the production issuer into the preview HTML so img src matches resourceDomains, instead of allowing every workers.dev host. Give GET/HEAD /i its own IMAGE_RATE_LIMIT binding so image fetches cannot starve /v1 or /mcp. Co-authored-by: billow <billow.fun@gmail.com>
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.
Image tools currently return full PNG base64 as MCP
ImageContent, which most hosts drop or render as raw b64. This change follows the Grok Imagine pattern: return a publichttps://image URL that any client can put in<img src>or markdown.What changed
structuredContent.image_urlplus aresource_linktohttps://nai.hoshinoaya.com/i/img_<id>.webp. Inline base64ImageContentis only emitted when the R2/WebP path is unavailable.quality: 99). If that binding is missing or fails, the public object is the original PNG.orig/<id>.png(private, owner incustomMetadata) for upscale/director/img2img chaining. Public rendition ati/<id>.webp. KV keeps vibe tokens, vibe cache, and OAuth data only.image_idand public URLs are permanent capability URLs (128-bitimg_id, no auth).GET /i/:fileserves them withCache-Control: public, max-age=31536000, immutable.getImagestill reads legacyimg:KV rows so image_ids from the 24h before deploy keep working.image-preview-v3.html) prefersimages[].urland allows the Worker origin in CSPresourceDomains.wrangler devrewrites Host to the custom domain over http; image URLs in that case usehttp://127.0.0.1:8787so they stay fetchable.Infra
nai-images(already created)IMG_BUCKET,IMAGESTests
npm test(210) andnpm run typecheckpass.Local
wrangler devsmoke: mock NovelAI zip →nai_generate_image→image_urlhttp://127.0.0.1:8787/i/img_….webp→200/image/webp/ 96-byte RIFF WebP from the local Images binding.