Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

xrange

Retrieve entries from a Redis stream. Specify the stream key and an optional count to limit results.

Instructions

Read entries from a Redis stream.

Args: key (str): The stream key. count (int, optional): Number of entries to retrieve.

Returns: str: The retrieved stream entries or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
countNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The xrange tool handler function that reads entries from a Redis stream using redis-py's xrange() and returns them as a string.
    @mcp.tool()
    async def xrange(key: str, count: int = 1) -> str:
        """Read entries from a Redis stream.
    
        Args:
            key (str): The stream key.
            count (int, optional): Number of entries to retrieve.
    
        Returns:
            str: The retrieved stream entries or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            entries = r.xrange(key, count=count)
            return str(entries) if entries else f"Stream {key} is empty or does not exist"
        except RedisError as e:
            return f"Error reading from stream {key}: {str(e)}"
  • The @mcp.tool() decorator registers xrange as an MCP tool. The MCP server is initialized in src/common/server.py and auto-loads all tools from src/tools/.
    @mcp.tool()
    async def xrange(key: str, count: int = 1) -> str:
  • Type annotations define the input schema: key (str) and count (int, default=1). The return type is str.
    async def xrange(key: str, count: int = 1) -> str:
        """Read entries from a Redis stream.
    
        Args:
            key (str): The stream key.
            count (int, optional): Number of entries to retrieve.
    
        Returns:
            str: The retrieved stream entries or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            entries = r.xrange(key, count=count)
            return str(entries) if entries else f"Stream {key} is empty or does not exist"
        except RedisError as e:
            return f"Error reading from stream {key}: {str(e)}"
  • The FastMCP server instance 'mcp' that hosts the @mcp.tool() decorator, and the load_tools() function that auto-discovers all tool modules.
    import importlib
    import pkgutil
    from mcp.server.fastmcp import FastMCP
    
    
    def load_tools():
  • load_tools() dynamically imports all modules in src/tools/, which causes the @mcp.tool() decorators to execute and register the tools.
    def load_tools():
        import src.tools as tools_pkg
    
        for _, module_name, _ in pkgutil.iter_modules(tools_pkg.__path__):
            importlib.import_module(f"src.tools.{module_name}")
    
    
    # Initialize FastMCP server
    mcp = FastMCP(
        "Redis MCP Server", dependencies=["redis", "python-dotenv", "numpy", "aiohttp"]
    )
    
    # Load tools
    load_tools()
Behavior3/5

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

No annotations exist, so the description must carry the transparency burden. It mentions the return type (str or error message) and implies a read-only operation, but lacks details on behavior for missing keys, pagination, or the fact that xrange returns entries in a specific ID range.

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

Conciseness5/5

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

The description is extremely concise, with only three sentences plus the Args/Returns list. It is front-loaded with the main purpose, and every sentence adds value without redundancy.

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

Completeness3/5

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

Despite the presence of an output schema, the description does not detail what the returned string looks like (e.g., format of entries). It also omits context like the requirement for a stream key to exist, or that xrange works with specific ID ranges. For a tool with two parameters and no nested objects, it is adequate but not fully complete.

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

Parameters2/5

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

With 0% schema description coverage, the description partially compensates by listing the two parameters and their types, but provides no additional semantics beyond the schema's type information. It does not explain the format of 'key' (e.g., stream key naming) or that 'count' limits the number of entries.

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

Purpose5/5

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

The description clearly states 'Read entries from a Redis stream,' which is a specific verb-resource pair. It distinguishes from sibling tools like xadd, xreadgroup, and xdel, all of which have different operations on streams.

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 is provided on when to use this tool versus alternatives like xreadgroup or lrange. The description does not mention the typical use case of retrieving a range of entries by ID or the difference from consumer group reads.

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

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