rename
Rename a Redis key by providing the current key name and the new key name. Updates the key identifier in the database.
Instructions
Renames a Redis key from old_key to new_key.
Args: old_key (str): The current name of the Redis key to rename. new_key (str): The new name to assign to the key.
Returns: Dict[str, Any]: A dictionary containing the result of the operation. On success: {"status": "success", "message": "..."} On error: {"error": "..."}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| old_key | Yes | ||
| new_key | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/tools/misc.py:76-106 (handler)The rename tool handler function. Decorated with @mcp.tool(), it renames a Redis key from old_key to new_key. Validates that the old key exists before renaming, catches RedisError exceptions, and returns a dict with status/error information.
@mcp.tool() async def rename(old_key: str, new_key: str) -> Dict[str, Any]: """ Renames a Redis key from old_key to new_key. Args: old_key (str): The current name of the Redis key to rename. new_key (str): The new name to assign to the key. Returns: Dict[str, Any]: A dictionary containing the result of the operation. On success: {"status": "success", "message": "..."} On error: {"error": "..."} """ try: r = RedisConnectionManager.get_connection() # Check if the old key exists if not r.exists(old_key): return {"error": f"Key '{old_key}' does not exist."} # Rename the key r.rename(old_key, new_key) return { "status": "success", "message": f"Renamed key '{old_key}' to '{new_key}'", } except RedisError as e: return {"error": str(e)} - src/tools/misc.py:76-76 (registration)The rename function is registered as an MCP tool via the @mcp.tool() decorator on line 76.
@mcp.tool() - src/common/server.py:1-19 (registration)The FastMCP server (mcp) is initialized here. The @mcp.tool() decorator used in misc.py registers tools on this server instance. The load_tools() function dynamically imports all tool modules including misc.py.
import importlib import pkgutil from mcp.server.fastmcp import FastMCP 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()