Redis MCP server

Bridge to Redis databases, enabling fast in-memory data operations for AI workflows.
Back to servers
Provider
Farhan Kaz
Release date
Jan 07, 2025
Language
TypeScript
Package
Stats
658 downloads
6 stars

The Redis MCP Server provides access to Redis database operations through the Model Context Protocol, allowing AI assistants to interact with Redis databases directly. It supports a wide range of Redis commands including hash operations, key operations, string operations, and sorted set commands.

Installation

Prerequisites

  • Node.js and npm installed
  • Access to a Redis server (local or remote)

Installing via npm

You can install the Redis MCP server using npm:

npm install -g redis-mcp

Installing via Smithery

For Claude Desktop users, you can install the Redis MCP server automatically using Smithery:

npx -y @smithery/cli install redis-mcp --client claude

Configuration

Basic Setup

To use the Redis MCP server with your MCP client (such as Claude Desktop or Cline), configure it in your client settings:

{
  "mcpServers": {
    "redis": {
      "command": "npx",
      "args": ["redis-mcp", "--redis-host", "localhost", "--redis-port", "6379"],
      "disabled": false
    }
  }
}

Command Line Arguments

The server supports the following command line arguments:

  • --redis-host: Redis server host (default: localhost)
  • --redis-port: Redis server port (default: 6379)

Example with custom Redis connection:

npx redis-mcp --redis-host my-redis-server.example.com --redis-port 6380

Available Commands

The Redis MCP server provides access to the following Redis operations:

Hash Commands

Command Description Input Parameters
hmset Set multiple hash fields to multiple values key: string
fields: object (field-value pairs)
hget Get the value of a hash field key: string
field: string
hgetall Get all fields and values in a hash key: string

String Commands

Command Description Input Parameters
set Set string value with optional NX and PX options key: string
value: string
nx: boolean (optional)
px: number (optional)
get Get string value key: string

Key Commands

Command Description Input Parameters
scan Scan Redis keys matching a pattern pattern: string
count: number (optional)
del Delete a key key: string

Sorted Set Commands

Command Description Input Parameters
zadd Add members to a sorted set key: string
members: array of objects with score and value
zrange Get range of members by index key: string
start: number
stop: number
withScores: boolean (optional)
zrangebyscore Get members with scores in a range key: string
min: number
max: number
withScores: boolean (optional)
zrem Remove members from a sorted set key: string
members: array of strings

Set Commands

Command Description Input Parameters
sadd Add members to a set key: string
members: array of strings
smembers Get all members in a set key: string

Usage Examples

Working with Hash Data

Setting multiple hash fields:

await redis.hmset({
  key: "user:1000",
  fields: {
    name: "John Doe",
    email: "[email protected]",
    age: "30"
  }
});

Getting a specific hash field:

const email = await redis.hget({
  key: "user:1000",
  field: "email"
});
// Returns: "[email protected]"

Getting all hash fields:

const userData = await redis.hgetall({
  key: "user:1000"
});
// Returns: { name: "John Doe", email: "[email protected]", age: "30" }

Working with String Data

Setting a string value:

await redis.set({
  key: "session:token",
  value: "abcd1234",
  px: 3600000  // Expire in 1 hour
});

Getting a string value:

const token = await redis.get({
  key: "session:token"
});
// Returns: "abcd1234"

Working with Sorted Sets

Adding members to a sorted set:

await redis.zadd({
  key: "leaderboard",
  members: [
    { score: 100, value: "user:1" },
    { score: 85, value: "user:2" },
    { score: 95, value: "user:3" }
  ]
});

Getting a range of members:

const topThree = await redis.zrange({
  key: "leaderboard",
  start: 0,
  stop: 2,
  withScores: true
});
// Returns top three users with their scores

Managing Keys

Scanning for keys matching a pattern:

const userKeys = await redis.scan({
  pattern: "user:*",
  count: 10
});
// Returns keys like "user:1000", "user:1001", etc.

Deleting a key:

await redis.del({
  key: "session:expired"
});

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later