Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

sadd

Add values to Redis sets with optional expiration times to manage collections and implement time-limited data structures.

Instructions

Add a value to a Redis set with an optional expiration time.

Args: name: The Redis set key. value: The value to add to the set. expire_seconds: Optional; time in seconds after which the set should expire.

Returns: A success message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
valueYes
expire_secondsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'sadd' tool, decorated with @mcp.tool() which registers it as an MCP tool. It adds a member to a Redis set with optional expiration time.
    @mcp.tool()
    async def sadd(name: str, value: str, expire_seconds: Optional[int] = None) -> str:
        """Add a value to a Redis set with an optional expiration time.
    
        Args:
            name: The Redis set key.
            value: The value to add to the set.
            expire_seconds: Optional; time in seconds after which the set should expire.
    
        Returns:
            A success message or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            r.sadd(name, value)
    
            if expire_seconds is not None:
                r.expire(name, expire_seconds)
    
            return f"Value '{value}' added successfully to set '{name}'." + (
                f" Expires in {expire_seconds} seconds." if expire_seconds else ""
            )
        except RedisError as e:
            return f"Error adding value '{value}' to set '{name}': {str(e)}"
  • src/tools/set.py:9-10 (registration)
    The @mcp.tool() decorator registers the sadd function as the 'sadd' MCP tool.
    @mcp.tool()
    async def sadd(name: str, value: str, expire_seconds: Optional[int] = None) -> str:
  • The function signature and docstring define the input schema (name: str, value: str, expire_seconds: Optional[int]) and output (str).
    async def sadd(name: str, value: str, expire_seconds: Optional[int] = None) -> str:
        """Add a value to a Redis set with an optional expiration time.
    
        Args:
            name: The Redis set key.
            value: The value to add to the set.
            expire_seconds: Optional; time in seconds after which the set should expire.
    
        Returns:
            A success message or an error message.
        """
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses key behavioral traits: it's a write operation (implied by 'Add'), supports optional expiration, and returns success/error messages. However, it doesn't mention side effects (e.g., duplicates are ignored in sets), idempotency, or error conditions (e.g., invalid key types). It adds value beyond schema but misses some operational details.

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 front-loaded with the core purpose in the first sentence, followed by structured Args and Returns sections. Every sentence adds value: the first explains the action, Args detail parameters, and Returns clarify output. No wasted words, and it's appropriately sized for a 3-parameter tool.

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 no annotations, 3 parameters with 0% schema coverage, and an output schema (implied by Returns), the description is mostly complete. It covers purpose, parameters, and return values. However, it could improve by mentioning Redis-specific behaviors (e.g., set uniqueness) or error handling, but the output schema likely handles return structure.

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 semantics for all 3 parameters: 'name' as the Redis set key, 'value' as the item to add, and 'expire_seconds' as optional expiration time. This fully explains parameter purposes beyond the bare schema, though it lacks format details (e.g., value type constraints).

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 verb ('Add'), resource ('value to a Redis set'), and distinguishes it from siblings by specifying it's for set operations (vs. other Redis data types like strings, hashes, lists, etc.). It explicitly mentions 'Redis set' which differentiates from tools like 'set' (for strings), 'hset' (for hashes), or 'zadd' (for sorted sets).

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

Usage Guidelines4/5

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

The description implies usage context (adding to Redis sets with optional expiration) but doesn't explicitly state when to use this vs. alternatives like 'srem' (remove from set) or 'smembers' (list set members). It does distinguish from non-set operations, providing clear scope, but lacks explicit comparison to sibling set tools.

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