Call a registered server tool from the view with inferred types.
Successful results populate data and clear error. Tool errors and
transport failures reject and populate error while preserving previous
data. Prefer reading data / error from the handle for React UI; use
try/catch for imperative flows.
const details = useCallTool("get-fruit-details");
// State-driven (typical in React):
// {details.error && <ErrorBanner message={details.error.message} />}
// {details.data && <DetailsCard data={details.data.structuredContent} />}
// Imperative:
try {
const result = await details.callTool({ fruit: "apple" });
showDetails(result.structuredContent);
} catch (err) {
if (err instanceof ToolError) {
showToolError(err.message);
}
}
Call a server tool using a ToolRef value (inline-JSX stretch path).