@futuretea/redis-mcp-server 0.0.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ make build
|
|
|
14
14
|
--params '{"operation":"get","args":{"key":"sample"}}'
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
`tools list` and `tools describe` do not connect to Redis. `tools call` and `mcp` connect, then reject an account that can run administrative commands unless `allow_unsafe_database_role` is set. See Service account.
|
|
18
|
+
|
|
17
19
|
The catalog contains `redis_key`, `redis_string`, `redis_hash`, `redis_list`, `redis_set`, `redis_sorted_set`, `redis_stream`, and `redis_observe`. Write-mode additionally registers the corresponding seven `*_write` tools; there is no raw-command tool and no `redis_observe_write`.
|
|
18
20
|
|
|
19
21
|
Collection responses are bounded to 1–1000 items before reaching Redis. `SCAN`, `HSCAN`, `SSCAN`, and `ZSCAN` return a fixed-length opaque base64url continuation reference, never a Redis-native cursor or buffered value. A continuation remains idle-valid for five minutes after a successful page, with at most 1,000 sessions and 16 MiB of encoded state per adapter; whole sessions are evicted by LRU. Expired or evicted references return `cursor_expired`; a newly unadmittable continuation returns `cursor_unavailable`. Stream entry reads are intentionally absent: the stream catalog is limited to length, bounded pending inspection, and `XCLAIM JUSTID`.
|
|
@@ -70,6 +72,7 @@ Both release entry points start MCP over stdio by default. Pass `--port 8080 --l
|
|
|
70
72
|
Redis topology is explicit. Password is read only from `MCP_REDIS_PASSWORD`; do not place it in YAML.
|
|
71
73
|
|
|
72
74
|
```yaml
|
|
75
|
+
allow_unsafe_database_role: false
|
|
73
76
|
redis:
|
|
74
77
|
topology: standalone # standalone | cluster | sentinel
|
|
75
78
|
addresses: ["127.0.0.1:6379"]
|
|
@@ -79,8 +82,83 @@ redis:
|
|
|
79
82
|
write_enabled: false
|
|
80
83
|
```
|
|
81
84
|
|
|
85
|
+
`allow_unsafe_database_role` defaults to false. The environment variable is `MCP_ALLOW_UNSAFE_DATABASE_ROLE`. Password remains `MCP_REDIS_PASSWORD` only.
|
|
86
|
+
|
|
82
87
|
Use `sentinel_master` for Sentinel. `addresses` lists cluster seeds for Cluster and Sentinel endpoints for Sentinel.
|
|
83
88
|
|
|
89
|
+
### Service account
|
|
90
|
+
|
|
91
|
+
After the process connects, and before any tool runs a Redis command, startup reads the current user's ACL. It sends `PING`, `ACL WHOAMI`, `ACL GETUSER`, and `ACL CAT`. The process exits with `[redis_unsafe_service_role] database service role is not permitted` when any root rule or selector can run:
|
|
92
|
+
|
|
93
|
+
- a command in the `@admin` category, including `CONFIG`, `DEBUG`, `SHUTDOWN`, `ACL SETUSER`, `BGSAVE`, `REPLICAOF`, `MODULE`, `MONITOR`, `CLIENT KILL`, and cluster administration subcommands such as `CLUSTER FAILOVER` and `CLUSTER RESET`
|
|
94
|
+
- `FLUSHALL`, `FLUSHDB`, `SWAPDB`, or `MIGRATE`
|
|
95
|
+
- server-side code and global function or script control: `@scripting`, including `EVAL`, `EVALSHA`, `FCALL`, `SCRIPT DEBUG`, `SCRIPT FLUSH`, `SCRIPT LOAD`, `SCRIPT KILL`, `FUNCTION FLUSH`, `FUNCTION DELETE`, `FUNCTION LOAD`, `FUNCTION RESTORE`, and `FUNCTION KILL`
|
|
96
|
+
- `MEMORY PURGE`
|
|
97
|
+
- every command in that server's `@dangerous` category. Redis 8 adds `TRIMSLOTS` and `BACKUP` there. They are not in `@admin` or `@scripting`, and `@write` and `@keyspace` grant `TRIMSLOTS`
|
|
98
|
+
- `RANDOMKEY` and `SCAN`. Both return key names and do not take a key argument, so a key pattern does not apply to them
|
|
99
|
+
- the whole `ACL`, `CLIENT`, `CLUSTER`, `FUNCTION`, `SCRIPT`, or `MEMORY` command
|
|
100
|
+
|
|
101
|
+
These probe commands are not a rejection by themselves: `ACL WHOAMI`, `ACL GETUSER`, and `ACL CAT`. `ACL GETUSER` cannot be limited to the current username, so this account can also read every user's ACL password hash. That probe disclosure is separate from key names returned by `RANDOMKEY` or `SCAN`. Startup calls `ACL GETUSER` only for the authenticated user and does not log or return that reply. Cluster discovery commands such as `CLUSTER SLOTS`, `CLUSTER NODES`, and `CLUSTER SHARDS` are not a rejection, and neither is `MEMORY USAGE` or `CLIENT SETNAME`. The account must be allowed to run the probe, or startup fails with `[redis_privilege_probe_failed]` even when the opt-out is set. A refused connection fails with `[redis_connection_failed]` and is not skipped by the opt-out.
|
|
102
|
+
|
|
103
|
+
An account limited to the read commands it needs, plus the probe commands, starts with the default configuration. No opt-out is required. `@read` includes `RANDOMKEY` and `SCAN`, so the read account also needs `-randomkey` and `-scan`. On Redis 6.2, `@read` includes `memory`, and `MEMORY PURGE` is not its own ACL name, so that account also needs `-memory`. The same shape works for a business account that grants the data categories and then revokes the global operations. `+@write` includes `FLUSHALL` and, on Redis 7, `FUNCTION FLUSH`, `FUNCTION DELETE`, `FUNCTION LOAD`, and `FUNCTION RESTORE`. On Redis 8 it also includes `TRIMSLOTS`. `+@connection` includes `CLIENT KILL`. `+@slow` and `+@scripting` include `EVAL` and `SCRIPT DEBUG`. Grant the broad category first, then revoke `@admin`, `@dangerous`, and `@scripting`, then revoke `RANDOMKEY`, `SCAN`, and the other individual global commands, then add the probe commands back. Redis 6.2 rejects unknown names such as `-function` and `-memory|purge`. Use `-memory` and `-@scripting` there. `-randomkey` and `-scan` are valid on Redis 6.2.
|
|
104
|
+
|
|
105
|
+
```redis
|
|
106
|
+
ACL SETUSER mcp-reader on >strong-password ~app:* resetchannels &
|
|
107
|
+
-@all
|
|
108
|
+
+@read
|
|
109
|
+
-@admin
|
|
110
|
+
-@dangerous
|
|
111
|
+
-randomkey
|
|
112
|
+
-scan
|
|
113
|
+
+ping
|
|
114
|
+
+acl|whoami
|
|
115
|
+
+acl|getuser
|
|
116
|
+
+acl|cat
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```redis
|
|
120
|
+
ACL SETUSER mcp-app on >strong-password ~app:* resetchannels &
|
|
121
|
+
-@all
|
|
122
|
+
+@read +@write +@string +@hash +@list +@set +@sortedset +@stream +@fast +@keyspace +@connection
|
|
123
|
+
-@admin -@dangerous -@scripting
|
|
124
|
+
-flushall -flushdb -swapdb -migrate -memory|purge
|
|
125
|
+
-randomkey -scan
|
|
126
|
+
+ping +acl|whoami +acl|getuser +acl|cat
|
|
127
|
+
+cluster|slots +cluster|nodes +cluster|shards
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`allow_unsafe_database_role` defaults to `false`. Set it to `true` in the config file, or export `MCP_ALLOW_UNSAFE_DATABASE_ROLE=true`, only when you cannot provision a least-privilege account. The server logs a warning and skips this privilege rejection. A refused connection, a failed ACL probe, and every other startup check still stop startup. The Redis user can still run `FLUSHALL`, `CONFIG`, `DEBUG`, or `SHUTDOWN` outside the tool catalog: this server does not expose a raw command, but the account itself can. Enable the option only for a Redis instance you control.
|
|
131
|
+
|
|
132
|
+
The warning is logged at warn level. HTTP mode shows it at the default `info` log level. Stdio mode keeps logs disabled so MCP output stays intact. Do not use the Redis `default` user. A standard server grants that user `+@all`.
|
|
133
|
+
|
|
134
|
+
## Output masking
|
|
135
|
+
|
|
136
|
+
Masking is off when the `masking` object is absent, when `enabled` is omitted, or when `enabled` is false. Tool results, CLI output, and errors then keep their current JSON. Set `enabled` to true and at least one rule to remove configured field names and values from output. `MCP_MASKING_JSON` replaces the whole YAML object when the variable is present. An empty value is rejected. Unset leaves the YAML object in place.
|
|
137
|
+
|
|
138
|
+
```yaml
|
|
139
|
+
masking:
|
|
140
|
+
enabled: true
|
|
141
|
+
placeholder: "[masked]"
|
|
142
|
+
names: ["synthetic_field"]
|
|
143
|
+
name_patterns: ["token_.+"]
|
|
144
|
+
values: ["synthetic-token-value"]
|
|
145
|
+
value_patterns: ["sk_live_[0-9]+"]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
export MCP_MASKING_JSON='{"enabled":true,"names":["synthetic_field"],"values":["synthetic-token-value"]}'
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Name rules match a whole dynamic object key, hash field, or other data string. Value rules are substring matches on the original text, including one-character literals. They run once and do not search the placeholder. A matched string becomes the placeholder. A matched number, bool, or other non-string becomes JSON `null`. An existing null stays `null`, so null can be a missing Redis value or a redacted value, and the JSON type can change.
|
|
153
|
+
|
|
154
|
+
Redis binary cells are masked from the original bytes, then both `utf8` and `base64` are written again from that result. A pair whose siblings disagree is rejected. Invalid UTF-8 stays in `base64` only. JSON objects and arrays stored as text are read as JSON, including escaped keys. `redis_key` `dump` is opaque. With an active policy it returns `[redis_masking_failed] result was not returned` and no payload. With masking off, `DUMP` is unchanged. `metadata.next_cursor` is a 16-byte continuation reference, not the stored key. If a rule matches that token, the page fails instead of returning a raw or rewritten cursor.
|
|
155
|
+
|
|
156
|
+
Invalid masking configuration, including `enabled: true` with no rules, stops startup with `invalid masking config` and does not echo the document. Bounds, duplicate keys, and key collisions use the same fixed failure and no partial payload. The Redis command and its arguments are unchanged. HTTP debug logs record a route class (`mcp`, `sse`, `message`, or `other`) instead of the raw path or query.
|
|
157
|
+
|
|
158
|
+
This covers the server's known Redis result shapes. It does not detect every private value, compressed payload, unknown encoding, or arbitrary PII.
|
|
159
|
+
|
|
160
|
+
The copied engine is mysql-mcp-server commit `6c6f58a343ff61e5f1e220b5cbdff7899afd886d`. This server does not patch those rules. Name patterns are parsed on their own and then anchored in the syntax tree. `a)|(b` is invalid. `(?:a)|(b)` matches only the whole names `a` and `b`. One budget is shared across a whole Redis result. A base64 cell longer than the input cap is rejected before it is decoded, and the paired `utf8` sibling is not returned. A value-rule hit on a native number or bool replaces that whole value with JSON `null`. A JSON value is counted again as its container, so it can exhaust the budget before a plain string of the same size. RE2 returns the leftmost-first match and does not search a longer alternative after a shorter one matches. Those two are limits. Masking still does not detect every private value, compressed payload, unknown encoding, or arbitrary PII.
|
|
161
|
+
|
|
84
162
|
## Production safety guide
|
|
85
163
|
|
|
86
164
|
This server reduces the Redis capabilities exposed to an AI client; it is not an authentication gateway or a complete data-access policy. Read-only mode prevents mutations, but reads can still disclose data or consume Redis capacity.
|
|
@@ -104,7 +182,7 @@ disabled_tools:
|
|
|
104
182
|
|
|
105
183
|
### Restrict the Redis account and keyspace
|
|
106
184
|
|
|
107
|
-
Connect with a dedicated Redis ACL account. Grant it only the commands and key patterns needed by the selected tools; do not use an administrator or application-owner account.
|
|
185
|
+
Connect with a dedicated Redis ACL account. Grant it only the commands and key patterns needed by the selected tools; do not use an administrator or application-owner account. Startup rejects `@admin`, `@dangerous`, `@scripting`, `FLUSHALL`, `FLUSHDB`, `TRIMSLOTS`, `FUNCTION FLUSH`, `SCRIPT DEBUG`, `MEMORY PURGE`, `RANDOMKEY`, `SCAN`, `CONFIG`, `DEBUG`, `SHUTDOWN`, and the other commands listed under Service account unless `allow_unsafe_database_role` is set. A key pattern limits commands that name a key. It does not apply to keyless commands. `RANDOMKEY` and `SCAN` return key names from the whole keyspace, including names the pattern cannot `GET`. `DBSIZE` still counts those keys. `redis_key` `random_key` and `redis_observe` `scan` call `RANDOMKEY` and `SCAN`, so a tenant profile that revokes those commands cannot use those operations. `ACL GETUSER` remains a separate probe permission and is not a key-name listing.
|
|
108
186
|
|
|
109
187
|
### Put HTTP and SSE behind an authenticated boundary
|
|
110
188
|
|
|
@@ -112,7 +190,7 @@ Prefer stdio for local MCP clients. When using HTTP or SSE, place the server beh
|
|
|
112
190
|
|
|
113
191
|
### Bound enumeration and verify the deployed catalog
|
|
114
192
|
|
|
115
|
-
`SCAN
|
|
193
|
+
`SCAN` does not take a key, so a key pattern does not limit it. A tenant profile revokes `SCAN` and `RANDOMKEY`. Where those commands remain granted, repeated `SCAN` requests can list key names outside that pattern. Each collection page is still bounded. Apply gateway quotas and monitoring for request rate, scan volume, latency, and errors. Before deployment, inspect the actual catalog:
|
|
116
194
|
|
|
117
195
|
```bash
|
|
118
196
|
./bin/redis-mcp-server tools list --config production.yaml
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@futuretea/redis-mcp-server",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Redis Model Context Protocol server",
|
|
5
5
|
"main": "./bin/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"redis-mcp-server": "bin/index.js"
|
|
8
8
|
},
|
|
9
9
|
"optionalDependencies": {
|
|
10
|
-
"@futuretea/redis-mcp-server-darwin-amd64": "0.0
|
|
11
|
-
"@futuretea/redis-mcp-server-darwin-arm64": "0.0
|
|
12
|
-
"@futuretea/redis-mcp-server-linux-amd64": "0.0
|
|
13
|
-
"@futuretea/redis-mcp-server-linux-arm64": "0.0
|
|
14
|
-
"@futuretea/redis-mcp-server-windows-amd64": "0.0
|
|
10
|
+
"@futuretea/redis-mcp-server-darwin-amd64": "0.2.0",
|
|
11
|
+
"@futuretea/redis-mcp-server-darwin-arm64": "0.2.0",
|
|
12
|
+
"@futuretea/redis-mcp-server-linux-amd64": "0.2.0",
|
|
13
|
+
"@futuretea/redis-mcp-server-linux-arm64": "0.2.0",
|
|
14
|
+
"@futuretea/redis-mcp-server-windows-amd64": "0.2.0"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|