add
Add two numbers together using structured input. This arithmetic tool calculates the sum of provided numerical values.
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)The handler function for the 'add' tool that takes two numbers a and b, computes their sum, and returns it in both text and structured content.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:14-22 (schema)Schema definition for the 'add' tool, including title, description, input schema (a and b as numbers), and output schema (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 using server.registerTool with name, schema, and handler.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, }; } );