1
+ # -*- coding: utf-8 -*-
2
+ """Provides core functionalities for the "rds_custom" MCP toolset.
3
+
4
+ This module contains the engine-agnostic logic and serves as the **required
5
+ base dependency** for all engine-specific toolsets. It can also be loaded
6
+ stand-alone for basic operations.
7
+
8
+ Toolsets are loaded at runtime via the `--toolsets` command-line argument
9
+ or a corresponding environment variable.
10
+
11
+ Command-Line Usage:
12
+ -------------------
13
+ 1. **Base Usage Only:**
14
+ To load only the base functionalities, specify `rds_custom` by itself.
15
+
16
+ 2. **Single-Engine Usage:**
17
+ To use tools for a specific engine (e.g., SQL Server), you MUST include
18
+ **both** the base toolset `rds_custom` AND the engine-specific toolset
19
+ `rds_custom_mssql` in the list, separated by a comma.
20
+
21
+ Command-Line Examples:
22
+ ----------------------
23
+ # Scenario 1: Basic usage with only the base toolset
24
+ # python server.py --toolsets rds_custom
25
+
26
+ # Scenario 2: Usage for SQL Server
27
+ # python your_server.py --toolsets rds_custom,rds_custom_mssql
28
+ """
29
+
30
+ import logging
31
+ from typing import Dict , Any , Optional , List
32
+ from .tool_registry import tool
33
+ import alibabacloud_rds20140815 .models as RdsApiModels
34
+ from .aliyun_openapi_gateway import AliyunServiceGateway
35
+
36
+
37
+ logger = logging .getLogger (__name__ )
38
+
39
+ RDS_CUSTOM_GROUP_NAME = 'rds_custom'
40
+
41
+ @tool (group = RDS_CUSTOM_GROUP_NAME )
42
+ async def describe_rc_instances (region_id : str , instance_id : str | None ) -> Dict [str , Any ]:
43
+ """
44
+ describe rds custom instances.
45
+
46
+ Args:
47
+ region_id: The region ID of the RDS Custom instances.
48
+ instance_id: The ID of a specific instance. If omitted, all instances in the region are returned.
49
+
50
+ Returns:
51
+ dict[str, Any]: The response containing instance metadata.
52
+ """
53
+ request = RdsApiModels .DescribeRCInstancesRequest (
54
+ region_id = region_id ,
55
+ instance_id = instance_id
56
+ )
57
+ rds_client = AliyunServiceGateway (region_id ).rds ()
58
+ return rds_client .describe_rcinstances_with_options (request )
59
+
60
+ @tool (group = RDS_CUSTOM_GROUP_NAME )
61
+ def describe_rc_instance_attribute (region_id : str ,instance_id : str ) -> Dict [str , Any ]:
62
+ """
63
+ describe a single rds custom instance's details.
64
+
65
+ Args:
66
+ region_id: The region ID of the RDS Custom instance.
67
+ instance_id: The ID of the RDS Custom instance.
68
+
69
+ Returns:
70
+ dict[str, Any]: The response containing the instance details.
71
+ """
72
+ request = RdsApiModels .DescribeRCInstanceAttributeRequest (
73
+ region_id = region_id ,
74
+ instance_id = instance_id
75
+ )
76
+ return AliyunServiceGateway (region_id ).rds ().describe_rcinstance_attribute_with_options (request )
77
+
78
+ @tool (group = RDS_CUSTOM_GROUP_NAME )
79
+ def resize_rc_instance_disk (
80
+ region_id : str ,
81
+ instance_id : str ,
82
+ new_size : int ,
83
+ disk_id : str ,
84
+ auto_pay : bool = False ,
85
+ dry_run : bool = False ,
86
+ ) -> Dict [str , Any ]:
87
+ """
88
+ resize a specific rds custom instance's disk.
89
+
90
+ Args:
91
+ region_id: The region ID of the RDS Custom instance.
92
+ instance_id: The ID of the RDS Custom instance.
93
+ new_size: The target size of the disk in GiB.
94
+ disk_id: The ID of the cloud disk.
95
+ auto_pay: Specifies whether to enable automatic payment. Default is false.
96
+ dry_run: Specifies whether to perform a dry run. Default is false.
97
+
98
+ Returns:
99
+ dict[str, Any]: The response containing the result of the operation.
100
+ """
101
+ request = RdsApiModels .ResizeRCInstanceDiskRequest (
102
+ region_id = region_id ,
103
+ instance_id = instance_id ,
104
+ new_size = new_size ,
105
+ disk_id = disk_id ,
106
+ auto_pay = auto_pay ,
107
+ dry_run = dry_run ,
108
+ type = 'online'
109
+ )
110
+ return AliyunServiceGateway (region_id ).rds ().resize_rcinstance_disk_with_options (request )
111
+
112
+ @tool (group = RDS_CUSTOM_GROUP_NAME )
113
+ def describe_rc_instance_vnc_url (
114
+ region_id : str ,
115
+ instance_id : str ,
116
+ db_type : str
117
+ ) -> Dict [str , Any ]:
118
+ """
119
+ describe the vnc login url for a specific rds custom instance.
120
+
121
+ Args:
122
+ region_id: The region ID of the RDS Custom instance.
123
+ instance_id: The ID of the instance.
124
+ db_type: The database type, e.g., 'mysql' or 'mssql'.
125
+
126
+ Returns:
127
+ dict[str, Any]: The response containing the VNC login URL.
128
+ """
129
+ request = RdsApiModels .DescribeRCInstanceVncUrlRequest (
130
+ region_id = region_id ,
131
+ instance_id = instance_id ,
132
+ db_type = db_type
133
+ )
134
+ return AliyunServiceGateway (region_id ).rds ().describe_rcinstance_vnc_url_with_options (request )
135
+
136
+ @tool (group = RDS_CUSTOM_GROUP_NAME )
137
+ def modify_rc_instance_attribute (
138
+ region_id : str ,
139
+ instance_id : str ,
140
+ password : Optional [str ] = None ,
141
+ reboot : Optional [bool ] = None ,
142
+ host_name : Optional [str ] = None ,
143
+ security_group_id : Optional [str ] = None ,
144
+ deletion_protection : Optional [bool ] = None
145
+ ) -> Dict [str , Any ]:
146
+ """
147
+ modify attributes of a specific rds custom instance.
148
+
149
+ Args:
150
+ region_id: The region ID of the RDS Custom instance.
151
+ instance_id: The ID of the RDS Custom instance to modify.
152
+ password: The new password for the instance.
153
+ reboot: Specifies whether to restart the instance after modification.
154
+ host_name: The new hostname for the instance.
155
+ security_group_id: The ID of the new security group for the instance.
156
+ deletion_protection: Specifies whether to enable the deletion protection feature.
157
+
158
+ Returns:
159
+ dict[str, Any]: The response containing the result of the operation.
160
+ """
161
+ request = RdsApiModels .ModifyRCInstanceAttributeRequest (
162
+ region_id = region_id ,
163
+ instance_id = instance_id ,
164
+ password = password ,
165
+ reboot = reboot ,
166
+ host_name = host_name ,
167
+ security_group_id = security_group_id ,
168
+ deletion_protection = deletion_protection
169
+ )
170
+ return AliyunServiceGateway (region_id ).rds ().modify_rcinstance_attribute_with_options (request )
171
+
172
+ @tool (group = RDS_CUSTOM_GROUP_NAME )
173
+ def modify_rc_instance_description (
174
+ region_id : str ,
175
+ instance_id : str ,
176
+ instance_description : str
177
+ ) -> Dict [str , Any ]:
178
+ """
179
+ modify the description of a specific rds custom instance.
180
+
181
+ Args:
182
+ region_id: The region ID of the RDS Custom instance.
183
+ instance_id: The ID of the instance to modify.
184
+ instance_description: The new description for the instance.
185
+
186
+ Returns:
187
+ dict[str, Any]: The response containing the result of the operation.
188
+ """
189
+
190
+ request = RdsApiModels .ModifyRCInstanceDescriptionRequest (
191
+ region_id = region_id ,
192
+ instance_id = instance_id ,
193
+ instance_description = instance_description
194
+ )
195
+ return AliyunServiceGateway (region_id ).rds ().modify_rcinstance_description_with_options (request )
0 commit comments