Skip to main content
Glama
xiaoyuchenhot

MCP Multi-Tool Server

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it specifies the mathematical operation, input constraints (non-negative integer), return value, and error handling (raises ValueError for negative inputs). It doesn't cover performance aspects like rate limits or computational complexity, but provides sufficient context for basic use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by definition, example, and sections for args, returns, and raises. Every sentence adds value without redundancy, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (single parameter, mathematical function) and the presence of an output schema (which handles return values), the description is largely complete. It covers purpose, usage, parameters, and errors adequately. A minor gap is lack of explicit sibling tool differentiation, but overall it meets needs for this simple tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate. It adds meaningful semantics by defining 'n' as a non-negative integer, explaining what factorial means with an example, and detailing error conditions. This goes beyond the bare schema, though it could elaborate on large integer handling or recursion limits.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool calculates the factorial of a non-negative integer, providing a specific mathematical operation ('calculate the factorial') and distinguishing it from sibling tools like add, multiply, etc. It includes a mathematical definition and example, making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for factorial calculations but doesn't explicitly state when to use this tool versus alternatives like 'power' or 'multiply' for related operations. It mentions the input constraint (non-negative integer) but lacks guidance on specific scenarios or comparisons with sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/xiaoyuchenhot/MCP-example'

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