redis-mcp-server

ylcnfrht/redis-mcp-server

3.2

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.

Tools
4
Resources
0
Prompts
0

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.
  • inputSchema returned by tools/list is 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:

  1. Add or reuse a Zod schema and corresponding JSON Schema.
  2. Implement an execute function.
  3. Register the tool in the tools map with description, inputSchema, validate, execute, and format.

Scripts

From package.json:

  • build: compile TypeScript to dist/
  • start: run node dist/index.js
  • dev: tsc && node dist/index.js
  • inspector: npx @modelcontextprotocol/inspector node dist/index.js

Troubleshooting

  • "Cannot find module …/x.js": ensure ESM paths include .js extensions (tsconfig uses NodeNext).
  • "Key not found": getKey throws when key doesn't exist.
  • "Invalid arguments …": Zod validation failed; ensure string key and value.

License

MIT