Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

zadd

Add members with scores to a Redis sorted set and optionally set expiration times for time-sensitive data management.

Instructions

Add a member to a Redis sorted set with an optional expiration time.

Args: key (str): The sorted set key. score (float): The score of the member. member (str): The member to add. expiration (int, optional): Expiration time in seconds.

Returns: str: Confirmation message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
scoreYes
memberYes
expirationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'zadd' tool. It is decorated with @mcp.tool(), which registers it as an MCP tool. The function adds a member with a score to a Redis sorted set and optionally sets an expiration on the key.
    @mcp.tool()
    async def zadd(
        key: str, score: float, member: str, expiration: Optional[int] = None
    ) -> str:
        """Add a member to a Redis sorted set with an optional expiration time.
    
        Args:
            key (str): The sorted set key.
            score (float): The score of the member.
            member (str): The member to add.
            expiration (int, optional): Expiration time in seconds.
    
        Returns:
            str: Confirmation message or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            r.zadd(key, {member: score})
            if expiration:
                r.expire(key, expiration)
            return f"Successfully added {member} to {key} with score {score}" + (
                f" and expiration {expiration} seconds" if expiration else ""
            )
        except RedisError as e:
            return f"Error adding to sorted set {key}: {str(e)}"
  • Input schema defined by function parameters with type hints and comprehensive docstring describing args and return type.
    async def zadd(
        key: str, score: float, member: str, expiration: Optional[int] = None
    ) -> str:
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 'optional expiration time' which adds some behavioral context, but doesn't disclose critical traits like whether this is a write operation (implied but not stated), potential side effects (e.g., overwriting existing members), error conditions, or performance characteristics. For a mutation tool with zero annotation coverage, this is inadequate.

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?

Perfectly structured and concise. The first sentence states the core purpose, followed by clearly labeled Args and Returns sections. Every sentence earns its place with no wasted words, and information is front-loaded appropriately.

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?

Given this is a mutation tool with no annotations and 4 parameters, the description is moderately complete. It explains parameters well and has an output schema (so return values are covered), but lacks behavioral context about write operations, error handling, or relationships to sibling tools. For a Redis command with potential side effects, more guidance would be helpful.

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 explanations for all 4 parameters: key identifies the sorted set, score is the member's score, member is what's being added, and expiration is optional with units (seconds). This adds substantial meaning beyond the bare schema, though it doesn't explain score semantics (e.g., ordering) or expiration behavior details.

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 a member to a Redis sorted set') and resource ('Redis sorted set'), distinguishing it from siblings like zrange (reads sorted sets) or zrem (removes from sorted sets). The verb 'add' is precise and the resource type is explicitly identified.

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. While it's clear this is for adding to sorted sets, there's no mention of when to choose zadd over other set operations (like sadd for regular sets) or how it relates to similar tools like xadd (for streams). The description lacks context about prerequisites or typical use cases.

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