Overview
Theontoolresult notification handler is called when the host sends the result of a tool execution. The result includes readable text content, optional model-visible structured data for the UI, component-only _meta, and an error flag.
Like all notification handlers, ontoolresult should be registered before calling connect().
Signature
Parameters
CallToolResult
Standard MCP tool execution result containing the following fields:
ContentBlock[]
Text content blocks intended for model context.
Record<string, unknown>
Structured data optimized for programmatic use. The model may read this data too, so keep private fields in
_meta.boolean
Whether the tool returned an error. When
true, content contains error details.object
Optional metadata attached to the result (for example a
progressToken or a related-task reference). Fields here are protocol-level and host-defined; do not assume application fields unless your server sets them.Usage
Handling success and error states
Rendering structured content
Using with the sunpeak framework
The sunpeak framework provides theuseToolData hook, which wraps ontoolresult (along with related handlers) into a reactive value for React components.
Related
- Event Handlers overview — all notification and request handlers
- ontoolinput — receive complete tool arguments before the result