sub
Subtracts the second number from the first to compute the difference between two values.
Instructions
Subtract two numbers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/tools/sub.ts:12-17 (handler)The handler function for the 'sub' tool: subtracts two numbers (a - b) and returns a text response with the difference.
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 difference of ${a} and ${b} is ${result}` }] }; }, - src/tools/sub.ts:6-11 (schema)The schema definition for the 'sub' tool, defining name='sub', description='Subtract two numbers', and an inputSchema requiring two numbers (a and b).
export const sub: Tool = { schema: { name: "sub", description: "Subtract two numbers", inputSchema: zodToJsonSchema(z.object({ a: z.number(), b: z.number() })), }, - src/server.ts:7-9 (registration)The tool is imported from './tools' and placed in the tools array (line 9) which is used to register it with the MCP server.
import { add, div, mod, mul, sqrt, sub } from "./tools"; const tools = [add, div, mod, mul, sqrt, sub]; - src/tools/index.ts:6-6 (helper)Re-exports the 'sub' module from './sub' via the barrel index file.
export * from "./sub";