random_number
Generate a random number within a defined range using customizable minimum and maximum values. Ideal for tasks requiring randomized data selection or testing scenarios.
Instructions
Generate a random number within a specified range.
Args:
min_value: Minimum value (default: 1)
max_value: Maximum value (default: 100)
Returns:
Dictionary containing the random number and range info
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_value | No | ||
| min_value | No |
Implementation Reference
- mcp_ahrefs/tools/example_tools.py:40-58 (handler)The main handler function that implements the random_number tool logic, generating a random integer between min_value and max_value inclusive, with validation and metadata return.async def random_number(min_value: int = 1, max_value: int = 100) -> Dict[str, Any]: """Generate a random number within a specified range. Args: min_value: Minimum value (default: 1) max_value: Maximum value (default: 100) Returns: Dictionary containing the random number and range info """ if min_value > max_value: raise ValueError("min_value must be less than or equal to max_value") number = random.randint(min_value, max_value) return { "number": number, "range": f"{min_value}-{max_value}", "timestamp": time.time() }
- mcp_ahrefs/server/app.py:98-111 (registration)Registration loop that applies SAAGA decorators (exception handling and logging) to each tool in example_tools list (including random_number) and registers them explicitly with mcp_server.tool(name=tool_name).for tool_func in example_tools: # Apply SAAGA decorator chain: exception_handler → tool_logger decorated_func = exception_handler(tool_logger(tool_func, config.__dict__)) # Extract metadata from the original function tool_name = tool_func.__name__ # Register the decorated function directly with MCP # This preserves the function signature for parameter introspection mcp_server.tool( name=tool_name )(decorated_func) unified_logger.info(f"Registered tool: {tool_name}")
- mcp_ahrefs/tools/example_tools.py:178-183 (registration)The list of regular example tools that includes the random_number handler function, which is imported into server/app.py and registered via the loop.example_tools = [ echo_tool, get_time, random_number, calculate_fibonacci ]
- mcp_ahrefs/server/app.py:23-23 (registration)Import statement that brings in the example_tools list containing random_number for subsequent registration.from mcp_ahrefs.tools.example_tools import example_tools, parallel_example_tools