Skip to content

Feature/multi database support #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

SPRAGE
Copy link
Contributor

@SPRAGE SPRAGE commented Jun 13, 2025

This pull request introduces support for Redis database switching, including configuration changes, new utility methods, and tools for managing databases. The main updates include adding environment variables and configuration options for database switching, implementing methods to handle blocked databases, and creating tools for database management such as switching, listing, and retrieving database information.

Configuration Updates:

  • .env.example: Added ALLOW_DB_SWITCH and BLOCKED_DBS environment variables to control database switching and specify blocked databases.
  • smithery.yaml: Updated the configuration schema to include allowDbSwitch and blockedDbs options, and mapped them to environment variables. [1] [2] [3]

Redis Configuration Enhancements:

  • src/common/config.py: Added support for ALLOW_DB_SWITCH and BLOCKED_DBS in Redis configuration, including methods to check if a database is blocked and retrieve the list of blocked databases. [1] [2]

Connection Management:

  • src/common/connection.py: Refactored the RedisConnectionManager class to support database switching, including methods to create connections for specific databases and handle blocked databases. [1] [2] [3]

Database Management Tools:

  • src/tools/server_management.py: Added tools for managing Redis databases, including switching databases, retrieving current database info, listing all databases, and handling blocked databases. [1] [2]

SPRAGE added 5 commits June 12, 2025 07:01
- Add get_connection_for_db() method to connect to specific databases
- Add switch_database() tool to change active database at runtime
- Add get_current_database() tool to get current database information
- Add list_all_databases() tool to discover databases with data
- Enable dynamic switching between Redis databases 0-15
- All existing tools work on currently selected database

Features:
- Runtime database switching without server restart
- Database discovery and key count reporting
- Support for multiple databases in single MCP server instance
- Proper error handling for invalid databases
- Compatible with existing Redis operations
…aults; enhance switch_database function documentation
@mortensi
Copy link
Member

mortensi commented Jun 16, 2025

Hello @SPRAGE, and thanks for studying this addition.

I am not a big supporter of multiple logical databases in general. Users can achieve similar results using ACLs on a subset of the data (e.g., a user can be granted access to data prefixed by a namespace like "app1:"). This would provide an overall feeling of multi-tenancy, but not be a real multi-tenancy configuration.

In addition, OSS Clusters do not support SELECT and the idea of multiple logical databases.

Using SELECT in an application can be okay if the connection is created and dismissed per session, which is not a desired way to manage connections. Working with shared connections, whether in a pool or not, achieves the effect of setting the connection to use a specific database for all the subsequent users. So, when the connection is returned to the pool and reused, it will provide data on another database. For this reason, as this MCP Server should remain generic, I think it is safer to remove the database switch and attribute the proper permissions to the Redis users.

I think that the use case this PR addresses can be solved by properly managing user permissions, with access granted to a specific data partition. So, a specific MCP Server will only have access to that subset of the data for that user. Or, simply specifying the logical database at MCP Server boot time using the REDIS_DB variable.

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.

2 participants