Skip to main content
Glama
codewithmsunke

MCP Math Server

divide

Perform division operations by calculating the quotient of two numbers, handling division by zero errors with proper error management.

Instructions

Divide a by b (a / b)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYes
bYes

Implementation Reference

  • The handler function for the 'divide' tool. It validates that b is not zero, computes the quotient a / b, and returns a textual response with the result or an error.
    async ({ a, b }) => { if (b === 0) { return { content: [ { type: "text", text: `Error: Division by zero is not allowed.` } ], isError: true }; } const quotient = a / b; return { content: [ { type: "text", text: `The quotient of ${a} divided by ${b} is ${quotient}` } ] }; }
  • The input schema for the 'divide' tool, defining parameters 'a' and 'b' as numbers using Zod.
    inputSchema: { a: z.number(), b: z.number() },
  • src/index.ts:169-192 (registration)
    The registration of the 'divide' tool using server.registerTool, including name, metadata (title, description, schema), and handler function.
    server.registerTool( "divide", { title: "Division tool", description: "Divide a by b (a / b)", inputSchema: { a: z.number(), b: z.number() }, }, async ({ a, b }) => { if (b === 0) { return { content: [ { type: "text", text: `Error: Division by zero is not allowed.` } ], isError: true }; } const quotient = a / b; return { content: [ { type: "text", text: `The quotient of ${a} divided by ${b} is ${quotient}` } ] }; } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/codewithmsunke/MCPMathTools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server