Skip to main content
Glama
farhankaz

Redis MCP Server

by farhankaz

set

Store a string value in Redis using MCP, with options to set expiry in milliseconds and ensure the key does not already exist.

Instructions

Set string value with optional NX (only if not exists) and PX (expiry in milliseconds) options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesKey to set
nxNoOnly set if key does not exist
pxNoSet expiry in milliseconds
valueYesValue to set

Implementation Reference

  • The execute method implements the core logic of the 'set' MCP tool, handling argument validation and executing the Redis SET command with support for NX (set if not exists) and PX (expiration in ms) options.
    async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> {
      if (!this.validateArgs(args)) {
        return this.createErrorResponse('Invalid arguments for set');
      }
    
      try {
        const options: any = {};
        if (args.nx) {
          options.NX = true;
        }
        if (args.px) {
          options.PX = args.px;
        }
    
        const result = await client.set(args.key, args.value, options);
        if (result === null) {
          return this.createSuccessResponse('Key not set (NX condition not met)');
        }
        return this.createSuccessResponse('OK');
      } catch (error) {
        return this.createErrorResponse(`Failed to set key: ${error}`);
      }
    }
  • Input schema defining the parameters for the 'set' tool: required key and value strings, optional boolean nx and number px.
    inputSchema = {
      type: 'object',
      properties: {
        key: { type: 'string', description: 'Key to set' },
        value: { type: 'string', description: 'Value to set' },
        nx: { type: 'boolean', description: 'Only set if key does not exist' },
        px: { type: 'number', description: 'Set expiry in milliseconds' }
      },
      required: ['key', 'value']
    };
  • Registers the SetTool instance in the ToolRegistry by including it in the defaultTools array and calling registerTool in the loop.
    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 the full burden of behavioral disclosure. It mentions that setting can be conditional (NX) and include expiry (PX), which adds some context. However, it fails to describe critical behaviors such as whether this overwrites existing values by default, what happens on expiry, error conditions, or response format. For a mutation tool with zero annotation coverage, this is a significant gap.

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 front-loads the core action ('Set string value') and briefly mentions optional features. There is no wasted language, and it's appropriately sized for the tool's complexity, making it easy to parse quickly.

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 complexity of a mutation tool with no annotations and no output schema, the description is incomplete. It lacks information on behavioral traits (e.g., default overwrite behavior, error handling), usage guidelines compared to siblings, and expected return values. While concise, it doesn't provide enough context for an agent to use the tool effectively without additional assumptions.

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%, meaning all parameters are documented in the schema. The description adds minimal value by naming NX and PX options but doesn't provide additional semantics beyond what the schema already states (e.g., NX means 'only set if key does not exist'). Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 ('Set') and resource ('string value'), making the purpose understandable. It also mentions optional NX and PX options, which adds specificity. However, it doesn't explicitly differentiate from sibling tools like 'hmset' or 'zadd' that also set values in different data structures, leaving room for ambiguity.

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. It mentions optional NX and PX options but doesn't explain scenarios where these are beneficial or when to choose this over other setting tools like 'hmset' for hashes or 'zadd' for sorted sets. This lack of context makes it harder for an agent to select the right tool.

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