Skip to main content
sunpeak API

Overview

Tool files define your MCP tools — metadata, input validation, and request handlers. Each .ts file in src/tools/ is auto-discovered by the framework.

File Convention

The filename (without .ts) becomes the tool name used by the MCP server. For example, src/tools/show-albums.ts registers a tool named show-albums.

Structure

Each tool file exports three things:

Exports

tool (AppToolConfig)

resource
string
The resource name, matching a directory in src/resources/ (e.g., 'albums' for src/resources/albums/). Links this tool to its UI. Omit for tools that return data only (no UI).
title
string
Human-readable title for the tool, shown in host UIs.
description
string
Description of what the tool does.
annotations
object
MCP tool annotations.
_meta
object
Tool metadata, including UI visibility.
  • "model" — The AI model can call this tool
  • "app" — The app can call this tool (via useCallServerTool)

schema (Zod record)

A record of Zod types defining the tool’s input parameters. Automatically converted to JSON Schema for the MCP server.

default (handler)

The default export is the tool handler function. It receives the validated input arguments and a ToolHandlerExtra object.
Return types:
  • { structuredContent: unknown } — Structured data passed to the resource via useToolData()
  • { content: [{ type: 'text', text: string }] } — Text content
  • A plain string is normalized to { content: [{ type: 'text', text }] }

ToolHandlerExtra

The extra parameter provides context from the MCP SDK:
authInfo
AuthInfo
Authentication info from the optional src/server.ts auth function.
sessionId
string
Unique session identifier.
signal
AbortSignal
Abort signal for cancellation.

Tools Without UI

Tools that don’t need a UI can omit the resource field. These are registered as plain MCP tools (no resource or iframe). A common pattern is pairing a UI tool (for review) with a backend-only tool (for execution). The review UI calls the backend tool via useCallServerTool after the user confirms:
The UI tool (review-purchase) returns structuredContent with a reviewTool field that tells the review resource which backend tool to call on confirm/cancel:
When the user clicks “Place Order”, the review resource calls useCallServerTool with the arguments plus confirmed: true. The tool returns both content (human-readable text for the host model) and structuredContent (with status and message for the UI). The review resource reads structuredContent.status to determine success/error styling and displays structuredContent.message. The same review tool handles all review variants — purchases, code diffs, social posts — differentiated by the action field. See the template’s review resource for the full implementation. Tools without a UI still appear in the inspector’s tool picker. Selecting one shows Tool does not render a UI in the preview, while the sidebar still lets you edit Tool Input, click Run, and inspect Tool Result. They are registered in the dev MCP server, so they can be called by UI resources via useCallServerTool or by the host directly. In production, they work as standard MCP tools.

Multiple Tools Per Resource

Multiple tool files can reference the same resource by name:
Each tool provides different data to the same UI via useToolData().

See Also

Server Entry

Optional auth and server configuration.

Simulation

Define test fixtures for your tools.