Skip to main content
Glama
Nicolas-One

Redis CRUD MCP Server

by Nicolas-One

redis_set

Set a key-value pair in Redis. Automatically reads project .env for connection configuration. Perform basic write operations on Redis strings.

Instructions

设置键值。自动读取项目 .env 配置连接 Redis。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
valueYes

Implementation Reference

  • src/index.ts:165-177 (registration)
    Tools are registered via ListToolsRequestSchema handler. 'redis_set' is listed as a tool with its name, description, and inputSchema (key: string, value: string, both required).
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        { name: "redis_set", description: "设置键值。自动读取项目 .env 配置连接 Redis。", inputSchema: { type: "object", properties: { key: { type: "string" }, value: { type: "string" } }, required: ["key", "value"] } },
        { name: "redis_get", description: "获取键值。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_del", description: "删除键。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_exists", description: "检查键是否存在。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_info", description: "获取连接信息。", inputSchema: { type: "object", properties: {} } },
        { name: "redis_hset", description: "设置哈希字段。", inputSchema: { type: "object", properties: { key: { type: "string" }, field: { type: "string" }, value: { type: "string" } }, required: ["key", "field", "value"] } },
        { name: "redis_hget", description: "获取哈希字段。", inputSchema: { type: "object", properties: { key: { type: "string" }, field: { type: "string" } }, required: ["key", "field"] } },
        { name: "redis_hgetall", description: "获取哈希所有字段。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_hdel", description: "删除哈希字段。", inputSchema: { type: "object", properties: { key: { type: "string" }, fields: { type: "array", items: { type: "string" } } }, required: ["key", "fields"] } }
      ]
    }));
  • The CallToolRequestSchema handler dispatches to the redis_set handler (line 187) which calls client.set(args.key, args.value) and returns a success message.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        const projectDir = getProjectDir();
        const client = await getClient(projectDir);
        const args = request.params.arguments as any;
    
        const ops: Record<string, () => Promise<string>> = {
          redis_info: async () => `Redis MCP 信息\n项目目录: ${projectDir}\n连接数: ${clientCache.size}`,
          redis_set: async () => { const r = await client.set(args.key, args.value); return `SET 成功。键: ${args.key}`; },
          redis_get: async () => { const r = await client.get(args.key); return `GET 成功。键: ${args.key}, 值: ${r ?? 'null'}`; },
          redis_del: async () => { const r = await client.del(args.key); return `DEL 成功。删除 ${r} 个键`; },
          redis_exists: async () => { const r = await client.exists(args.key); return `EXISTS 成功。键 ${args.key} ${r > 0 ? '存在' : '不存在'}`; },
          redis_hset: async () => { await client.hSet(args.key, args.field, args.value); return `HSET 成功。${args.key}.${args.field} = ${args.value}`; },
          redis_hget: async () => { const r = await client.hGet(args.key, args.field); return `HGET 成功。${args.key}.${args.field} = ${r ?? 'null'}`; },
          redis_hgetall: async () => { const r = await client.hGetAll(args.key); return `HGETALL 成功。${args.key}: ${JSON.stringify(r)}`; },
          redis_hdel: async () => { const r = await client.hDel(args.key, args.fields); return `HDEL 成功。删除 ${r} 个字段`; }
        };
  • Input schema for redis_set: object with 'key' (string) and 'value' (string), both required.
    { name: "redis_set", description: "设置键值。自动读取项目 .env 配置连接 Redis。", inputSchema: { type: "object", properties: { key: { type: "string" }, value: { type: "string" } }, required: ["key", "value"] } },
Behavior2/5

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

No annotations are provided, so the description must carry the full burden. It mentions automatic connection, but fails to disclose whether the command overwrites existing keys, sets TTL, or error handling. For a mutation tool, more behavioral details are needed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences front-loaded with purpose. It is efficient with no wasted words, though could include more detail without compromising brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with 2 parameters and no output schema, the description is minimally adequate. It lacks details on overwrite behavior, error handling, and differentiation from siblings, but covers the basic set operation and connection method.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 0% description coverage; parameter names 'key' and 'value' are self-explanatory but the description adds no extra meaning or constraints (e.g., format, length). It does not compensate for the lack of schema descriptions.

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 '设置键值' (set key-value), effectively communicating the core action and resource. However, it does not differentiate from sibling tools like redis_hset (hash set), which also sets a key-value pair.

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?

No guidance on when to use this tool versus alternatives. The description mentions automatic configuration via .env, but does not provide context for choosing redis_set over siblings like redis_hset or redis_get.

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/Nicolas-One/redis-crud-mcp-server'

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