Skip to main content
MCP Apps SDK

Overview

The ontoolcancelled notification handler is called when tool execution is cancelled. Cancellation can occur for several reasons: the user manually stops the tool, a timeout is reached, or a host-side classifier intervenes. Use this handler to clean up in-progress state, stop animations, and display appropriate feedback to the user. Like all notification handlers, ontoolcancelled should be registered before calling connect().
Register handlers before calling connect() to avoid missing notifications during the initialization handshake.

Signature

Parameters

params.reason
string
Optional reason for the cancellation. May describe the cause (e.g., user action, timeout, or classifier intervention).

Usage

Basic cancellation handling

Cleaning up in-progress state

Combining with the full tool lifecycle

Using with the sunpeak framework

The sunpeak framework provides the useToolData hook, which manages the full tool lifecycle including cancellation as a reactive value.