Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

xadd

Add entries to Redis streams with optional expiration times to manage time-series data or event logs in Redis databases.

Instructions

Add an entry to a Redis stream with an optional expiration time.

Args: key (str): The stream key. fields (dict): The fields and values for the stream entry. expiration (int, optional): Expiration time in seconds.

Returns: str: The ID of the added entry or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
fieldsYes
expirationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The xadd tool handler function implementing the Redis XADD operation with optional expiration handling and error management.
    @mcp.tool()
    async def xadd(
        key: str, fields: Dict[str, Any], expiration: Optional[int] = None
    ) -> str:
        """Add an entry to a Redis stream with an optional expiration time.
    
        Args:
            key (str): The stream key.
            fields (dict): The fields and values for the stream entry.
            expiration (int, optional): Expiration time in seconds.
    
        Returns:
            str: The ID of the added entry or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            entry_id = r.xadd(key, fields)
            if expiration:
                r.expire(key, expiration)
            return f"Successfully added entry {entry_id} to {key}" + (
                f" with expiration {expiration} seconds" if expiration else ""
            )
        except RedisError as e:
            return f"Error adding to stream {key}: {str(e)}"
  • MCP server initialization and tool loading mechanism that imports all src/tools modules, registering the xadd tool via its decorator.
    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", "dotenv", "numpy", "aiohttp"])
    
    # Load tools
    load_tools()
  • Type hints defining the input schema (key: str, fields: dict[str, Any], expiration: Optional[int]) and output (str) for the xadd tool.
    async def xadd(
        key: str, fields: Dict[str, Any], expiration: Optional[int] = None
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the action ('Add') and optional expiration, but lacks details on permissions needed, error conditions, rate limits, whether the operation is idempotent, or what happens on expiration. For a write operation with zero annotation coverage, this is insufficient behavioral disclosure.

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 efficiently structured: a clear purpose statement followed by organized sections for Args and Returns. Every sentence earns its place with no redundant information, and key details are front-loaded in the opening sentence.

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

Completeness4/5

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

Given 3 parameters with 0% schema coverage and an output schema present, the description does well by explaining all parameters semantically and stating the return value. However, as a write operation with no annotations, it should ideally mention more about behavioral aspects like error handling or side effects to be fully complete.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It provides clear semantic explanations for all three parameters: 'key' as the stream key, 'fields' as fields/values for the entry, and 'expiration' as time in seconds. This adds meaningful context beyond the bare schema types, though it doesn't detail field format constraints or expiration behavior.

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 the specific action ('Add an entry'), target resource ('to a Redis stream'), and optional feature ('with an optional expiration time'). It distinguishes this tool from siblings like 'set', 'hset', 'lpush', or 'zadd' by specifying it's for Redis streams specifically.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through 'Add an entry to a Redis stream', suggesting this is for stream data structures rather than other Redis types. However, it doesn't explicitly state when to use this versus alternatives like 'publish' for pub/sub or 'lpush' for lists, nor does it mention prerequisites or exclusions.

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