generateHelpers is a factory function that creates fully typed versions of useCallTool and useToolInfo hooks with end-to-end type inference from your MCP server definition. Inspired by TRPC and Hono, it provides a type-safe, developer-friendly API that eliminates the need for manual type annotations.
Why generateHelpers?
If you’re familiar with TRPC or Hono,generateHelpers provides a similar developer experience:
- Full type inference: Tool names, inputs, and outputs are automatically inferred from your server
- Autocomplete: Get IntelliSense suggestions for all available tools
- Type safety: Catch errors at compile time, not runtime
Prerequisites
Server Must Use Method Chaining
Your MCP server must use method chaining for type inference to work. See Type Safety: Method Chaining for details.Export Server Type
Export your server type so it can be imported in your web code:Quick Start
1. One-Time Setup
Create a bridge file that connects your server types to your widgets:2. Use Typed Hooks in Widgets
Import and use the typed hooks throughout your app:API Reference
Type Parameters
T
typeof server to get the type:
The server type must be defined using method chaining for type inference to work correctly. See Prerequisites for more details.
Returns
An object containing typed versions ofuseCallTool and useToolInfo hooks:
useCallTool
A typed version of the useCallTool hook that provides autocomplete for tool names and full type inference for inputs and outputs.
name
Return Value
The typeduseCallTool returns the same structure as the untyped version, but with automatically inferred types. See the useCallTool API reference for detailed documentation on all return properties.
useToolInfo
A typed version of the useToolInfo hook that provides autocomplete for tool names and full type inference for inputs, outputs, and response metadata.
Type Parameter K
Limitations
- Chaining Required: Server must use method chaining for type inference to work
- Runtime Types: Types are inferred at compile time; runtime validation still uses Zod schemas
- Callback Return Type: Output types are inferred from the callback’s return value, not
outputSchema
