Skip to main content
Glama

zset_add

Add members with scores to a Redis sorted set to store and retrieve data by rank or score range.

Instructions

添加有序集合成员

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes有序集合键名
membersYes要添加的成员或成员数组

Implementation Reference

  • The main handler function for the zset_add MCP tool. Ensures Redis connection and calls the underlying RedisService.zadd method, returning the result as MCP content.
    private async handleZsetAdd(args: any) {
      this.ensureRedisConnection();
      const result = await this.redisService!.zadd(args.key, args.members);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2)
          }
        ]
      };
    }
  • Input schema definition for the zset_add tool, specifying key (string) and members (single object {member: string, score: number} or array thereof).
    inputSchema: {
      type: 'object',
      properties: {
        key: { type: 'string', description: '有序集合键名' },
        members: {
          oneOf: [
            {
              type: 'object',
              properties: {
                member: { type: 'string', description: '成员' },
                score: { type: 'number', description: '分数' }
              },
              required: ['member', 'score'],
              description: '单个成员'
            },
            {
              type: 'array',
              items: {
                type: 'object',
                properties: {
                  member: { type: 'string', description: '成员' },
                  score: { type: 'number', description: '分数' }
                },
                required: ['member', 'score']
              },
              description: '成员数组'
            }
          ],
          description: '要添加的成员或成员数组'
        }
      },
      required: ['key', 'members']
  • Registration in the tool dispatcher switch statement within CallToolRequestHandler, routing calls to the zset_add handler.
    case 'zset_add':
      return await this.handleZsetAdd(args);
  • Helper method in RedisService that implements the ZADD Redis command, converting MCP parameters to redis client zAdd format and handling single/array inputs.
    async zadd(key: string, members: RedisSortedSetMember | RedisSortedSetMember[]): Promise<RedisOperationResult<number>> {
      return this.executeCommand(async () => {
        if (!this.client) throw new Error('Redis client not initialized');
        
        if (Array.isArray(members)) {
          const args: Array<{ score: number, value: string }> = members.map(m => ({
            score: m.score,
            value: m.member
          }));
          return await this.client.zAdd(key, args);
        } else {
          return await this.client.zAdd(key, { score: members.score, value: members.member });
        }
      });
    }
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 states the action ('add') which implies a write/mutation operation, but doesn't cover critical traits: whether it overwrites existing members, requires authentication, has rate limits, or what happens on success/failure. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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 waste. It's appropriately sized and front-loaded, 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 (a mutation tool for sorted sets with 2 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't address behavioral aspects like idempotency, error handling, or return values, leaving gaps that could hinder an AI agent's correct 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%, with both parameters ('key' and 'members') well-documented in the schema. The description doesn't add any meaning beyond what the schema provides—it doesn't explain parameter interactions, constraints, or examples. Baseline is 3 since the schema does the heavy lifting, but no extra value is added.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '添加有序集合成员' (add sorted set members) clearly states the verb (add) and resource (sorted set members), which is specific. However, it doesn't distinguish this tool from sibling tools like 'zset_range' or 'zset_remove' that also operate on sorted sets, nor does it mention the scoring aspect that defines sorted sets. The purpose is understandable but lacks sibling differentiation.

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. There are no mentions of prerequisites (e.g., connection state), exclusions, or comparisons to similar tools like 'set_add' for unordered sets or 'zset_remove' for deletion. Usage is implied by the action but without explicit context.

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

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/pickstar-2002/redis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server