Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

json_set

Set JSON values at specific paths in Redis keys with optional expiration times for structured data storage.

Instructions

Set a JSON value in Redis at a given path with an optional expiration time.

Args: name: The Redis key where the JSON document is stored. path: The JSON path where the value should be set. value: The JSON value to store (as JSON string, or will be auto-converted). expire_seconds: Optional; time in seconds after which the key should expire.

Returns: A success message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
pathYes
valueYes
expire_secondsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The json_set tool handler: an async function decorated with @mcp.tool() that sets a JSON value in Redis at a specified path, with optional expiration. Handles JSON parsing, Redis operations, and error handling.
    @mcp.tool()
    async def json_set(
        name: str,
        path: str,
        value: str,
        expire_seconds: Optional[int] = None,
    ) -> str:
        """Set a JSON value in Redis at a given path with an optional expiration time.
    
        Args:
            name: The Redis key where the JSON document is stored.
            path: The JSON path where the value should be set.
            value: The JSON value to store (as JSON string, or will be auto-converted).
            expire_seconds: Optional; time in seconds after which the key should expire.
    
        Returns:
            A success message or an error message.
        """
        # Try to parse the value as JSON, if it fails, treat it as a plain string
        try:
            parsed_value = json.loads(value)
        except (json.JSONDecodeError, TypeError):
            parsed_value = value
    
        try:
            r = RedisConnectionManager.get_connection()
            r.json().set(name, path, parsed_value)
    
            if expire_seconds is not None:
                r.expire(name, expire_seconds)
    
            return f"JSON value set at path '{path}' in '{name}'." + (
                f" Expires in {expire_seconds} seconds." if expire_seconds else ""
            )
        except RedisError as e:
            return f"Error setting JSON value at path '{path}' in '{name}': {str(e)}"
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: this is a write operation ('Set'), it handles JSON data with path-based access, supports expiration, and returns success/error messages. However, it doesn't mention important details like whether this overwrites existing values, what happens on partial path failures, or authentication/rate limit requirements.

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 with a clear purpose statement followed by organized Args and Returns sections. Every sentence earns its place: the first sentence establishes core functionality, parameter explanations are essential for understanding, and the return statement sets expectations. No wasted words.

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 4 parameters with 0% schema coverage and no annotations, the description does an excellent job explaining parameters and basic behavior. However, as a write operation to Redis with JSON path manipulation, it could benefit from more detail about error conditions, data format expectations, or interaction with sibling tools like 'json_get' and 'json_del'. The presence of an output schema helps but doesn't fully compensate for missing behavioral context.

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

Parameters5/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 fully compensate. It provides clear semantic explanations for all 4 parameters: 'name' as the Redis key, 'path' as JSON path, 'value' as JSON data with conversion notes, and 'expire_seconds' as optional TTL. This adds substantial meaning beyond the bare schema types.

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 tool's purpose with specific verb ('Set a JSON value'), resource ('in Redis'), and location ('at a given path'). It distinguishes itself from sibling tools like 'set' (general Redis SET) and 'json_get' by specifying JSON-specific operations with path-based access.

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 parameter explanations (e.g., 'JSON document stored', 'JSON path'), but doesn't explicitly state when to use this versus alternatives like 'set' (for simple values) or 'hset' (for hash fields). No explicit when-not-to-use guidance or sibling comparisons are provided.

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