ylcnfrht/redis-mcp-server
If you are the rightful owner of redis-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A tiny Model Context Protocol (MCP) server that exposes basic Redis database tools, built with TypeScript and Zod.
Redis MCP Server
A tiny Model Context Protocol (MCP) server that exposes basic Redis database tools. Built with TypeScript and Zod. Easy to extend.
Quick Start
npm install
npm run build && npm start
Server runs over stdio and connects to Redis on localhost:6379.
Development
npm run dev
Inspector
Interactive testing with MCP Inspector:
npm run build
npm run inspector
This starts the server under the inspector so you can list tools and call them.
Tools
- setKey: sets a key-value pair in Redis
- getKey: gets a value from Redis by key
- delKey: deletes a key from Redis
- listKeys: lists all keys in Redis
List tools request (MCP):
{
"method": "tools/list",
"params": {}
}
Call example:
{
"method": "tools/call",
"params": {
"name": "setKey",
"arguments": { "key": "user:123", "value": "John Doe" }
}
}
Response example:
{
"content": [{ "type": "text", "text": "Key \"user:123\" set with value \"John Doe\"" }]
}
Validation & Schemas
- Input validation is done with Zod directly in
src/index.ts. inputSchemareturned bytools/listis a JSON Schema object that MCP clients can use.
Key-value input schema (Zod):
const keyValueInput = z.object({ key: z.string(), value: z.string() });
JSON Schema (for MCP):
const inputKeyValueJsonSchema = {
type: 'object',
properties: {
key: { type: 'string', description: 'Key' },
value: { type: 'string', description: 'Value' },
},
required: ['key', 'value'],
} as const;
Project Structure
src/
index.ts # server setup, tool definitions, validation, and handlers
dist/
index.js # build output
Extending (add a new tool)
All tools are defined in src/index.ts under the tools map. To add one:
- Add or reuse a Zod schema and corresponding JSON Schema.
- Implement an
executefunction. - Register the tool in the
toolsmap withdescription,inputSchema,validate,execute, andformat.
Scripts
From package.json:
build: compile TypeScript todist/start: runnode dist/index.jsdev:tsc && node dist/index.jsinspector:npx @modelcontextprotocol/inspector node dist/index.js
Troubleshooting
- "Cannot find module …/x.js": ensure ESM paths include
.jsextensions (tsconfig uses NodeNext). - "Key not found":
getKeythrows when key doesn't exist. - "Invalid arguments …": Zod validation failed; ensure string
keyandvalue.
License
MIT