redisctl-mcp 0.1.2

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
//! Cloud tools implementation
//!
//! Wraps Redis Cloud API client operations for MCP tool invocation.

use redis_cloud::fixed::subscriptions::FixedSubscriptionCreateRequest;
use redis_cloud::{
    AccountHandler, CloudAccountHandler, CloudClient, DatabaseHandler, FixedDatabaseHandler,
    FixedSubscriptionHandler, PrivateLinkHandler, SubscriptionHandler, TaskHandler,
    TransitGatewayHandler, VpcPeeringHandler,
};
use redisctl_config::Config;
use rmcp::{ErrorData as RmcpError, model::*};
use serde_json::Value;
use tracing::debug;

/// Cloud tools wrapper
#[derive(Clone)]
pub struct CloudTools {
    client: CloudClient,
}

impl CloudTools {
    /// Create new Cloud tools instance
    pub fn new(profile: Option<&str>) -> anyhow::Result<Self> {
        let config = Config::load()?;

        // Resolve profile name: explicit > default > error
        let profile_name = match profile {
            Some(name) => name.to_string(),
            None => config.resolve_cloud_profile(None)?,
        };

        debug!(profile = %profile_name, "Loading Cloud client from profile");

        let profile_config = config
            .profiles
            .get(&profile_name)
            .ok_or_else(|| anyhow::anyhow!("Cloud profile '{}' not found", profile_name))?;

        let (api_key, api_secret, api_url) = profile_config
            .cloud_credentials()
            .ok_or_else(|| anyhow::anyhow!("Profile '{}' is not a Cloud profile", profile_name))?;

        let client = CloudClient::builder()
            .api_key(api_key)
            .api_secret(api_secret)
            .base_url(api_url.to_string())
            .build()?;

        Ok(Self { client })
    }

    fn to_result(&self, value: serde_json::Value) -> Result<CallToolResult, RmcpError> {
        Ok(CallToolResult::success(vec![Content::text(
            serde_json::to_string_pretty(&value).unwrap_or_else(|_| value.to_string()),
        )]))
    }

    fn to_error(&self, err: impl std::fmt::Display) -> RmcpError {
        RmcpError::internal_error(err.to_string(), None)
    }

    // =========================================================================
    // Account Operations
    // =========================================================================

