Skip to main content
Glama
farhankaz

Redis MCP Server

by farhankaz

scan

Scan Redis keys by pattern to retrieve specific data entries. Input a pattern (e.g., "user:*") and optionally set the count of keys per iteration for efficient data management.

Instructions

Scan Redis keys matching a pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of keys to return per iteration (optional)
patternYesPattern to match (e.g., "user:*" or "schedule:*")

Implementation Reference

  • The core handler function that executes the 'scan' tool logic: validates input, scans Redis keys matching the pattern using client.keys(), limits results to 10 keys max, and returns a JSON-formatted list or error response.
    async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> {
      if (!this.validateArgs(args)) {
        return this.createErrorResponse('Invalid arguments for scan');
      }
    
      try {
        const { pattern, count = 100 } = args;
        const keys = await client.keys(pattern);
        
        if (keys.length === 0) {
          return this.createSuccessResponse('No keys found matching pattern');
        }
    
        // Limit keys to at most 10, or less if count is specified and smaller
        const maxKeys = Math.min(count || 10, 10);
        const limitedKeys = keys.slice(0, maxKeys);
        return this.createSuccessResponse(JSON.stringify(limitedKeys, null, 2));
      } catch (error) {
        return this.createErrorResponse(`Failed to scan keys: ${error}`);
      }
    }
  • JSON schema defining the input parameters for the 'scan' tool: required 'pattern' string and optional 'count' number.
    inputSchema = {
      type: 'object',
      properties: {
        pattern: {
          type: 'string',
          description: 'Pattern to match (e.g., "user:*" or "schedule:*")'
        },
        count: {
          type: 'number',
          description: 'Number of keys to return per iteration (optional)',
          minimum: 1
        }
      },
      required: ['pattern']
    };
  • Registration of the ScanTool instance in the default tools array of ToolRegistry.
    new ScanTool(),
  • TypeScript interface defining the expected arguments for the 'scan' tool.
    export interface ScanArgs {
      pattern: string;
      count?: number;
    }
  • Helper function to validate input arguments match ScanArgs structure.
    validateArgs(args: unknown): args is ScanArgs {
      return typeof args === 'object' && args !== null &&
        'pattern' in args && typeof (args as any).pattern === 'string' &&
        (!('count' in args) || typeof (args as any).count === 'number');
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions scanning keys matching a pattern but omits critical details like whether this is a read-only operation, potential performance impacts on Redis, iteration mechanics (implied by 'per iteration' in schema but not explained), or output format. This leaves significant gaps in understanding the tool's behavior.

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 purpose without unnecessary words. It is front-loaded and wastes no space, making it easy to parse quickly while conveying the core functionality.

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 the lack of annotations and output schema, the description is incomplete for a tool with potential complexity (e.g., iterative scanning in Redis). It fails to explain behavioral aspects like safety, performance, or result format, which are crucial for an agent to use it effectively. The high schema coverage doesn't compensate for these missing contextual elements.

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 schema description coverage is 100%, with clear descriptions for both parameters ('pattern' and 'count'). The description adds minimal value beyond the schema, as it only reiterates the pattern matching concept without providing additional context like examples of complex patterns or advice on 'count' usage. This meets 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 ('Scan') and the resource ('Redis keys matching a pattern'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'get' or 'smembers', which might retrieve specific keys or set members, but the scanning functionality is distinct enough for basic clarity.

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 'get' for single keys or 'smembers' for set members. It lacks context about scenarios where pattern-based scanning is appropriate, such as bulk operations or key discovery, leaving the agent without usage direction.

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