Skip to main content
Glama
zazencodes

Random Number MCP

by zazencodes

random_int

Generate a random integer between two inclusive bounds. Specify a low and high value to receive a random number within that range.

Instructions

Generate a random integer between low and high (inclusive).

Args: low: Lower bound (inclusive) high: Upper bound (inclusive)

Returns: Random integer between low and high

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lowYes
highYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual implementation of the random_int tool. Validates inputs via validate_range helper and calls random.randint(low, high).
    def random_int(low: int, high: int) -> int:
        """Generate a random integer between low and high (inclusive).
    
        Args:
            low: Lower bound (inclusive)
            high: Upper bound (inclusive)
    
        Returns:
            Random integer between low and high
    
        Raises:
            ValueError: If low > high
            TypeError: If inputs are not integers
        """
        if not isinstance(low, int) or not isinstance(high, int):
            raise TypeError("Both low and high must be integers")
    
        validate_range(low, high)
        return random.randint(low, high)
  • Registers random_int as an MCP tool via @app.tool() decorator on FastMCP. Delegates to tools.random_int.
    @app.tool()
    def random_int(low: int, high: int) -> int:
        """Generate a random integer between low and high (inclusive).
    
        Args:
            low: Lower bound (inclusive)
            high: Upper bound (inclusive)
    
        Returns:
            Random integer between low and high
        """
        return tools.random_int(low, high)
  • The validate_range helper used by random_int to ensure low <= high.
    def validate_range(low: int | float, high: int | float) -> None:
        """Validate that low <= high for range-based functions."""
        if low > high:
            raise ValueError(f"Low value ({low}) must be <= high value ({high})")
  • Tests for random_int, covering basic usage, same bounds, negative ranges, invalid ranges, and non-integer inputs. Effectively documents the expected input/output contract.
    class TestRandomInt:
        """Tests for random_int function."""
    
        def test_random_int_basic(self):
            """Test basic random integer generation."""
            result = random_int(1, 10)
            assert isinstance(result, int)
            assert 1 <= result <= 10
    
        def test_random_int_same_bounds(self):
            """Test random integer with same low and high."""
            result = random_int(5, 5)
            assert result == 5
    
        def test_random_int_negative_range(self):
            """Test random integer with negative range."""
            result = random_int(-10, -1)
            assert isinstance(result, int)
            assert -10 <= result <= -1
    
        def test_random_int_invalid_range(self):
            """Test random integer with invalid range."""
            with pytest.raises(ValueError, match="Low value .* must be <= high value"):
                random_int(10, 5)
    
        def test_random_int_non_integer_input(self):
            """Test random integer with non-integer input."""
            with pytest.raises(TypeError, match="Both low and high must be integers"):
                random_int(1.5, 10)
  • Example usage demonstrating how to call random_int via the MCP client.
    # Demo random_int
    print("\n1. random_int - Generate random integers")
    result = await client.call_tool("random_int", {"low": 1, "high": 100})
    print(f"   Random integer (1-100): {result}")
    
    result = await client.call_tool("random_int", {"low": -10, "high": 10})
    print(f"   Random integer (-10 to 10): {result}")
Behavior2/5

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

With no annotations, the description must disclose all behavioral traits. It states inclusive bounds and return value, but fails to mention that the random generation is not cryptographically secure (relevant given secure_random_int sibling), potential error behavior for invalid bounds, or distribution uniformity. This is insufficient.

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 extremely concise with a clear structure: one line purpose, then bullet-like Args and Returns. Every sentence adds value with no waste.

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

Completeness3/5

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

Given the simplicity (2 params, output schema exists), the description covers the basic functionality. However, it lacks context about cryptographic security (vs secure_random_int) and fails to mention error handling or constraints, which would be useful for complete agent understanding.

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 description adds meaning beyond the schema by explaining 'Lower bound (inclusive)' and 'Upper bound (inclusive)'. However, it does not specify that low must be <= high, which would be helpful. Schema coverage is effectively high because both parameters are explained.

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

Purpose4/5

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

The description clearly states 'Generate a random integer between low and high (inclusive)', which is a specific verb-resource. It distinguishes itself from sibling tools like random_float (generates floats) and random_choices, but does not explicitly differentiate from secure_random_int, which could be confusing.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives. There is no mention of non-cryptographic nature relative to secure_random_int, nor any prerequisites or constraints (e.g., low must be <= high). Usage is only implied by the name.

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/zazencodes/random-number-mcp'

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