Skip to main content
Glama
farhankaz

Redis MCP Server

by farhankaz

zrange

Retrieve a specified range of members from a sorted set by index using key, start, and stop parameters, optionally including scores for efficient data access in Redis MCP Server.

Instructions

Return a range of members from a sorted set by index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesSorted set key
startYesStart index (0-based)
stopYesStop index (inclusive)
withScoresNoInclude scores in output

Implementation Reference

  • ZRangeTool class: defines the 'zrange' tool name, input schema, validation, and execute handler that runs the Redis ZRANGE command with optional WITHSCORES.
    export class ZRangeTool extends RedisTool {
      name = 'zrange';
      description = 'Return a range of members from a sorted set by index';
      inputSchema = {
        type: 'object',
        properties: {
          key: { type: 'string', description: 'Sorted set key' },
          start: { type: 'number', description: 'Start index (0-based)' },
          stop: { type: 'number', description: 'Stop index (inclusive)' },
          withScores: { type: 'boolean', description: 'Include scores in output', default: false }
        },
        required: ['key', 'start', 'stop']
      };
    
      validateArgs(args: unknown): args is ZRangeArgs {
        return typeof args === 'object' && args !== null &&
          'key' in args && typeof (args as any).key === 'string' &&
          'start' in args && typeof (args as any).start === 'number' &&
          'stop' in args && typeof (args as any).stop === '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 zrange');
        }
    
        try {
          const result = await client.sendCommand([
            'ZRANGE',
            args.key,
            args.start.toString(),
            args.stop.toString(),
            ...(args.withScores ? ['WITHSCORES'] : [])
          ]) as string[];
    
          if (!Array.isArray(result) || result.length === 0) {
            return this.createSuccessResponse('No members found in the specified 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 from sorted set: ${error}`);
        }
      }
    }
  • TypeScript interface ZRangeArgs defining the input parameters for the zrange tool.
    export interface ZRangeArgs {
      key: string;
      start: number;
      stop: number;
      withScores?: boolean;
    }
  • JSON schema for zrange tool input validation.
    inputSchema = {
      type: 'object',
      properties: {
        key: { type: 'string', description: 'Sorted set key' },
        start: { type: 'number', description: 'Start index (0-based)' },
        stop: { type: 'number', description: 'Stop index (inclusive)' },
        withScores: { type: 'boolean', description: 'Include scores in output', default: false }
      },
      required: ['key', 'start', 'stop']
    };
  • Registration of ZRangeTool instance in the default tools array within ToolRegistry.
    new ZRangeTool(),
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 only states the basic operation. It doesn't disclose important behavioral traits such as whether this is read-only or has side effects, error conditions, performance characteristics, or what the output format looks like (especially given no output schema).

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 directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, with every word earning its place in conveying the core purpose.

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?

Given no annotations and no output schema, the description is incomplete for a tool with 4 parameters that performs data retrieval. It doesn't explain return values, error handling, or behavioral constraints, leaving significant gaps for the agent to understand how to use it effectively.

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 meaning beyond what's in the schema (e.g., it doesn't explain index semantics or score inclusion implications), meeting the baseline for high schema coverage.

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 a range of members') and resource ('from a sorted set by index'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'zrangebyscore' which also returns ranges but by score rather than index, missing full sibling distinction.

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 'zrangebyscore' or 'smembers'. It lacks context about appropriate use cases, prerequisites, or exclusions, leaving the agent to infer usage from the name and parameters 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