alepha@docs:~/docs/reference/primitives$
cat $tool.md1 min read
#$tool
#Import
typescript
1import { $tool } from "alepha/mcp";
#Overview
Creates an MCP tool primitive for defining callable functions.
Tools are the primary way for LLMs to interact with external systems through MCP. Each tool has a name, description, typed parameters, and a handler function.
Key Features
- Full TypeScript inference for parameters and results
- Automatic schema validation using TypeBox
- JSON Schema generation for MCP protocol
- Integration with MCP server provider
#Options
| Option | Type | Required | Description |
|---|---|---|---|
name |
string |
No | The name of the tool |
description |
string |
Yes | A human-readable description of what the tool does |
schema |
T |
No | TypeBox schema defining the tool's parameters and result type |
handler |
Object |
Yes | The handler function that executes when the tool is called |
#Examples
ts
1class CalculatorTools { 2 add = $tool({ 3 description: "Add two numbers together", 4 schema: { 5 params: t.object({ 6 a: t.number(), 7 b: t.number(), 8 }), 9 result: t.number(),10 },11 handler: async ({ params }) => {12 return params.a + params.b;13 },14 });15 16 greet = $tool({17 description: "Generate a greeting message",18 schema: {19 params: t.object({20 name: t.text(),21 }),22 result: t.text(),23 },24 handler: async ({ params }) => {25 return `Hello, ${params.name}!`;26 },27 });28}