Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

json_set

Set a JSON value at a specified path in a Redis key, with an optional expiration time.

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 main handler function for the 'json_set' tool. Uses @mcp.tool() decorator to register as an MCP tool. Takes name, path, value, and optional expire_seconds, then sets a JSON value in Redis via redis-py's json().set() method.
    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)}"
  • src/tools/json.py:6-6 (registration)
    Imports the 'mcp' FastMCP instance from src.common.server, which is used as a decorator (@mcp.tool()) to register json_set as an MCP tool.
    from src.common.server import mcp
  • The load_tools() function dynamically imports all tool modules (including src/tools/json.py) via pkgutil, which causes the @mcp.tool() decorators to execute and register all tools (including json_set) with the FastMCP server.
    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", "python-dotenv", "numpy", "aiohttp"]
    )
    
    # Load tools
    load_tools()
  • The function signature defines the schema: name (str), path (str), value (str - JSON string auto-converted), expire_seconds (Optional[int]). Return type is str.
    async def json_set(
        name: str,
        path: str,
        value: str,
        expire_seconds: Optional[int] = None,
Behavior3/5

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

No annotations are provided, so description carries full burden. It mentions auto-conversion of value to JSON, optional expiration, and return type (success/error). However, it does not disclose behavior like overwriting existing path, atomicity, or error conditions beyond generic 'error message'. More specifics would improve transparency.

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?

Description is concise with clear 'Args' and 'Returns' sections, using few sentences without redundancy. Every sentence serves a purpose, and the structure is easy to parse.

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 the presence of an output schema (implied), the description covers the tool's purpose, parameters, and return type. It could mention edge cases (e.g., non-existent key, invalid path) but overall sufficient for basic usage.

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%, but the description explains each parameter: name (Redis key), path (JSON path), value (JSON string/auto-converted), expire_seconds (optional). This adds essential meaning beyond the schema's type-only definitions.

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?

Description clearly states 'Set a JSON value in Redis at a given path with an optional expiration time.' It specifies the operation (set), resource (JSON in Redis), and key parameters (path, expiration). This distinguishes it from sibling tools like json_get, json_del, and set.

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?

No explicit guidance on when to use this tool vs alternatives (e.g., set for non-JSON, hset for hash fields). The context of Redis JSON operations is implied but not stated. A brief note on when to prefer this over other set tools would help.

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