factorial
Use this tool to compute the factorial of a number, essential for mathematical and algorithmic calculations within the Zerodha Trading Bot’s automated trading operations.
Instructions
This tool calculates the factorial of a number
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:40-46 (handler)The handler function computes the factorial of the input number 'a' using a for loop starting from 2 to 'a', multiplying accumulatively.async ({ a }) => { let ans = 1; for (let i = 2; i <= a; i++) ans *= i; return { content: [{ type: "text", text: `${ans}` }], }; }
- index.js:39-39 (schema)Zod schema defining the input parameter 'a' as a number.{ a: z.number() },
- index.js:36-47 (registration)Registration of the 'factorial' MCP tool using McpServer.tool, including name, description, schema, and inline handler.server.tool( "factorial", "This tool calculates the factorial of a number", { a: z.number() }, async ({ a }) => { let ans = 1; for (let i = 2; i <= a; i++) ans *= i; return { content: [{ type: "text", text: `${ans}` }], }; } );