Skip to content

feat(runtime): allow tools to return raw MCP content directly#3125

Merged
tlgimenes merged 3 commits intomainfrom
tlgimenes/explore-createtool
Apr 16, 2026
Merged

feat(runtime): allow tools to return raw MCP content directly#3125
tlgimenes merged 3 commits intomainfrom
tlgimenes/explore-createtool

Conversation

@tlgimenes
Copy link
Copy Markdown
Contributor

@tlgimenes tlgimenes commented Apr 16, 2026

What is this contribution about?

Tools created with createTool previously had their return values automatically wrapped into { structuredContent, content: [{ type: "text", text: JSON.stringify(result) }] }. This change allows tools to return raw MCP content directly (e.g., { content: [{ type: "image", ... }] }) by detecting when the result already has a valid MCP content array. This enables returning images, embedded resources, and other MCP content types without the forced JSON text wrapping.

How to Test

  1. Create a tool that returns { content: [{ type: "text", text: "hello" }] } directly
  2. Verify it passes through as-is without double-wrapping
  3. Create a tool that returns a plain object like { foo: "bar" }
  4. Verify it still gets auto-wrapped as before

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Allow tools created with createTool to return raw MCP content directly, bypassing JSON wrapping when a valid array is provided. Also bumps @decocms/runtime to 1.5.0.

  • New Features

    • Passes through results with a valid content array unchanged (including images and embedded resources).
    • Keeps auto-wrapping for plain objects into { structuredContent, content: [{ type: "text", text: JSON.stringify(result) }] }.
  • Bug Fixes

    • Uses CallToolResult for passthrough to ensure correct typing.

Written for commit ae8bae9. Summary will update on new commits.

Tools can now return `{ content, structuredContent }` directly from
execute, bypassing the automatic JSON wrapping. This enables returning
images, embedded resources, and other MCP content types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

tlgimenes and others added 2 commits April 16, 2026 09:23
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tlgimenes tlgimenes merged commit 8eeaebc into main Apr 16, 2026
13 checks passed
@tlgimenes tlgimenes deleted the tlgimenes/explore-createtool branch April 16, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant