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);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'Get' implies a read operation, it doesn't specify whether this requires authentication, has rate limits, returns errors for missing fields, or provides any details about the return format. The description is minimal and lacks important operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose without any wasted words. It's appropriately sized for a simple retrieval operation and gets straight to the point.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what type of value is returned, how errors are handled, or provide any context about the data store or typical use cases. Given the sibling tools suggest this is part of a key-value or hash storage system, more context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with both parameters clearly documented as 'Field to get' and 'Hash key'. The description doesn't add any meaningful semantic context beyond what's already in the schema, such as explaining the relationship between key and field or providing examples of valid values.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'value of a hash field', making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'get' or 'hgetall', which might also retrieve values from the same data store.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'get', 'hgetall', and 'scan' available, there's no indication whether this is for specific hash structures, when to prefer it over other retrieval methods, or any prerequisites for its use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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