subtract
Calculate the difference between two numbers by subtracting the second value from the first value.
Instructions
Subtract b from a (a - b)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/index.ts:66-73 (handler)The handler function for the 'subtract' tool. It takes inputs 'a' and 'b', computes their difference (a - b), and returns a structured text response containing the result.async ({ a, b }) => { const diff = a - b; return { content: [ { type: "text", text: `The difference of ${a} and ${b} is ${diff}` } ] }; }
- src/index.ts:64-64 (schema)The input schema for the 'subtract' tool, defining 'a' and 'b' as numbers using Zod validation.inputSchema: { a: z.number(), b: z.number() },
- src/index.ts:59-74 (registration)The registration of the 'subtract' tool on the MCP server, including name, metadata, schema, and handler function.server.registerTool( "subtract", { title: "Subtraction tool", description: "Subtract b from a (a - b)", inputSchema: { a: z.number(), b: z.number() }, }, async ({ a, b }) => { const diff = a - b; return { content: [ { type: "text", text: `The difference of ${a} and ${b} is ${diff}` } ] }; } );