hgetall
Retrieve all fields and values stored in a specific hash key within a Redis database using the Model Context Protocol (MCP) for structured data management.
Instructions
Get all the fields and values in a hash
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Hash key |
Implementation Reference
- src/tools/hgetall_tool.ts:21-35 (handler)The execute method implements the hgetall tool logic: validates args, calls Redis hGetAll on the key, and returns formatted response or error.async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> { if (!this.validateArgs(args)) { return this.createErrorResponse('Invalid arguments for hgetall'); } try { const value = await client.hGetAll(args.key); if (Object.keys(value).length === 0) { return this.createSuccessResponse('Hash not found or empty'); } return this.createSuccessResponse(JSON.stringify(value, null, 2)); } catch (error) { return this.createErrorResponse(`Failed to get hash: ${error}`); } }
- src/tools/hgetall_tool.ts:8-14 (schema)JSON schema defining input for hgetall tool: requires 'key' string.inputSchema = { type: 'object', properties: { key: { type: 'string', description: 'Hash key' } }, required: ['key'] };
- src/interfaces/types.ts:16-18 (schema)TypeScript interface for HGetAllArgs used in validation.export interface HGetAllArgs { key: string; }
- src/tools/tool_registry.ts:4-28 (registration)Imports and instantiates HGetAllTool for registration in ToolRegistry's default tools.import { HGetAllTool } from './hgetall_tool.js'; import { ScanTool } from './scan_tool.js'; import { SetTool } from './set_tool.js'; import { GetTool } from './get_tool.js'; import { DelTool } from './del_tool.js'; import { ZAddTool } from './zadd_tool.js'; import { ZRangeTool } from './zrange_tool.js'; import { ZRangeByScoreTool } from './zrangebyscore_tool.js'; import { ZRemTool } from './zrem_tool.js'; import { SAddTool } from './sadd_tool.js'; import { SMembersTool } from './smembers_tool.js'; export class ToolRegistry { private tools: Map<string, BaseTool>; constructor() { this.tools = new Map(); this.registerDefaultTools(); } private registerDefaultTools() { const defaultTools = [ new HMSetTool(), new HGetTool(), new HGetAllTool(),