type
Check the data type of a value stored at a given Redis key. Returns the type as a string or 'none' if the key does not exist.
Instructions
Returns the string representation of the type of the value stored at key
Args: key (str): The key to check.
Returns: str: The type of key, or none when key doesn't exist
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/tools/misc.py:33-50 (handler)The handler function for the 'type' tool. Uses Redis TYPE command to get the type of a key's value, also returns TTL. Registered via @mcp.tool() decorator.
@mcp.tool() async def type(key: str) -> Dict[str, Any]: """Returns the string representation of the type of the value stored at key Args: key (str): The key to check. Returns: str: The type of key, or none when key doesn't exist """ try: r = RedisConnectionManager.get_connection() key_type = r.type(key) info = {"key": key, "type": key_type, "ttl": r.ttl(key)} return info except RedisError as e: return {"error": str(e)} - src/common/server.py:6-19 (registration)The FastMCP server initialization and tool loading mechanism. All modules in src/tools/ are auto-imported, and the @mcp.tool() decorator registers each tool function with 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() - src/tools/misc.py:7-8 (helper)The 'type' handler depends on RedisConnectionManager (for database connection) and the mcp server instance (for the @mcp.tool() decorator).
from src.common.connection import RedisConnectionManager from src.common.server import mcp - src/tools/misc.py:34-35 (schema)The 'type' tool accepts a single string parameter 'key' and returns a dictionary with key, type, and ttl fields.
async def type(key: str) -> Dict[str, Any]: """Returns the string representation of the type of the value stored at key