add
Add two numbers together using the Math-MCP server’s API, enabling accurate numerical calculations for LLMs by processing defined input values.
Instructions
Adds two numbers together
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| firstNumber | Yes | The first addend | |
| secondNumber | Yes | The second addend |
Implementation Reference
- src/index.ts:26-38 (registration)Registration of the 'add' tool including description, input schema using Zod, and the handler function that delegates to Arithmetic.add and formats the response.
mathServer.tool("add", "Adds two numbers together", { firstNumber: z.number().describe("The first addend"), secondNumber: z.number().describe("The second addend") }, async ({ firstNumber, secondNumber }) => { const value = Arithmetic.add(firstNumber, secondNumber) return { content: [{ type: "text", text: `${value}` }] } }) - src/index.ts:29-38 (handler)The handler function for the 'add' tool, which performs the addition via Arithmetic.add and returns a text response.
}, async ({ firstNumber, secondNumber }) => { const value = Arithmetic.add(firstNumber, secondNumber) return { content: [{ type: "text", text: `${value}` }] } }) - src/index.ts:27-28 (schema)Zod schema defining the input parameters for the 'add' tool: two numbers.
firstNumber: z.number().describe("The first addend"), secondNumber: z.number().describe("The second addend") - src/Classes/Arithmetic.ts:8-11 (helper)Arithmetic.add static method implementing the core addition logic.
static add(firstNumber: number, secondNumber: number): number { const sum = firstNumber + secondNumber; return sum }