add
Perform addition of two numbers using this tool, designed for basic mathematical operations within the Calculator MCP server. Input two numerical values to get the sum instantly.
Instructions
Add two numbers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/tools/add.ts:12-18 (handler)The handler function that executes the 'add' tool logic: extracts numbers a and b from params, computes their sum, and returns a formatted text response.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)Defines the tool schema including name, description, and input schema (requiring numbers a and b) converted to JSON schema via Zod.schema: { name: "add", description: "Add two numbers", inputSchema: zodToJsonSchema(z.object({ a: z.number(), b: z.number() })), },
- src/server.ts:7-9 (registration)Imports the 'add' tool (along with others) from './tools' and registers it in the 'tools' array, which is used by the MCP server's listTools and callTool handlers.import { add, div, mod, mul, sqrt, sub } from "./tools"; const tools = [add, div, mod, mul, sqrt, sub];