redisctl-mcp 0.4.0

MCP (Model Context Protocol) server for Redis Cloud and Enterprise
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
//! Alerts, logs, aggregate stats, shards, debug info, and module tools

use std::sync::Arc;

use redis_enterprise::alerts::AlertHandler;
use redis_enterprise::debuginfo::DebugInfoHandler;
use redis_enterprise::logs::{LogsHandler, LogsQuery};
use redis_enterprise::modules::ModuleHandler;
use redis_enterprise::shards::ShardHandler;
use redis_enterprise::stats::StatsHandler;
use schemars::JsonSchema;
use serde::Deserialize;
use tower_mcp::extract::{Json, State};
use tower_mcp::{CallToolResult, McpRouter, ResultExt, Tool, ToolBuilder};

use crate::state::AppState;
use crate::tools::wrap_list;

// ============================================================================
// Alert tools
// ============================================================================

/// Input for listing alerts
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ListAlertsInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
}

/// Build the list_alerts tool
pub fn list_alerts(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("list_alerts")
        .description("List all active alerts in the Redis Enterprise cluster")
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, ListAlertsInput>(
            state,
            |State(state): State<Arc<AppState>>, Json(input): Json<ListAlertsInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = AlertHandler::new(client);
                let alerts = handler.list().await.tool_context("Failed to list alerts")?;

                wrap_list("alerts", &alerts)
            },
        )
        .build()
}

// ============================================================================
// Logs tools
// ============================================================================

/// Input for listing cluster logs
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ListLogsInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
    /// Start time - only return events after this time (ISO 8601 format, e.g., "2024-01-15T10:00:00Z")
    #[serde(default)]
    pub start_time: Option<String>,
    /// End time - only return events before this time (ISO 8601 format)
    #[serde(default)]
    pub end_time: Option<String>,
    /// Sort order: "asc" (oldest first) or "desc" (newest first, default)
    #[serde(default)]
    pub order: Option<String>,
    /// Maximum number of log entries to return
    #[serde(default)]
    pub limit: Option<u32>,
    /// Number of entries to skip (for pagination)
    #[serde(default)]
    pub offset: Option<u32>,
}

/// Build the list_logs tool
pub fn list_logs(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("list_logs")
        .description(
            "List cluster event logs from Redis Enterprise. Logs include events like database \
             changes, node status updates, configuration modifications, and alerts. Supports \
             filtering by time range and pagination.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, ListLogsInput>(
            state,
            |State(state): State<Arc<AppState>>, Json(input): Json<ListLogsInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let query = if input.start_time.is_some()
                    || input.end_time.is_some()
                    || input.order.is_some()
                    || input.limit.is_some()
                    || input.offset.is_some()
                {
                    Some(LogsQuery {
                        stime: input.start_time,
                        etime: input.end_time,
                        order: input.order,
                        limit: input.limit,
                        offset: input.offset,
                    })
                } else {
                    None
                };

                let handler = LogsHandler::new(client);
                let logs = handler
                    .list(query)
                    .await
                    .tool_context("Failed to list logs")?;

                wrap_list("logs", &logs)
            },
        )
        .build()
}

// ============================================================================
// Aggregate Stats tools
// ============================================================================

/// Input for getting all nodes stats
#[derive(Debug, Deserialize, JsonSchema)]
pub struct GetAllNodesStatsInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
}

/// Build the get_all_nodes_stats tool
pub fn get_all_nodes_stats(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("get_all_nodes_stats")
        .description(
            "Get current statistics for all nodes in the Redis Enterprise cluster in a single \
             call. Returns aggregated stats per node including CPU, memory, and network metrics.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, GetAllNodesStatsInput>(
            state,
            |State(state): State<Arc<AppState>>,
             Json(input): Json<GetAllNodesStatsInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = StatsHandler::new(client);
                let stats = handler
                    .nodes_last()
                    .await
                    .tool_context("Failed to get all nodes stats")?;

                CallToolResult::from_serialize(&stats)
            },
        )
        .build()
}

/// Input for getting all databases stats
#[derive(Debug, Deserialize, JsonSchema)]
pub struct GetAllDatabasesStatsInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
}

