Skip to main content

Overview

Returns a function to invoke other MCP tools registered on the server. Useful for multi-step workflows where one app needs to trigger another tool.

Import

import { useCallServerTool } from 'sunpeak';

Signature

function useCallServerTool(): (params: CallServerToolParams) => Promise<CallServerToolResult | undefined>

CallServerToolParams

name
string
required
Name of the MCP tool to call.
arguments
Record<string, unknown>
Arguments to pass to the tool.

Returns

callTool
(params: CallServerToolParams) => Promise<CallServerToolResult | undefined>
Function to call an MCP server tool.

CallServerToolResult

content
Array<{ type: string; text?: string }>
Tool response content.
isError
boolean
Whether the tool call resulted in an error.

Usage

import { useCallServerTool } from 'sunpeak';

function ReviewResource() {
  const callTool = useCallServerTool();

  const handleApply = async () => {
    const result = await callTool({
      name: 'apply_changes',
      arguments: { changesetId: 'cs_789' },
    });
    console.log('Tool result:', result);
  };

  return <button onClick={handleApply}>Apply Changes</button>;
}