Skip to main content
Glama

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
NameRequiredDescriptionDefault
nYes

Implementation Reference

  • 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()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vipankumar87/MCP-Example'

If you have feedback or need assistance with the MCP directory API, please join our Discord server