Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

zrem

Remove a member from a Redis sorted set by providing the key and member name.

Instructions

Remove a member from a Redis sorted set.

Args: key (str): The sorted set key. member (str): The member to remove.

Returns: str: Confirmation message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
memberYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The zrem tool handler: removes a member from a Redis sorted set using r.zrem() and returns a confirmation or error message.
    @mcp.tool()
    async def zrem(key: str, member: str) -> str:
        """Remove a member from a Redis sorted set.
    
        Args:
            key (str): The sorted set key.
            member (str): The member to remove.
    
        Returns:
            str: Confirmation message or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            result = r.zrem(key, member)
            return (
                f"Successfully removed {member} from {key}"
                if result
                else f"Member {member} not found in {key}"
            )
        except RedisError as e:
            return f"Error removing from sorted set {key}: {str(e)}"
  • The @mcp.tool() decorator registers the zrem function as an MCP tool.
    @mcp.tool()
    async def zrem(key: str, member: str) -> str:
  • File imports: RedisConnectionManager for DB connection, RedisError for error handling, and the mcp server for tool registration.
    from typing import Optional
    
    from redis.exceptions import RedisError
    
    from src.common.connection import RedisConnectionManager
    from src.common.server import mcp
    
    
    @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)}"
    
    
    @mcp.tool()
    async def zrange(key: str, start: int, end: int, with_scores: bool = False) -> str:
        """Retrieve a range of members from a Redis sorted set.
    
        Args:
            key (str): The sorted set key.
            start (int): The starting index.
            end (int): The ending index.
            with_scores (bool, optional): Whether to include scores in the result.
    
        Returns:
            str: The sorted set members in the given range or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            members = r.zrange(key, start, end, withscores=with_scores)
            return (
                str(members) if members else f"Sorted set {key} is empty or does not exist"
            )
        except RedisError as e:
            return f"Error retrieving sorted set {key}: {str(e)}"
    
    
    @mcp.tool()
    async def zrem(key: str, member: str) -> str:
        """Remove a member from a Redis sorted set.
    
        Args:
            key (str): The sorted set key.
            member (str): The member to remove.
    
        Returns:
            str: Confirmation message or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            result = r.zrem(key, member)
            return (
                f"Successfully removed {member} from {key}"
                if result
                else f"Member {member} not found in {key}"
            )
        except RedisError as e:
            return f"Error removing from sorted set {key}: {str(e)}"
Behavior3/5

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

With no annotations, the description must fully disclose behavior. It states the tool removes a member and returns a confirmation or error, but lacks details on side effects (e.g., whether the sorted set must exist, idempotency, or behavior when the member is absent). This is adequate but not comprehensive.

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, using a single sentence to state the purpose followed by structured parameter documentation. There is no fluff, and every sentence serves a clear purpose.

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 the simple nature of the tool (2 parameters, no nested objects), the description covers the basics. However, it omits edge cases like missing keys or duplicate members. The return value is explained, but output schema exists, so less burden. Overall, it meets minimal requirements but could be more thorough.

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?

Schema description coverage is 0%, but the description adds minimal value beyond parameter names ('The sorted set key' and 'The member to remove'). It does not provide format, constraints, or example values, which would be helpful for correct invocation.

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 explicitly states 'Remove a member from a Redis sorted set,' which is a specific verb-resource combination. This clearly differentiates it from sibling tools like srem (set removal), hdel (hash deletion), and lrem (list removal), all of which operate on different data structures.

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 such as srem, hdel, or delete. The description only explains what the tool does, without contextual hints about scenarios where zrem is preferred.

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