factorial
Calculate the factorial of a non-negative integer for mathematical computations and probability 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 factorial tool handler: validates that n is non-negative and not too large (>100), then computes and returns math.factorial(n).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.@mcp.tool()