Skip to main content
Glama
farhankaz

Redis MCP Server

by farhankaz

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
NameRequiredDescriptionDefault
fieldYesField to get
keyYesHash key

Implementation Reference

  • 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}`);
        }
      }
    }
  • 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;
    }
  • 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(),
  • 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']
    };
  • 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);
      }
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/farhankaz/redis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server