Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

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
NameRequiredDescriptionDefault
nameYes
startYes
stopYes

Implementation Reference

  • 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)}"
  • The @mcp.tool() decorator registers the lrange function as an MCP tool.
    @mcp.tool()
  • 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. """

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/redis/mcp-redis'

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