div
Divide one number by another to return the quotient.
Instructions
Divide two numbers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/tools/div.ts:12-17 (handler)The handler function for the 'div' tool. It divides two numbers (a/b) and returns the result as text content.
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 division of ${a} and ${b} is ${result}` }] }; }, - src/tools/div.ts:6-18 (schema)The full tool definition including the schema (name: 'div', description, inputSchema with a: number, b: number) and the handler.
export const div: Tool = { schema: { name: "div", description: "Divide 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 division of ${a} and ${b} is ${result}` }] }; }, }; - src/server.ts:7-9 (registration)The 'div' tool is imported from ./tools and added to the tools array, which is then registered with the MCP server via ListToolsRequestSchema and CallToolRequestSchema handlers.
import { add, div, mod, mul, sqrt, sub } from "./tools"; const tools = [add, div, mod, mul, sqrt, sub]; - src/tools/index.ts:2-2 (registration)Re-exports the div tool from ./div, making it available via the barrel index.
export * from "./div"; - src/tools/types.ts:15-18 (helper)The Tool interface type that the div export conforms to, defining the schema and handle structure.
export interface Tool { schema: ToolSchema; handle: (params: Record<string, unknown>) => Promise<ToolResult>; }