Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

json_get

Retrieve specific JSON values from Redis keys using JSON path queries to access nested data structures.

Instructions

Retrieve a JSON value from Redis at a given path.

Args: name: The Redis key where the JSON document is stored. path: The JSON path to retrieve (default: root '$').

Returns: The retrieved JSON value or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
pathNo$

Implementation Reference

  • The core handler function for the 'json_get' tool. It uses Redis JSON .get() to retrieve data from a specified path in a JSON document stored in Redis. Includes error handling and formats the output as an indented JSON string. The @mcp.tool() decorator registers it as an MCP tool.
    @mcp.tool()
    async def json_get(name: str, path: str = "$") -> str:
        """Retrieve a JSON value from Redis at a given path.
    
        Args:
            name: The Redis key where the JSON document is stored.
            path: The JSON path to retrieve (default: root '$').
    
        Returns:
            The retrieved JSON value or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            value = r.json().get(name, path)
            if value is not None:
                # Convert the value to JSON string for consistent return type
                return json.dumps(value, ensure_ascii=False, indent=2)
            else:
                return f"No data found at path '{path}' in '{name}'."
        except RedisError as e:
            return f"Error retrieving JSON value at path '{path}' in '{name}': {str(e)}"
  • The @mcp.tool() decorator registers the json_get function as an MCP tool.
    @mcp.tool()

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