divide
Perform division of two numbers using the Arithmetic MCP Server. Input values 'a' and 'b' to calculate the result, ensuring accurate arithmetic operations via the Model Context Protocol.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- src/index.ts:52-69 (handler)The handler function for the 'divide' tool. It takes two numbers a and b, checks if b is zero to avoid division by zero error, and returns the division result as text content.async ({ a, b }) => { if (b === 0) { return { content: [{ type: "text", text: "エラー: ゼロで割ることはできません" }], isError: true }; } return { content: [{ type: "text", text: `${a} と ${b} の割り算の結果: ${a / b}` }] }; }
- src/index.ts:51-51 (schema)Zod schema defining the input parameters for the 'divide' tool: two required number fields 'a' and 'b'.{ a: z.number(), b: z.number() },
- src/index.ts:49-70 (registration)Registration of the 'divide' tool using the McpServer's tool method, including name, schema, and handler.server.tool( "divide", { a: z.number(), b: z.number() }, async ({ a, b }) => { if (b === 0) { return { content: [{ type: "text", text: "エラー: ゼロで割ることはできません" }], isError: true }; } return { content: [{ type: "text", text: `${a} と ${b} の割り算の結果: ${a / b}` }] }; } );