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'); }

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