Skip to main content
MCP Apps SDK

Overview

oncalltool is a request handler that receives tool calls from the host directed at your app. This enables bidirectional tool communication — in addition to calling server tools, the host (or model) can call tools that the View implements. To use oncalltool, you must declare the tools capability when constructing the App. The host discovers available tools through onlisttools, then calls them through this handler. Because this is a request handler, the host waits for your response. Return a result object containing content blocks, or throw an error to signal failure.

Signature

Parameters

params
object
required
The tool call parameters sent by the host.
name
string
required
Name of the tool being called. Must match one of the tools declared in onlisttools.
arguments
Record<string, unknown>
Tool arguments as key-value pairs. The shape corresponds to the tool’s inputSchema.
Register handlers before calling connect() to avoid missing notifications during the initialization handshake.

Usage

Declare tools capability and handle calls

Handle multiple tools with structured results

Return errors without throwing

For expected failures, return an error result instead of throwing: