sub
Perform subtraction of two numbers using the Calculator MCP server. Input two numerical values to retrieve the result of the subtraction operation.
Instructions
Subtract two numbers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/tools/sub.ts:6-18 (handler)Full tool definition including schema and handler function for the 'sub' tool. The handler subtracts two numbers and returns a text response.
export const sub: Tool = { schema: { name: "sub", description: "Subtract two numbers", inputSchema: zodToJsonSchema(z.object({ a: z.number(), b: z.number() })), }, 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:7-11 (schema)Schema definition for the 'sub' tool, including name, description, and Zod-based input schema for two numbers.
schema: { name: "sub", description: "Subtract two numbers", inputSchema: zodToJsonSchema(z.object({ a: z.number(), b: z.number() })), }, - src/server.ts:7-9 (registration)Import of the 'sub' tool and registration in the tools array used by the MCP server for listing and calling tools.
import { add, div, mod, mul, sqrt, sub } from "./tools"; const tools = [add, div, mod, mul, sqrt, sub]; - src/tools/index.ts:6-6 (registration)Re-export of the 'sub' tool from index.ts, facilitating barrel import in server.ts.
export * from "./sub";