/// Build the get_all_databases_stats tool
pub fn get_all_databases_stats(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("get_all_databases_stats")
        .description(
            "Get current statistics for all databases in the Redis Enterprise cluster in a \
             single call. Returns aggregated stats per database including latency, throughput, \
             and memory usage.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, GetAllDatabasesStatsInput>(
            state,
            |State(state): State<Arc<AppState>>,
             Json(input): Json<GetAllDatabasesStatsInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = StatsHandler::new(client);
                let stats = handler.databases_last().await.tool_context("Failed to get all databases stats")?;

                CallToolResult::from_serialize(&stats)
            },
        )
        .build()
}

/// Input for getting shard stats
#[derive(Debug, Deserialize, JsonSchema)]
pub struct GetShardStatsInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
    /// Shard UID
    pub uid: u32,
}

/// Build the get_shard_stats tool
pub fn get_shard_stats(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("get_shard_stats")
        .description("Get current statistics for a specific shard in the Redis Enterprise cluster")
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, GetShardStatsInput>(
            state,
            |State(state): State<Arc<AppState>>, Json(input): Json<GetShardStatsInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = StatsHandler::new(client);
                let stats = handler
                    .shard(input.uid, None)
                    .await
                    .tool_context("Failed to get shard stats")?;

                CallToolResult::from_serialize(&stats)
            },
        )
        .build()
}

/// Input for getting all shards stats
#[derive(Debug, Deserialize, JsonSchema)]
pub struct GetAllShardsStatsInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
}

/// Build the get_all_shards_stats tool
pub fn get_all_shards_stats(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("get_all_shards_stats")
        .description(
            "Get current statistics for all shards in the Redis Enterprise cluster in a single \
             call. Returns aggregated stats per shard.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, GetAllShardsStatsInput>(
            state,
            |State(state): State<Arc<AppState>>,
             Json(input): Json<GetAllShardsStatsInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = StatsHandler::new(client);
                let stats = handler
                    .shards(None)
                    .await
                    .tool_context("Failed to get all shards stats")?;

                CallToolResult::from_serialize(&stats)
            },
        )
        .build()
}

// ============================================================================
// Shard tools
// ============================================================================

/// Input for listing shards
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ListShardsInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
    /// Optional database UID to filter by
    #[serde(default)]
    pub database_uid: Option<u32>,
}

/// Build the list_shards tool
pub fn list_shards(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("list_shards")
        .description(
            "List all shards in the Redis Enterprise cluster. Optionally filter by database UID.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, ListShardsInput>(
            state,
            |State(state): State<Arc<AppState>>, Json(input): Json<ListShardsInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = ShardHandler::new(client);
                let shards = if let Some(db_uid) = input.database_uid {
                    handler
                        .list_by_database(db_uid)
                        .await
                        .tool_context("Failed to list shards")?
                } else {
                    handler.list().await.tool_context("Failed to list shards")?
                };

                wrap_list("shards", &shards)
            },
        )
        .build()
}

/// Input for getting a specific shard
#[derive(Debug, Deserialize, JsonSchema)]
pub struct GetShardInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
    /// Shard UID (e.g., "1" or "2")
    pub uid: String,
}

/// Build the get_shard tool
pub fn get_shard(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("get_shard")
        .description(
            "Get detailed information about a specific shard in the Redis Enterprise cluster \
             including role (master/replica), status, and assigned node.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, GetShardInput>(
            state,
            |State(state): State<Arc<AppState>>, Json(input): Json<GetShardInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = ShardHandler::new(client);
                let shard = handler
                    .get(&input.uid)
                    .await
                    .tool_context("Failed to get shard")?;

                CallToolResult::from_serialize(&shard)
            },
        )
        .build()
}

// ============================================================================
// Debug Info tools
// ============================================================================

/// Input for listing debug info tasks
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ListDebugInfoTasksInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
}

