Skip to content

perf(mcp): URL-keyed connection pooling for Redis database tools#808

Merged
joshrotenberg merged 1 commit intomainfrom
perf/mcp-redis-connection-pooling
Mar 5, 2026
Merged

perf(mcp): URL-keyed connection pooling for Redis database tools#808
joshrotenberg merged 1 commit intomainfrom
perf/mcp-redis-connection-pooling

Conversation

@joshrotenberg
Copy link
Copy Markdown
Collaborator

Summary

  • Add a connection cache to CachedClients keyed by resolved URL, returning shared MultiplexedConnection instances
  • Add redis_connection_for_url() on AppState with PING health check and automatic reconnect on stale connections
  • Add get_connection() helper in tools/redis/mod.rs combining URL resolution + cached connection retrieval
  • Replace per-handler Client::open + get_multiplexed_async_connection boilerplate across all 55 database tool handlers (-496 lines net)

Connections are keyed by URL (not profile name) so different profiles pointing to the same database share a connection, and raw URL callers benefit from caching too. Users with multiple database profiles get one cached connection per unique URL.

Follows the same RwLock<HashMap> pattern already used for Cloud and Enterprise API client caching.

Closes #801

Test plan

  • cargo clippy -p redisctl-mcp --all-features -- -D warnings (clean)
  • cargo check -p redisctl-mcp --no-default-features (clean)
  • cargo check -p redisctl-mcp --features database (clean)
  • cargo check -p redisctl-mcp --features cloud (clean)
  • cargo check -p redisctl-mcp --features enterprise (clean)
  • cargo test --lib -p redisctl-mcp --all-features (95 passed)
  • cargo fmt --all -- --check (clean)
  • Integration tests: cargo test -p redisctl-mcp --test redis_tools --all-features -- --ignored (requires Docker)

Add a connection cache to CachedClients (keyed by resolved URL) that
returns a shared MultiplexedConnection, matching the existing pattern
used for Cloud and Enterprise API clients.

- Add `database: HashMap<String, MultiplexedConnection>` to CachedClients
- Add `redis_connection_for_url()` on AppState with PING health check
  and automatic reconnect on stale connections
- Add `get_connection()` helper in tools/redis/mod.rs that combines
  URL resolution and cached connection retrieval
- Replace per-handler Client::open + get_multiplexed_async_connection
  boilerplate across all 55 database tool handlers

Connections are keyed by URL (not profile name) so different profiles
pointing to the same database share a connection, and raw URL callers
benefit from caching too.

Closes #801
@joshrotenberg joshrotenberg merged commit 22054ea into main Mar 5, 2026
16 checks passed
@joshrotenberg joshrotenberg deleted the perf/mcp-redis-connection-pooling branch March 5, 2026 21:39
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.

perf(mcp): connection pooling for Redis database tools

1 participant