json_get
Extract specific JSON values from Redis keys using a defined path. Simplify data retrieval by querying nested JSON structures directly, enabling efficient data management and integration.
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
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| path | No | $ |
Implementation Reference
- src/tools/json.py:47-67 (handler)The handler function implementing the json_get tool logic. It retrieves a JSON value from Redis using the redis-py JSON module at the specified path in the document named by 'name'. Returns the JSON string or error message. Registered via @mcp.tool() decorator.@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)}"
- src/tools/json.py:47-47 (registration)The @mcp.tool() decorator registers the json_get function as an MCP tool, inferring schema from the function signature and docstring.@mcp.tool()
- src/tools/json.py:48-57 (schema)The function signature and docstring define the input schema (name: str, path: str = '$') and output (str).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. """