factorial
Calculate the factorial of a non-negative integer to solve mathematical problems involving permutations, combinations, or recursive calculations.
Instructions
Calculate the factorial of a non-negative integer.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n | Yes |
Implementation Reference
- server.py:108-114 (handler)The handler function implementing the logic for the 'factorial' MCP tool. It validates the input integer n (non-negative and <=100) and computes factorial using math.factorial.def factorial(n: int) -> int: """Calculate the factorial of a non-negative integer.""" if n < 0: raise ValueError("Factorial is not defined for negative numbers") if n > 100: raise ValueError("Number too large for factorial calculation") return math.factorial(n)
- server.py:107-107 (registration)The @mcp.tool() decorator registers the factorial function as an MCP tool, making it available for invocation.@mcp.tool()