Skip to content

Conversation

@joshrotenberg
Copy link
Collaborator

Summary

Add 23 new MCP tools for direct Redis database interaction, enabling AI agents to query, inspect, and diagnose Redis databases through natural conversation.

Closes #564

New Tools (23 total)

Server Info (6)

  • database_ping - Ping the Redis server
  • database_info - Get server information (INFO)
  • database_dbsize - Get number of keys in database
  • database_module_list - List loaded modules
  • database_client_list - Get connected clients
  • database_config_get - Get configuration values

Key Operations (7)

  • database_scan - Scan keys matching a pattern (safe alternative to KEYS)
  • database_type - Get key type
  • database_ttl - Get key TTL in seconds
  • database_exists - Check if key exists
  • database_memory_usage - Get memory usage of a key
  • database_get - Get string key value
  • database_execute - Execute arbitrary Redis command

Data Structures (10)

  • database_hgetall - Get all hash fields
  • database_hlen - Get hash length
  • database_lrange - Get list range
  • database_llen - Get list length
  • database_smembers - Get set members
  • database_scard - Get set cardinality
  • database_zrange - Get sorted set range
  • database_zcard - Get sorted set cardinality
  • database_slowlog - Get slow log entries
  • database_slowlog_len - Get slow log length

Features

  • Database Profile Integration: Uses the new Database profile type for connection credentials (host, port, password, TLS, username, database number)
  • Read-Only Mode Protection: Write commands (SET, DEL, FLUSHDB, etc.) are blocked by default; use --allow-writes to enable
  • Generic Execute Tool: database_execute allows arbitrary Redis commands for flexibility
  • Lazy Connection: Connection is established on first tool use, not server startup
  • Full TLS Support: Uses tokio-rustls for secure connections to Redis Cloud and other TLS-enabled instances

Implementation

  • New database_tools.rs module with DatabaseTools struct and ConnectionManager
  • Parameter structs and 23 tool implementations in server.rs
  • Updated mcp tools command output (now shows 78 total tools)
  • Integration test for local Redis validation

Testing

# Unit tests
cargo test -p redisctl-mcp

# Integration test (requires local Redis + local-redis profile)
cargo test -p redisctl-mcp -- --ignored test_database_tools_integration

# View tools list
cargo run -- mcp tools

Tool Count

Category Count
Cloud 7
Enterprise 48
Database 23
Total 78

Add 23 new MCP tools for direct Redis database interaction, enabling AI
agents to query, inspect, and diagnose Redis databases.

New tools:
- Server info: ping, info, dbsize, module_list, client_list, config_get
- Key operations: scan, type, ttl, exists, memory_usage, get, execute
- Data structures: hgetall, hlen, lrange, llen, smembers, scard, zrange,
  zcard, slowlog, slowlog_len

Features:
- Uses Database profile type for connection credentials
- Read-only mode blocks write commands (SET, DEL, FLUSHDB, etc.)
- Generic execute tool for arbitrary Redis commands
- Lazy connection initialization
- Full TLS support via tokio-rustls

Implementation:
- New database_tools.rs with DatabaseTools struct and ConnectionManager
- Parameter structs and tool implementations in server.rs
- Updated mcp tools list command (now 78 total tools)
- Integration test for local Redis validation
…lete, alias, and synonym tools

New tools added:
- FT.CREATE: Create indexes with full schema definition (TEXT, TAG, NUMERIC, GEO, VECTOR fields)
- FT.DROPINDEX: Delete indexes with optional document deletion
- FT.ALTER: Add fields to existing indexes
- FT.EXPLAIN: Get query execution plans for debugging
- FT.TAGVALS: Get unique values for TAG fields
- FT.SPELLCHECK: Get spelling suggestions for queries
- FT.ALIASADD/DEL/UPDATE: Manage index aliases for zero-downtime rebuilds
- FT.SUGADD/GET/DEL/LEN: Autocomplete dictionary management
- FT.SYNDUMP/SYNUPDATE: Synonym group management

All tools include comprehensive documentation for jpx discovery indexing.
Add 10 new RedisJSON MCP tools:
- JSON.MGET: Get JSON values from multiple keys
- JSON.OBJKEYS: Get all keys from a JSON object
- JSON.OBJLEN: Get the number of keys in a JSON object
- JSON.ARRINDEX: Find the index of an element in a JSON array
- JSON.ARRPOP: Pop an element from a JSON array
- JSON.ARRTRIM: Trim a JSON array to a specified range
- JSON.ARRINSERT: Insert elements into a JSON array
- JSON.CLEAR: Clear container values or set numbers to 0
- JSON.TOGGLE: Toggle a boolean value
- JSON.FORGET: Alias for JSON.DEL (documented separately)

Also adds JSON.CLEAR and JSON.TOGGLE to WRITE_COMMANDS list for
read-only mode protection.

These tools enable comprehensive JSON document manipulation and
support testing RediSearch on both HASH and JSON data types.
- Add database_pipeline tool for executing multiple Redis commands in a single round-trip
- Support atomic mode (MULTI/EXEC) for transactional execution
- Benchmarked: 380x speedup vs individual calls (100 commands: 5ms vs 2065ms)
- Update session notes with competitive analysis and scoped work chunks

Streams and Pub/Sub support scoped for next implementation phase.
The rustls-pemfile crate is marked unmaintained but is a transitive
dependency of the redis crate. We cannot directly update it until
upstream redis-rs updates their dependencies.
Streams tools (18 new tools):
- database_xadd: Add entries to streams
- database_xread: Read from streams (supports blocking)
- database_xrange/xrevrange: Range queries
- database_xlen: Get stream length
- database_xinfo_stream/groups/consumers: Stream introspection
- database_xgroup_create/destroy/delconsumer/setid: Consumer group management
- database_xreadgroup: Consumer group reads
- database_xack: Acknowledge messages
- database_xdel: Delete entries
- database_xtrim: Trim stream length
- database_xpending: Get pending entries
- database_xclaim/xautoclaim: Claim pending messages

Pub/Sub tools (4 new tools):
- database_publish: Publish messages to channels
- database_pubsub_channels: List active channels
- database_pubsub_numsub: Get subscriber counts
- database_pubsub_numpat: Get pattern subscription count

Also:
- Fix clippy doc comment formatting
- Add cargo-audit config to ignore RUSTSEC-2025-0134
Added 22 new tool definitions:
- 18 Streams tools (XADD, XREAD, XRANGE, XREVRANGE, XLEN, XINFO, XGROUP, XREADGROUP, XACK, XDEL, XTRIM, XPENDING, XCLAIM, XAUTOCLAIM)
- 4 Pub/Sub tools (PUBLISH, PUBSUB CHANNELS, PUBSUB NUMSUB, PUBSUB NUMPAT)

Added two new subcategories:
- streams: Redis Streams for event sourcing and message queues
- pubsub: Pub/Sub messaging operations

Total tools in discovery: 100
@joshrotenberg joshrotenberg merged commit 0e73dd5 into main Jan 16, 2026
25 checks passed
@joshrotenberg joshrotenberg deleted the feat/mcp-database-tools branch January 16, 2026 21:07
@joshrotenberg joshrotenberg mentioned this pull request Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add Redis database tools to MCP server

2 participants