/// Build the list_debug_info_tasks tool
pub fn list_debug_info_tasks(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("list_debug_info_tasks")
        .description(
            "List all debug info collection tasks in the Redis Enterprise cluster. Returns task \
             IDs, statuses (queued, running, completed, failed), and download URLs for completed \
             collections.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, ListDebugInfoTasksInput>(
            state,
            |State(state): State<Arc<AppState>>,
             Json(input): Json<ListDebugInfoTasksInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = DebugInfoHandler::new(client);
                let tasks = handler
                    .list()
                    .await
                    .tool_context("Failed to list debug info tasks")?;

                wrap_list("tasks", &tasks)
            },
        )
        .build()
}

/// Input for getting debug info task status
#[derive(Debug, Deserialize, JsonSchema)]
pub struct GetDebugInfoStatusInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
    /// The task ID returned when debug info collection was started
    pub task_id: String,
}

/// Build the get_debug_info_status tool
pub fn get_debug_info_status(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("get_debug_info_status")
        .description(
            "Get the status of a debug info collection task. Returns status (queued, running, \
             completed, failed), progress percentage, download URL (when completed), and error \
             message (if failed).",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, GetDebugInfoStatusInput>(
            state,
            |State(state): State<Arc<AppState>>,
             Json(input): Json<GetDebugInfoStatusInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = DebugInfoHandler::new(client);
                let status = handler
                    .status(&input.task_id)
                    .await
                    .tool_context("Failed to get debug info status")?;

                CallToolResult::from_serialize(&status)
            },
        )
        .build()
}

// ============================================================================
// Module tools
// ============================================================================

/// Input for listing modules
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ListModulesInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
}

/// Build the list_modules tool
pub fn list_modules(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("list_modules")
        .description(
            "List all Redis modules installed on the Redis Enterprise cluster. Returns module \
             names, versions, descriptions, and capabilities (e.g., RedisJSON, RediSearch, \
             RedisTimeSeries).",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, ListModulesInput>(
            state,
            |State(state): State<Arc<AppState>>, Json(input): Json<ListModulesInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = ModuleHandler::new(client);
                let modules = handler
                    .list()
                    .await
                    .tool_context("Failed to list modules")?;

                wrap_list("modules", &modules)
            },
        )
        .build()
}

/// Input for getting a specific module
#[derive(Debug, Deserialize, JsonSchema)]
pub struct GetModuleInput {
    /// Profile name for multi-cluster support. If not specified, uses the first configured profile or default.
    #[serde(default)]
    pub profile: Option<String>,
    /// Module UID
    pub uid: String,
}

/// Build the get_module tool
pub fn get_module(state: Arc<AppState>) -> Tool {
    ToolBuilder::new("get_module")
        .description(
            "Get detailed information about a specific Redis module including version, \
             description, author, license, capabilities, and platform compatibility.",
        )
        .read_only_safe()
        .extractor_handler_typed::<_, _, _, GetModuleInput>(
            state,
            |State(state): State<Arc<AppState>>, Json(input): Json<GetModuleInput>| async move {
                let client = state
                    .enterprise_client_for_profile(input.profile.as_deref())
                    .await
                    .map_err(|e| crate::tools::credential_error("enterprise", e))?;

                let handler = ModuleHandler::new(client);
                let module = handler
                    .get(&input.uid)
                    .await
                    .tool_context("Failed to get module")?;

                CallToolResult::from_serialize(&module)
            },
        )
        .build()
}

/// Build an MCP sub-router containing observability tools
pub fn router(state: Arc<AppState>) -> McpRouter {
    McpRouter::new()
        // Alerts
        .tool(list_alerts(state.clone()))
        // Logs
        .tool(list_logs(state.clone()))
        // Aggregate Stats
        .tool(get_all_nodes_stats(state.clone()))
        .tool(get_all_databases_stats(state.clone()))
        .tool(get_shard_stats(state.clone()))
        .tool(get_all_shards_stats(state.clone()))
        // Shards
        .tool(list_shards(state.clone()))
        .tool(get_shard(state.clone()))
        // Debug Info
        .tool(list_debug_info_tasks(state.clone()))
        .tool(get_debug_info_status(state.clone()))
        // Modules
        .tool(list_modules(state.clone()))
        .tool(get_module(state.clone()))
}