Skip to main content
Glama
farhankaz

Redis MCP Server

by farhankaz

zrangebyscore

Retrieve members from a Redis sorted set whose scores fall within a specified range, optionally including their scores, to efficiently filter and manage ordered data.

Instructions

Return members from a sorted set with scores between min and max

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesSorted set key
maxYesMaximum score
minYesMinimum score
withScoresNoInclude scores in output

Implementation Reference

  • The ZRangeByScoreTool class implementing the handler for the 'zrangebyscore' tool, including name, input schema, validation, and the execute method that performs the Redis ZRANGEBYSCORE command.
    export class ZRangeByScoreTool extends RedisTool {
      name = 'zrangebyscore';
      description = 'Return members from a sorted set with scores between min and max';
      inputSchema = {
        type: 'object',
        properties: {
          key: { type: 'string', description: 'Sorted set key' },
          min: { type: 'number', description: 'Minimum score' },
          max: { type: 'number', description: 'Maximum score' },
          withScores: { type: 'boolean', description: 'Include scores in output', default: false }
        },
        required: ['key', 'min', 'max']
      };
    
      validateArgs(args: unknown): args is ZRangeByScoreArgs {
        return typeof args === 'object' && args !== null &&
          'key' in args && typeof (args as any).key === 'string' &&
          'min' in args && typeof (args as any).min === 'number' &&
          'max' in args && typeof (args as any).max === 'number' &&
          (!('withScores' in args) || typeof (args as any).withScores === 'boolean');
      }
    
      async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> {
        if (!this.validateArgs(args)) {
          return this.createErrorResponse('Invalid arguments for zrangebyscore');
        }
    
        try {
          const result = await client.sendCommand([
            'ZRANGEBYSCORE',
            args.key,
            args.min.toString(),
            args.max.toString(),
            ...(args.withScores ? ['WITHSCORES'] : [])
          ]) as string[];
    
          if (!Array.isArray(result) || result.length === 0) {
            return this.createSuccessResponse('No members found in the specified score range');
          }
    
          if (args.withScores) {
            // Format result with scores when WITHSCORES is used
            const pairs = [];
            for (let i = 0; i < result.length; i += 2) {
              pairs.push(`${result[i]} (score: ${result[i + 1]})`);
            }
            return this.createSuccessResponse(pairs.join('\n'));
          }
    
          return this.createSuccessResponse(result.join('\n'));
        } catch (error) {
          return this.createErrorResponse(`Failed to get range by score from sorted set: ${error}`);
        }
      }
    }
  • TypeScript interface defining the input parameters for the zrangebyscore tool.
    export interface ZRangeByScoreArgs {
      key: string;
      min: number;
      max: number;
      withScores?: boolean;
    }
  • Registration of the ZRangeByScoreTool instance in the default tools array of ToolRegistry.
    new ZRangeByScoreTool(),
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral context. It doesn't disclose whether this is a read-only operation, what happens if the key doesn't exist, how scores are compared (inclusive/exclusive), or the return format. The description states the basic function but lacks critical operational details.

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 states the core functionality without unnecessary words. It's front-loaded with the main purpose and contains zero redundant information. Every word earns its place in this compact description.

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 Redis sorted set operation with 4 parameters and no annotations or output schema, the description is insufficient. It doesn't explain the return format (members only or with scores), error behavior, score boundary semantics, or how this differs from similar tools. The agent lacks critical context for proper tool invocation.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema - it mentions 'min' and 'max' but provides no extra context about their interpretation or the 'withScores' option. Baseline 3 is appropriate when schema does the heavy lifting.

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 action ('return members') and resource ('from a sorted set') with the specific condition ('with scores between min and max'). It distinguishes from siblings like 'zrange' (which uses index ranges) and 'zadd' (which adds members), but doesn't explicitly mention these distinctions. The purpose is specific and unambiguous.

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 like 'zrange' (for index-based retrieval) or 'scan' (for pattern matching). It doesn't mention prerequisites, error conditions, or typical use cases. The agent must infer usage from the purpose alone.

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