tool_result() is the explicit opt-in boundary for returning protocol-native
MCP results. Its content must be created with one of the content_*()
constructors; ordinary R values, including bare lists and JSON strings,
retain the legacy single-text-block conversion used by tool().
Arguments
- content
One content block created by a
content_*()constructor, or an ordered list of such blocks. Omittingcontentpermits automatic text fallback generation fromstructured_content; explicitcontent = list()suppresses fallback and is invalid.- structured_content
Optional named list representing a JSON object. An empty object is allowed.
mcplitedoes not validate this value against a tool's advertised output schema.- is_error
Whether the result reports a tool error.
- meta
Optional named result metadata. MCP wire names such as
_metaare created only during serialization.
Details
When structured_content is supplied and content is omitted,
tool_result() generates exactly one JSON text fallback block. Explicitly
supplied content is preserved as-is and no fallback is appended. Structured
content and tool output schemas are sent only to clients using MCP
2025-06-18 or later; older clients receive the generated text fallback.
Examples
tool_result(content_text("Done."))
#> $content
#> $content[[1]]
#> $type
#> [1] "text"
#>
#> $text
#> [1] "Done."
#>
#> $annotations
#> named list()
#>
#> $meta
#> named list()
#>
#> attr(,"class")
#> [1] "mcplite_content_text" "mcplite_content"
#>
#>
#> $structured_content
#> NULL
#>
#> $is_error
#> [1] FALSE
#>
#> $meta
#> named list()
#>
#> attr(,"class")
#> [1] "mcplite_tool_result"
tool_result(
content = list(
content_text("Generated the plot."),
content_image("base64-data", "image/png")
)
)
#> $content
#> $content[[1]]
#> $type
#> [1] "text"
#>
#> $text
#> [1] "Generated the plot."
#>
#> $annotations
#> named list()
#>
#> $meta
#> named list()
#>
#> attr(,"class")
#> [1] "mcplite_content_text" "mcplite_content"
#>
#> $content[[2]]
#> $type
#> [1] "image"
#>
#> $data
#> [1] "base64-data"
#>
#> $mime_type
#> [1] "image/png"
#>
#> $annotations
#> named list()
#>
#> $meta
#> named list()
#>
#> attr(,"class")
#> [1] "mcplite_content_image" "mcplite_content"
#>
#>
#> $structured_content
#> NULL
#>
#> $is_error
#> [1] FALSE
#>
#> $meta
#> named list()
#>
#> attr(,"class")
#> [1] "mcplite_tool_result"
tool_result(structured_content = list(ok = TRUE, count = 2L))
#> $content
#> $content[[1]]
#> $type
#> [1] "text"
#>
#> $text
#> {"ok":true,"count":2}
#>
#> $annotations
#> named list()
#>
#> $meta
#> named list()
#>
#> attr(,"class")
#> [1] "mcplite_content_text" "mcplite_content"
#>
#>
#> $structured_content
#> $structured_content$ok
#> [1] TRUE
#>
#> $structured_content$count
#> [1] 2
#>
#>
#> $is_error
#> [1] FALSE
#>
#> $meta
#> named list()
#>
#> attr(,"class")
#> [1] "mcplite_tool_result"