Skip to content

feat: support images in custom tool responses #9539

Closed as not planned
kiennq/opencode
#18

Description

@leeweisern

Problem

Custom tools (defined in .opencode/tools/) can currently only return strings. MCP tools already support returning structured content with images via { content: [{type: "image", mimeType, data}] }. This limitation prevents custom tools from returning visual data like screenshots, charts, or processed images that the LLM could analyze.

Proposed Solution

Extend the custom tool API to support the same rich content pattern as MCP tools:

export default tool({
  description: 'Capture a screenshot',
  args: { url: z.string() },
  async execute(args) {
    const base64 = await captureScreenshot(args.url)
    return {
      content: [
        { type: 'text', text: 'Screenshot captured' },
        { type: 'image', mimeType: 'image/png', data: base64 }
      ]
    }
  }
})

Requirements

  • Custom tools can return either string (backwards compatible) or { content: ToolContentPart[] }
  • Images are converted to attachments and sent to the model (same as MCP tools)
  • Existing string-only tools continue to work unchanged
  • Validation for image mime types and size limits

Related

Activity

  1. github-actions commented on Jan 20, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. added a commit that references this issue on Jan 20, 2026
    34f35dd
  3. leeweisern commented on Jan 20, 2026

    @leeweisern
    Author

    Currenty i am turning my custom tools into mcp to support images....

  4. guilhermelowa commented on Jan 20, 2026

    @guilhermelowa

    It would be super helpful to have this tool!

  5. Samraaj commented on Feb 27, 2026

    @Samraaj

    +1 i need dis

  6. github-actions commented on Apr 29, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions