add
Calculate the sum of two numbers using structured input parameters for precise arithmetic operations.
Instructions
Add two numbers.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | The first number to add. | |
| b | Yes | The second number to add. |
Implementation Reference
- src/mcpserver/index.ts:23-30 (handler)Handler function for the 'add' tool that computes the sum of two numbers and returns it in both text and structured format.async ({ a, b }: { a: number; b: number }) => { const output = { result: a + b }; return { content: [{ type: "text", text: JSON.stringify(output) }], structuredContent: output, }; }
- src/mcpserver/index.ts:15-22 (schema)Schema definition for the 'add' tool, specifying title, description, input parameters 'a' and 'b' as numbers, and output 'result' as number.title: "addition tool", description: "Add two numbers.", inputSchema: { a: z.number().describe("The first number to add."), b: z.number().describe("The second number to add."), }, outputSchema: { result: z.number() }, },
- src/mcpserver/index.ts:12-31 (registration)Registration of the 'add' tool on the MCP server, including schema and handler function.server.registerTool( "add", { title: "addition tool", description: "Add two numbers.", inputSchema: { a: z.number().describe("The first number to add."), b: z.number().describe("The second number to add."), }, outputSchema: { result: z.number() }, }, async ({ a, b }: { a: number; b: number }) => { const output = { result: a + b }; return { content: [{ type: "text", text: JSON.stringify(output) }], structuredContent: output, }; } );