Skip to main content
Glama

generate_rarity

Distribute items across rarity tiers with defined probabilities and optional minimum guarantees. Input item count, tiers, percentages, and salt for entropy. Used in games, finance, and testing.

Instructions

Rarity Distributor Args: item_count: Number of items rarity_tiers: Array of rarity tiers rarity_percentages: Probability percentage for each rarity tier guaranteed_minimums: Minimum guaranteed count for each rarity tier (optional) salt: Additional entropy source

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guaranteed_minimumsNo
item_countYes
rarity_percentagesYes
rarity_tiersYes
saltNo

Implementation Reference

  • main.py:300-310 (handler)
    Handler function for the 'generate_rarity' tool, registered via @mcp.tool(). Delegates execution to the rarity_distributor helper.
    @mcp.tool()
    async def generate_rarity(item_count: int, rarity_tiers: List[str], rarity_percentages: List[float], guaranteed_minimums: Optional[List[int]] = None, salt: str="") -> str:
        """Rarity Distributor
        Args:
            item_count: Number of items
            rarity_tiers: Array of rarity tiers
            rarity_percentages: Probability percentage for each rarity tier
            guaranteed_minimums: Minimum guaranteed count for each rarity tier (optional)
            salt: Additional entropy source
        """
        return await rarity_distributor(item_count, rarity_tiers, rarity_percentages, guaranteed_minimums, salt)
  • Core helper function implementing the rarity distribution logic using blockchain-derived random seeds and numpy for probabilistic assignments, handling guaranteed minimums and percentage-based distribution.
    async def rarity_distributor(item_count: int, rarity_tiers: List[str], rarity_percentages: List[float], guaranteed_minimums: Optional[List[int]] = None, salt: str="") -> Dict:
        """
        Rarity distributor
        
        Distribute items across rarity tiers based on specified percentages
        
        Args:
            item_count: Total number of items
            rarity_tiers: List of rarity tier names
            rarity_percentages: Percentage for each rarity tier
            guaranteed_minimums: Minimum guaranteed items per tier
            salt: Optional salt value for additional randomness
            
        Returns:
            Dict containing rarity assignments and tier counts
        """
        if len(rarity_tiers) != len(rarity_percentages):
            raise ValueError("Tiers and percentages must have the same length")
        
        if guaranteed_minimums and len(guaranteed_minimums) != len(rarity_tiers):
            raise ValueError("Guaranteed minimums must match tiers length if provided")
        
        random_num = await get_random_str()
        if not random_num:
            return {"error": "Failed to get random number"}
        request_id = generate_request_id(random_num)
        seed = _derive_seed(request_id, salt)
        np.random.seed(seed)
        
        # Initialize guaranteed minimums
        tier_counts = {tier: 0 for tier in rarity_tiers}
        assignments = [""] * item_count
        remaining_items = item_count
        
        # Handle guaranteed minimums
        if guaranteed_minimums:
            for i, tier in enumerate(rarity_tiers):
                min_count = guaranteed_minimums[i]
                if min_count > 0:
                    # Randomly assign guaranteed minimums
                    indices = np.random.choice(
                        [i for i, a in enumerate(assignments) if a == ""],
                        size=min(min_count, remaining_items),
                        replace=False
                    )
                    
                    for idx in indices:
                        assignments[idx] = tier
                        tier_counts[tier] += 1
                        remaining_items -= 1
        
        # Handle remaining items
        if remaining_items > 0:
            # Normalize percentages
            percentages = np.array(rarity_percentages, dtype=float)
            percentages = percentages / np.sum(percentages)
            
            # Randomly assign remaining items
            remaining_indices = [i for i, a in enumerate(assignments) if a == ""]
            remaining_assignments = np.random.choice(
                rarity_tiers,
                size=remaining_items,
                p=percentages
            )
            
            for i, idx in enumerate(remaining_indices):
                tier = remaining_assignments[i]
                assignments[idx] = tier
                tier_counts[tier] += 1
        
        result = {
            "requestId": request_id,
            "rarityAssignments": assignments,
            "tierCounts": tier_counts
        }
        
        return result
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It lists parameters but doesn't explain what the tool actually does behaviorally - how items are generated, what the output format is, whether it's deterministic with salt, or any constraints. The title 'Rarity Distributor' suggests distribution behavior but lacks operational details needed for an agent to understand the tool's behavior.

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

Conciseness4/5

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

The description is appropriately sized and structured with a title followed by parameter list. Each parameter gets a brief explanation. There's no wasted text, though it could be more front-loaded with a purpose statement. The structure is clear but could be more efficient in conveying the tool's purpose upfront.

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

Completeness2/5

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

Given 5 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lists parameters but doesn't explain the tool's operation, output format, or behavioral characteristics. For a tool with this complexity (rarity distribution with probabilities and guarantees), the description should explain how the distribution works, what gets returned, and any constraints or edge cases.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate. It lists all 5 parameters with brief explanations, adding meaning beyond the schema's property names. However, explanations are minimal (e.g., 'Number of items' for item_count, 'Additional entropy source' for salt) and don't fully clarify parameter relationships or constraints. The description adds some value but doesn't fully compensate for the 0% schema coverage.

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

Purpose3/5

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

The description provides a title 'Rarity Distributor' which implies distributing items by rarity, but lacks a clear verb-action statement. It distinguishes from siblings by focusing on rarity distribution rather than general random generation, but doesn't explicitly state what the tool does (e.g., 'generate items with specified rarity distribution'). The purpose is somewhat vague but not tautological.

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 sibling tools like 'generate_random_weighted' or 'generate_distribution'. The description lists parameters but doesn't provide context about appropriate use cases, prerequisites, or alternatives. Usage is implied through parameter names but not explicitly stated.

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

Related 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/suxiongye/random-web3-mcp'

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