lrange
Retrieve elements from a Redis list by specifying a start and stop index range. Use this tool to extract specific segments of list data stored in Redis databases.
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 'lrange' tool handler: an async function decorated with @mcp.tool() that retrieves a range of elements from a Redis list using the Redis client's lrange method, returns them as a JSON string or an error message.@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)}"
- src/tools/list.py:59-59 (registration)The @mcp.tool() decorator registers the lrange function as an MCP tool.@mcp.tool()
- src/tools/list.py:60-65 (schema)Type hints and docstring define the input schema (name: str, start: int, stop: int) and output (JSON string or list/error str).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. """