add
Perform numerical addition by inputting two numbers to calculate their sum using this calculation tool from the Demo MCP Server.
Instructions
Add two numbers together
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | First number | |
| b | Yes | Second number |
Implementation Reference
- src/tools/calculator-tools.ts:26-33 (handler)The handler function that takes two numbers a and b, computes their sum, and returns a text response with the result.async ({ a, b }) => ({ content: [ { type: "text", text: `${a} + ${b} = ${a + b}` } ] })
- src/tools/calculator-tools.ts:21-24 (schema)Input schema using Zod for validating two numeric parameters: a and b.inputSchema: { a: z.number().describe("First number"), b: z.number().describe("Second number") }
- src/tools/calculator-tools.ts:16-34 (registration)Registration of the 'add' tool using server.registerTool, specifying name, title, description, input schema, and handler function.server.registerTool( "add", { title: "Addition Tool", description: "Add two numbers together", inputSchema: { a: z.number().describe("First number"), b: z.number().describe("Second number") } }, async ({ a, b }) => ({ content: [ { type: "text", text: `${a} + ${b} = ${a + b}` } ] }) );