lrange
Retrieve elements from a Redis list within a specified range. Input the list name, start, and stop indices to return a JSON string of the elements or an error message.
Instructions
Get elements from a Redis list within a specific range.
Returns: str: A JSON string containing the list of elements or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| start | Yes | ||
| stop | Yes |
Implementation Reference
- src/tools/list.py:59-74 (handler)The handler function for the 'lrange' MCP tool. It uses RedisConnectionManager to get a connection, calls r.lrange(name, start, stop), converts the result to JSON if successful, or returns an error message. The @mcp.tool() decorator registers the tool and defines the input schema from the function signature (name: str, start: int, stop: int) and output as Union[str, List[str]] which is typically serialized.@mcp.tool() async def lrange(name: str, start: int, stop: int) -> Union[str, List[str]]: """Get elements from a Redis list within a specific range. Returns: str: A JSON string containing the list of elements or an error message. """ try: r = RedisConnectionManager.get_connection() values = r.lrange(name, start, stop) if not values: return f"List '{name}' is empty or does not exist." else: return json.dumps(values) except RedisError as e: return f"Error retrieving values from list '{name}': {str(e)}"