hget
Retrieve the value of a specific field within a hash stored in Redis using the MCP protocol. Specify the hash key and field to access the desired data.
Instructions
Get the value of a hash field
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| field | Yes | Field to get | |
| key | Yes | Hash key |
Implementation Reference
- src/tools/hget_tool.ts:5-38 (handler)The HGetTool class that implements the core logic for the 'hget' tool, including validation and execution using Redis client.hGet(key, field).export class HGetTool extends RedisTool { name = 'hget'; description = 'Get the value of a hash field'; inputSchema = { type: 'object', properties: { key: { type: 'string', description: 'Hash key' }, field: { type: 'string', description: 'Field to get' } }, required: ['key', 'field'] }; validateArgs(args: unknown): args is HGetArgs { return typeof args === 'object' && args !== null && 'key' in args && typeof (args as any).key === 'string' && 'field' in args && typeof (args as any).field === 'string'; } async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> { if (!this.validateArgs(args)) { return this.createErrorResponse('Invalid arguments for hget'); } try { const value = await client.hGet(args.key, args.field); if (value === null || value === undefined) { return this.createSuccessResponse('Field not found'); } return this.createSuccessResponse(value); } catch (error) { return this.createErrorResponse(`Failed to get hash field: ${error}`); } } }
- src/interfaces/types.ts:11-14 (schema)Interface defining the input arguments for the hget tool (key and field). Used for type checking in the tool.export interface HGetArgs { key: string; field: string; }
- src/tools/tool_registry.ts:3-27 (registration)Import and instantiation of HGetTool in ToolRegistry's default tools list, registering it by name 'hget'.import { HGetTool } from './hget_tool.js'; 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(),
- src/tools/hget_tool.ts:8-15 (schema)JSON schema definition for hget tool inputs, defining properties and requirements.inputSchema = { type: 'object', properties: { key: { type: 'string', description: 'Hash key' }, field: { type: 'string', description: 'Field to get' } }, required: ['key', 'field'] };
- src/tools/tool_registry.ts:24-44 (registration)The registerDefaultTools method in ToolRegistry that instantiates and registers all default tools, including HGetTool.private registerDefaultTools() { const defaultTools = [ new HMSetTool(), new HGetTool(), new HGetAllTool(), new ScanTool(), new SetTool(), new GetTool(), new DelTool(), new ZAddTool(), new ZRangeTool(), new ZRangeByScoreTool(), new ZRemTool(), new SAddTool(), new SMembersTool(), ]; for (const tool of defaultTools) { this.registerTool(tool); } }