Skip to main content
Glama
zazencodes

Random Number MCP

by zazencodes

secure_token_hex

Generate a cryptographically secure random hex token for authentication and security purposes. Specify the number of bytes to control length.

Instructions

Generate a secure random hex token.

Args: nbytes: Number of random bytes to generate (default 32)

Returns: Hex string containing 2*nbytes characters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nbytesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual implementation of secure_token_hex. Uses secrets.token_hex to generate a cryptographically secure random hex string. Validates nbytes via validate_positive_int (must be int >= 0), then calls secrets.token_hex.
    def secure_token_hex(nbytes: int = 32) -> str:
        """Generate a secure random hex token.
    
        Args:
            nbytes: Number of random bytes to generate (default 32)
    
        Returns:
            Hex string containing 2*nbytes characters
    
        Raises:
            ValueError: If nbytes < 0
            TypeError: If nbytes is not an integer
        """
        validate_positive_int(nbytes, "nbytes")
        return secrets.token_hex(nbytes)
  • The MCP tool decorator (@app.tool()) that registers secure_token_hex as a callable tool. It delegates to tools.secure_token_hex.
    @app.tool()
    def secure_token_hex(nbytes: int = 32) -> str:
        """Generate a secure random hex token.
    
        Args:
            nbytes: Number of random bytes to generate (default 32)
    
        Returns:
            Hex string containing 2*nbytes characters
        """
        return tools.secure_token_hex(nbytes)
  • The validate_positive_int helper used by secure_token_hex to ensure nbytes is a non-negative integer.
    def validate_positive_int(value: int, name: str) -> None:
        """Validate that a value is a positive integer."""
        if not isinstance(value, int):
            raise TypeError(f"{name} must be an integer, got {type(value).__name__}")
        if value < 0:
            raise ValueError(f"{name} must be non-negative, got {value}")
  • Input/output schema is defined by the function signature: nbytes: int = 32 (input) -> str (output). The docstring specifies the return value is a hex string of 2*nbytes characters.
    def secure_token_hex(nbytes: int = 32) -> str:
        """Generate a secure random hex token.
    
        Args:
            nbytes: Number of random bytes to generate (default 32)
    
        Returns:
            Hex string containing 2*nbytes characters
    
        Raises:
            ValueError: If nbytes < 0
            TypeError: If nbytes is not an integer
        """
        validate_positive_int(nbytes, "nbytes")
        return secrets.token_hex(nbytes)
Behavior2/5

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

With no annotations, the description carries the full burden. It mentions 'secure random' implying cryptographic security, but does not disclose potential behavioral traits like performance, blocking, or error conditions for invalid input.

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 concise with clear Args and Returns sections. Every sentence is informative, no redundancy, and efficiently structured for a single-parameter tool.

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 simplicity, the description covers input parameter and output format well via the docstring. Missing edge-case constraints (e.g., nbytes=0) but still sufficient for basic use. Output schema exists, so return details are adequately handled.

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?

Schema coverage is 0%, so the description compensates well by explaining the nbytes parameter: number of random bytes, default 32. It adds meaning beyond the schema's type and default, though could clarify that nbytes must be positive.

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 generates a secure random hex token, with specific verb 'generate' and resource 'secure random hex token'. It differentiates from sibling tools like random_choices, random_int, etc., which serve different purposes.

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?

No explicit when-to-use or when-not-to-use guidance is provided. The name and description imply it is for secure hex tokens, distinguishing it from siblings, but there is no direct comparison or exclusion statement.

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