    /// Get account information
    pub async fn get_account(&self) -> Result<CallToolResult, RmcpError> {
        let handler = AccountHandler::new(self.client.clone());
        let account = handler
            .get_current_account()
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(account).map_err(|e| self.to_error(e))?)
    }

    /// Get payment methods
    pub async fn get_payment_methods(&self) -> Result<CallToolResult, RmcpError> {
        let handler = AccountHandler::new(self.client.clone());
        let methods = handler
            .get_account_payment_methods()
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(methods).map_err(|e| self.to_error(e))?)
    }

    /// Get supported database modules
    pub async fn get_database_modules(&self) -> Result<CallToolResult, RmcpError> {
        let handler = AccountHandler::new(self.client.clone());
        let modules = handler
            .get_supported_database_modules()
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(modules).map_err(|e| self.to_error(e))?)
    }

    /// Get supported regions
    pub async fn get_regions(&self, provider: Option<&str>) -> Result<CallToolResult, RmcpError> {
        let handler = AccountHandler::new(self.client.clone());
        let regions = handler
            .get_supported_regions(provider.map(String::from))
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(regions).map_err(|e| self.to_error(e))?)
    }

    // =========================================================================
    // Pro Subscription Operations
    // =========================================================================

    /// List all Pro subscriptions
    pub async fn list_subscriptions(&self) -> Result<CallToolResult, RmcpError> {
        let handler = SubscriptionHandler::new(self.client.clone());
        let subs = handler
            .get_all_subscriptions()
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(subs).map_err(|e| self.to_error(e))?)
    }

    /// Get a specific Pro subscription
    pub async fn get_subscription(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = SubscriptionHandler::new(self.client.clone());
        let sub = handler
            .get_subscription_by_id(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(sub).map_err(|e| self.to_error(e))?)
    }

    /// Create a Pro subscription (accepts JSON payload)
    pub async fn create_subscription(&self, request: Value) -> Result<CallToolResult, RmcpError> {
        let result = self
            .client
            .post_raw("/subscriptions", request)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(result)
    }

    /// Delete a Pro subscription
    pub async fn delete_subscription(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = SubscriptionHandler::new(self.client.clone());
        let result = handler
            .delete_subscription_by_id(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(result).map_err(|e| self.to_error(e))?)
    }

    // =========================================================================
    // Essentials (Fixed) Subscription Operations
    // =========================================================================

    /// List all Essentials subscriptions
    pub async fn list_essentials_subscriptions(&self) -> Result<CallToolResult, RmcpError> {
        let handler = FixedSubscriptionHandler::new(self.client.clone());
        let subs = handler.list().await.map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(subs).map_err(|e| self.to_error(e))?)
    }

    /// Get a specific Essentials subscription
    pub async fn get_essentials_subscription(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = FixedSubscriptionHandler::new(self.client.clone());
        let sub = handler
            .get_by_id(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(sub).map_err(|e| self.to_error(e))?)
    }

    /// Create an Essentials subscription
    pub async fn create_essentials_subscription(
        &self,
        name: &str,
        plan_id: i64,
        payment_method_id: Option<i64>,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = FixedSubscriptionHandler::new(self.client.clone());
        let request = FixedSubscriptionCreateRequest {
            name: name.to_string(),
            plan_id: plan_id as i32,
            payment_method: None,
            payment_method_id: payment_method_id.map(|id| id as i32),
            command_type: None,
            extra: Value::Null,
        };
        let result = handler
            .create(&request)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(result).map_err(|e| self.to_error(e))?)
    }

    /// Delete an Essentials subscription
    pub async fn delete_essentials_subscription(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = FixedSubscriptionHandler::new(self.client.clone());
        let result = handler
            .delete_by_id(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(result).map_err(|e| self.to_error(e))?)
    }

    /// List Essentials plans
    pub async fn list_essentials_plans(
        &self,
        provider: Option<&str>,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = FixedSubscriptionHandler::new(self.client.clone());
        let plans = handler
            .list_plans(provider.map(String::from), None)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(plans).map_err(|e| self.to_error(e))?)
    }

    // =========================================================================
    // Database Operations
    // =========================================================================

    /// List databases in a subscription
    pub async fn list_databases(&self, subscription_id: i64) -> Result<CallToolResult, RmcpError> {
        let handler = DatabaseHandler::new(self.client.clone());
        let dbs = handler
            .get_subscription_databases(subscription_id as i32, None, None)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(dbs).map_err(|e| self.to_error(e))?)
    }

    /// Get a specific database
    pub async fn get_database(
        &self,
        subscription_id: i64,
        database_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = DatabaseHandler::new(self.client.clone());
        let db = handler
            .get_subscription_database_by_id(subscription_id as i32, database_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(db).map_err(|e| self.to_error(e))?)
    }

    // =========================================================================
    // Task Operations
    // =========================================================================

    /// List tasks
    pub async fn list_tasks(&self) -> Result<CallToolResult, RmcpError> {
        let handler = TaskHandler::new(self.client.clone());
        let tasks = handler
            .get_all_tasks()
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(tasks).map_err(|e| self.to_error(e))?)
    }

    /// Get a specific task
    pub async fn get_task(&self, task_id: &str) -> Result<CallToolResult, RmcpError> {
        let handler = TaskHandler::new(self.client.clone());
        let task = handler
            .get_task_by_id(task_id.to_string())
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(task).map_err(|e| self.to_error(e))?)
    }

    // =========================================================================
    // Essentials (Fixed) Database Operations
    // =========================================================================

    /// List databases in an Essentials subscription
    pub async fn list_essentials_databases(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = FixedDatabaseHandler::new(self.client.clone());
        let dbs = handler
            .list(subscription_id as i32, None, None)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(dbs).map_err(|e| self.to_error(e))?)
    }

    /// Get a specific Essentials database
    pub async fn get_essentials_database(
        &self,
        subscription_id: i64,
        database_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = FixedDatabaseHandler::new(self.client.clone());
        let db = handler
            .get_by_id(subscription_id as i32, database_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(db).map_err(|e| self.to_error(e))?)
    }

    /// Delete an Essentials database
    pub async fn delete_essentials_database(
        &self,
        subscription_id: i64,
        database_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = FixedDatabaseHandler::new(self.client.clone());
        let result = handler
            .delete_by_id(subscription_id as i32, database_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(result).map_err(|e| self.to_error(e))?)
    }

    // =========================================================================
    // VPC Peering Operations
    // =========================================================================

    /// Get VPC peerings for a subscription
    pub async fn get_vpc_peerings(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = VpcPeeringHandler::new(self.client.clone());
        let peerings = handler
            .get(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(peerings).map_err(|e| self.to_error(e))?)
    }

    /// Delete a VPC peering
    pub async fn delete_vpc_peering(
        &self,
        subscription_id: i64,
        peering_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = VpcPeeringHandler::new(self.client.clone());
        handler
            .delete(subscription_id as i32, peering_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::json!({
            "success": true,
            "message": format!("VPC peering {} deleted from subscription {}", peering_id, subscription_id)
        }))
    }

    // =========================================================================
    // Cloud Account Operations
    // =========================================================================

    /// List all cloud accounts
    pub async fn list_cloud_accounts(&self) -> Result<CallToolResult, RmcpError> {
        let handler = CloudAccountHandler::new(self.client.clone());
        let accounts = handler
            .get_cloud_accounts()
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(accounts).map_err(|e| self.to_error(e))?)
    }

    /// Get a specific cloud account
    pub async fn get_cloud_account(&self, account_id: i64) -> Result<CallToolResult, RmcpError> {
        let handler = CloudAccountHandler::new(self.client.clone());
        let account = handler
            .get_cloud_account_by_id(account_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(account).map_err(|e| self.to_error(e))?)
    }

    /// Delete a cloud account
    pub async fn delete_cloud_account(&self, account_id: i64) -> Result<CallToolResult, RmcpError> {
        let handler = CloudAccountHandler::new(self.client.clone());
        let result = handler
            .delete_cloud_account(account_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(result).map_err(|e| self.to_error(e))?)
    }

    // =========================================================================
    // Private Link Operations (AWS PrivateLink)
    // =========================================================================

    /// Get Private Link configuration for a subscription
    pub async fn get_private_link(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = PrivateLinkHandler::new(self.client.clone());
        let result = handler
            .get(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(result)
    }

    /// Delete Private Link configuration for a subscription
    pub async fn delete_private_link(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = PrivateLinkHandler::new(self.client.clone());
        let result = handler
            .delete(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(result)
    }

    // =========================================================================
    // Transit Gateway Operations (AWS Transit Gateway)
    // =========================================================================

    /// Get Transit Gateway attachments for a subscription
    pub async fn get_transit_gateway_attachments(
        &self,
        subscription_id: i64,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = TransitGatewayHandler::new(self.client.clone());
        let result = handler
            .get_attachments(subscription_id as i32)
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(result).map_err(|e| self.to_error(e))?)
    }

    /// Delete a Transit Gateway attachment
    pub async fn delete_transit_gateway_attachment(
        &self,
        subscription_id: i64,
        attachment_id: &str,
    ) -> Result<CallToolResult, RmcpError> {
        let handler = TransitGatewayHandler::new(self.client.clone());
        let result = handler
            .delete_attachment(subscription_id as i32, attachment_id.to_string())
            .await
            .map_err(|e| self.to_error(e))?;
        self.to_result(serde_json::to_value(result).map_err(|e| self.to_error(e))?)
    }
}