feat: add image generation MCP server and enhanced image rendering#1699
Draft
benjaminshafii wants to merge 2 commits intodevfrom
Draft
feat: add image generation MCP server and enhanced image rendering#1699benjaminshafii wants to merge 2 commits intodevfrom
benjaminshafii wants to merge 2 commits intodevfrom
Conversation
Add @openwork/image-gen-mcp — a standalone MCP server that exposes AI image generation (OpenAI, xAI/Grok, Google Imagen) as MCP tools. The server reads API keys from environment variables and returns generated images as MCP image content blocks, which OpenCode already converts to FilePart attachments. Also enhance FileCard in the session message list to render generated images (data URL + image MIME from assistant) as large inline previews with click-to-expand and download, instead of tiny 44x44 thumbnails. No OpenCode changes required — the entire pipeline from MCP subprocess to FilePart to SSE stream to UI already works.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Tool results with attachments (e.g. MCP image content) were stored correctly by OpenCode but never extracted by the OpenWork adapter layer. The attachments array on completed tool state was silently dropped in toUIPart(), mapToolPart(), handleToolPart(), and snapshotToUIMessages(). Fix all three paths: - session-sync.ts: emit file parts alongside tool part on update - usechat-adapter.ts handleToolPart: emit file chunks on tool output - usechat-adapter.ts snapshotToUIMessages: flatMap tool attachments This completes the pipeline from MCP image content through to the enhanced FileCard renderer.
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.
Summary
packages/image-gen-mcp— a standalone MCP server that exposes AI image generation as MCP toolsFileCardin session message list to render generated images as large inline previewsArchitecture
The MCP server (
openwork-image-gen-mcp) works with the existing OpenCode agent harness — no OpenCode changes required:MCP Server (
packages/image-gen-mcp).mjsfile, no build step, same pattern asopenwork-ui-mcpOPENAI_API_KEY,XAI_API_KEY,GOOGLE_API_KEY)generate_imageandlist_image_providersimagecontent blocks (not text), avoiding output truncationFileCard Enhancement
Usage
Add to
opencode.json:{ "mcp": { "openwork-image-gen": { "type": "local", "command": ["node", "packages/image-gen-mcp/index.mjs"], "env": { "OPENAI_API_KEY": "sk-..." } } } }Or via the existing
POST /workspace/:id/mcpendpoint.Why MCP (not plugin or built-in tool)
stringonly — base64 images get truncated byTruncate.output()FilePartattachmentsTesting
node --check packages/image-gen-mcp/index.mjs— syntax validation passessettings-route.tsxandwelcome-route.tsx— not related to this changeOPENAI_API_KEY, ask agent to generate an image, verifyFilePartarrives and renders as large previewFuture work