factorial
Calculate the factorial of a non-negative integer to find the product of all positive integers up to that number.
Instructions
Calculate the factorial of a non-negative integer.
The factorial of n (written as n!) is the product of all positive integers
less than or equal to n. For example: 5! = 5 × 4 × 3 × 2 × 1 = 120
Args:
n: A non-negative integer
Returns:
The factorial of n
Raises:
ValueError: If n is negative
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n | Yes |
Implementation Reference
- server.py:125-144 (handler)The complete implementation of the 'factorial' MCP tool: @mcp.tool() decorator registers it; function signature with types provides schema; docstring details IO and validation; handler validates input (n >= 0) and computes using math.factorial(n).@mcp.tool() def factorial(n: int) -> int: """ Calculate the factorial of a non-negative integer. The factorial of n (written as n!) is the product of all positive integers less than or equal to n. For example: 5! = 5 × 4 × 3 × 2 × 1 = 120 Args: n: A non-negative integer Returns: The factorial of n Raises: ValueError: If n is negative """ if n < 0: raise ValueError("Factorial is only defined for non-negative integers") return math.factorial(n)