add
Calculate the sum of two numbers by providing numeric inputs a and b.
Instructions
Add two numbers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/tools/add.ts:12-17 (handler)The handler function that executes the 'add' tool logic. It takes params (a, b), adds them, and returns a text result.
handle: async (params) => { const a = params.a as number; const b = params.b as number; const result = a + b; return { content: [{ type: "text", text: `The sum of ${a} and ${b} is ${result}` }] }; }, - src/tools/add.ts:7-11 (schema)The schema definition for the 'add' tool, specifying name 'add', description 'Add two numbers', and input schema with two number fields (a, b).
schema: { name: "add", description: "Add two numbers", inputSchema: zodToJsonSchema(z.object({ a: z.number(), b: z.number() })), }, - src/server.ts:7-9 (registration)Import and registration of the 'add' tool (along with others) into the tools array used by the server.
import { add, div, mod, mul, sqrt, sub } from "./tools"; const tools = [add, div, mod, mul, sqrt, sub]; - src/tools/index.ts:1-1 (registration)Re-exports the 'add' module from the tools barrel file.
export * from "./add"; - src/tools/types.ts:15-18 (helper)The Tool interface that the 'add' constant conforms to, defining schema + handle pattern.
export interface Tool { schema: ToolSchema; handle: (params: Record<string, unknown>) => Promise<ToolResult>; }