redis

Local 2025-08-31 23:26:16 0

A Model Context Protocol server that provides access to Redis databases. This server enables LLMs to interact with Redis key-value stores through a set of standardized tools.


A Model Context Protocol server that provides access to Redis databases. This server enables LLMs to interact with Redis key-value stores through a set of standardized tools.

Prerequisites

  1. Redis server must be installed and running
  2. Download Redis
  3. For Windows users: Use Windows Subsystem for Linux (WSL) or Memurai (Redis-compatible Windows server)
  4. Default port: 6379

Common Issues & Solutions

Connection Errors

ECONNREFUSED - Cause: Redis server is not running or unreachable - Solution: - Verify Redis is running: redis-cli ping should return "PONG" - Check Redis service status: systemctl status redis (Linux) or brew services list (macOS) - Ensure correct port (default 6379) is not blocked by firewall - Verify Redis URL format: redis://hostname:port

Server Behavior

  • The server implements exponential backoff with a maximum of 5 retries
  • Initial retry delay: 1 second, maximum delay: 30 seconds
  • Server will exit after max retries to prevent infinite reconnection loops

Components

Tools

  • set
  • Set a Redis key-value pair with optional expiration
  • Input:

    • key (string): Redis key
    • value (string): Value to store
    • expireSeconds (number, optional): Expiration time in seconds
  • get

  • Get value by key from Redis
  • Input: key (string): Redis key to retrieve

  • delete

  • Delete one or more keys from Redis
  • Input: key (string | string[]): Key or array of keys to delete

  • list

  • List Redis keys matching a pattern
  • Input: pattern (string, optional): Pattern to match keys (default: *)

Usage with Claude Desktop

To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json:

Docker

  • when running docker on macos, use host.docker.internal if the server is running on the host network (eg localhost)
  • Redis URL can be specified as an argument, defaults to "redis://localhost:6379"
{
  "mcpServers": {
    "redis": {
      "command": "docker",
      "args": [
        "run", 
        "-i", 
        "--rm", 
        "mcp/redis", 
        "redis://host.docker.internal:6379"]
    }
  }
}

NPX

{
  "mcpServers": {
    "redis": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-redis",
        "redis://localhost:6379"
      ]
    }
  }
}

Building

Docker:

docker build -t mcp/redis -f src/redis/Dockerfile . 

License

This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

[
  {
    "description": "Set multiple hash fields to multiple values",
    "inputSchema": {
      "properties": {
        "fields": {
          "description": "Field-value pairs to set (格式示例:"field1 value1 field2 value2")",
          "type": "string"
        },
        "key": {
          "description": "Hash key",
          "type": "string"
        }
      },
      "required": [
        "fields",
        "key"
      ],
      "type": "object"
    },
    "name": "hmset"
  },
  {
    "description": "Get the value of a hash field",
    "inputSchema": {
      "properties": {
        "field": {
          "description": "Field to get",
          "type": "string"
        },
        "key": {
          "description": "Hash key",
          "type": "string"
        }
      },
      "required": [
        "field",
        "key"
      ],
      "type": "object"
    },
    "name": "hget"
  },
  {
    "description": "Get all the fields and values in a hash",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Hash key",
          "type": "string"
        }
      },
      "required": [
        "key"
      ],
      "type": "object"
    },
    "name": "hgetall"
  },
  {
    "description": "Scan Redis keys matching a pattern",
    "inputSchema": {
      "properties": {
        "count": {
          "description": "Number of keys to return per iteration (optional)",
          "type": "integer"
        },
        "pattern": {
          "description": "Pattern to match (e.g., "user:*" or "schedule:*")",
          "type": "string"
        }
      },
      "required": [
        "pattern"
      ],
      "type": "object"
    },
    "name": "scan"
  },
  {
    "description": "Set string value with optional NX (only if not exists) and PX (expiry in milliseconds) options",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Key to set",
          "type": "string"
        },
        "nx": {
          "description": "Only set if key does not exist",
          "type": "boolean"
        },
        "px": {
          "description": "Set expiry in milliseconds",
          "type": "integer"
        },
        "value": {
          "description": "Value to set",
          "type": "string"
        }
      },
      "required": [
        "key",
        "value"
      ],
      "type": "object"
    },
    "name": "set"
  },
  {
    "description": "Get string value",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Key to get",
          "type": "string"
        }
      },
      "required": [
        "key"
      ],
      "type": "object"
    },
    "name": "get"
  },
  {
    "description": "Delete a key",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Key to delete",
          "type": "string"
        }
      },
      "required": [
        "key"
      ],
      "type": "object"
    },
    "name": "del"
  },
  {
    "description": "Add one or more members to a sorted set",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Sorted set key",
          "type": "string"
        },
        "members": {
          "description": "Score-value pairs (格式示例:"1 member1 2 member2")",
          "type": "string"
        }
      },
      "required": [
        "key",
        "members"
      ],
      "type": "object"
    },
    "name": "zadd"
  },
  {
    "description": "Return a range of members from a sorted set by index",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Sorted set key",
          "type": "string"
        },
        "start": {
          "description": "Start index (0-based)",
          "minimum": 0,
          "type": "integer"
        },
        "stop": {
          "description": "Stop index (inclusive)",
          "minimum": 0,
          "type": "integer"
        },
        "withScores": {
          "description": "Include scores in output",
          "type": "boolean"
        }
      },
      "required": [
        "key",
        "start",
        "stop"
      ],
      "type": "object"
    },
    "name": "zrange"
  },
  {
    "description": "Return members from a sorted set with scores between min and max",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Sorted set key",
          "type": "string"
        },
        "max": {
          "description": "Maximum score",
          "type": "number"
        },
        "min": {
          "description": "Minimum score",
          "type": "number"
        },
        "withScores": {
          "description": "Include scores in output",
          "type": "boolean"
        }
      },
      "required": [
        "key",
        "min",
        "max"
      ],
      "type": "object"
    },
    "name": "zrangebyscore"
  },
  {
    "description": "Remove one or more members from a sorted set",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Sorted set key",
          "type": "string"
        },
        "members": {
          "description": "Members to remove (格式示例:"member1 member2")",
          "type": "string"
        }
      },
      "required": [
        "key",
        "members"
      ],
      "type": "object"
    },
    "name": "zrem"
  },
  {
    "description": "Add one or more members to a set",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Set key",
          "type": "string"
        },
        "members": {
          "description": "Members to add (格式示例:"member1 member2")",
          "type": "string"
        }
      },
      "required": [
        "key",
        "members"
      ],
      "type": "object"
    },
    "name": "sadd"
  },
  {
    "description": "Get all members in a set",
    "inputSchema": {
      "properties": {
        "key": {
          "description": "Set key",
          "type": "string"
        }
      },
      "required": [
        "key"
      ],
      "type": "object"
    },
    "name": "smembers"
  }
]