add
Calculate the sum of two numbers by providing values for a and b to perform basic addition operations.
Instructions
Add two numbers a + b
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/index.ts:21-28 (handler)The handler function for the 'add' tool that adds two input numbers 'a' and 'b' and returns a text message with the result.async ({ a, b }) => { const sum = a + b; return { content: [ { type: "text", text: `The sum of ${a} and ${b} is ${sum}` } ] }; }
- src/index.ts:16-20 (schema)The tool configuration including input schema (using Zod for numbers a and b), title, and description.{ title: "Addition tool", description: "Add two numbers a + b", inputSchema: { a: z.number(), b: z.number() }, },
- src/index.ts:14-29 (registration)Registers the 'add' tool on the MCP server with name, configuration (schema), and handler function.server.registerTool( "add", { title: "Addition tool", description: "Add two numbers a + b", inputSchema: { a: z.number(), b: z.number() }, }, async ({ a, b }) => { const sum = a + b; return { content: [ { type: "text", text: `The sum of ${a} and ${b} is ${sum}` } ] }; } );