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.
You can install the Redis MCP server using npm:
npm install -g redis-mcp
For Claude Desktop users, you can install the Redis MCP server automatically using Smithery:
npx -y @smithery/cli install redis-mcp --client claude
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
}
}
}
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
The Redis MCP server provides access to the following Redis operations:
Command | Description | Input Parameters |
---|---|---|
hmset | Set multiple hash fields to multiple values | key : stringfields : object (field-value pairs) |
hget | Get the value of a hash field | key : stringfield : string |
hgetall | Get all fields and values in a hash | key : string |
Command | Description | Input Parameters |
---|---|---|
set | Set string value with optional NX and PX options | key : stringvalue : stringnx : boolean (optional)px : number (optional) |
get | Get string value | key : string |
Command | Description | Input Parameters |
---|---|---|
scan | Scan Redis keys matching a pattern | pattern : stringcount : number (optional) |
del | Delete a key | key : string |
Command | Description | Input Parameters |
---|---|---|
zadd | Add members to a sorted set | key : stringmembers : array of objects with score and value |
zrange | Get range of members by index | key : stringstart : numberstop : numberwithScores : boolean (optional) |
zrangebyscore | Get members with scores in a range | key : stringmin : numbermax : numberwithScores : boolean (optional) |
zrem | Remove members from a sorted set | key : stringmembers : array of strings |
Command | Description | Input Parameters |
---|---|---|
sadd | Add members to a set | key : stringmembers : array of strings |
smembers | Get all members in a set | key : string |
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" }
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"
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
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"
});
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.
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"
]
}
}
}
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.
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.