@@ -86,14 +86,16 @@ async def describe_db_instance_performance(region_id: str,
86
86
start_time: start time(e.g. 2023-01-01 00:00)
87
87
end_time: end time(e.g. 2023-01-01 00:00)
88
88
"""
89
+
89
90
def _compress_performance (performance_value , max_items = 10 ):
90
91
if len (performance_value ) > max_items :
91
92
result = []
92
93
offset = len (performance_value ) / 10
93
94
for i in range (0 , len (performance_value ), int (offset )):
94
95
_item = None
95
96
for j in range (i , min (i + int (offset ), len (performance_value ))):
96
- if _item is None or sum ([float (v ) for v in performance_value [j ].value .split ('&' )]) > sum ([float (v ) for v in _item .value .split ('&' )]):
97
+ if _item is None or sum ([float (v ) for v in performance_value [j ].value .split ('&' )]) > sum (
98
+ [float (v ) for v in _item .value .split ('&' )]):
97
99
_item = performance_value [j ]
98
100
else :
99
101
result .append (_item )
@@ -879,6 +881,43 @@ async def describe_db_instance_accounts(
879
881
except Exception as e :
880
882
raise e
881
883
884
+
885
+ @mcp .tool ()
886
+ async def create_db_instance_account (
887
+ region_id : str ,
888
+ db_instance_id : str ,
889
+ account_name : str ,
890
+ account_password : str ,
891
+ account_description : str = None ,
892
+ account_type : str = "Normal"
893
+ ) -> dict :
894
+ """
895
+ Create a new account for an RDS instance.
896
+ Args:
897
+ region_id: The region ID of the RDS instance.
898
+ db_instance_id: The ID of the RDS instance.
899
+ account_name: The name of the new account.
900
+ account_password: The password for the new account.
901
+ account_description: The description for the new account.
902
+ account_type: The type of the new account. (e.g. Normal,Super)
903
+ Returns:
904
+ dict[str, Any]: The response.
905
+ """
906
+ try :
907
+ client = get_rds_client (region_id )
908
+ request = rds_20140815_models .CreateAccountRequest (
909
+ dbinstance_id = db_instance_id ,
910
+ account_name = account_name ,
911
+ account_password = account_password ,
912
+ account_description = account_description ,
913
+ account_type = account_type
914
+ )
915
+ response = await client .create_account_async (request )
916
+ return response .body .to_map ()
917
+ except Exception as e :
918
+ raise e
919
+
920
+
882
921
@mcp .tool ()
883
922
async def describe_db_instance_parameters (
884
923
region_id : str ,
@@ -989,6 +1028,174 @@ async def describe_bills(
989
1028
raise e
990
1029
991
1030
1031
+ @mcp .tool ()
1032
+ async def modify_db_instance_description (
1033
+ region_id : str ,
1034
+ db_instance_id : str ,
1035
+ description : str
1036
+ ):
1037
+ """
1038
+ modify db instance description.
1039
+ Args:
1040
+ region_id: The region ID of the RDS instance.
1041
+ db_instance_id: The ID of the RDS instance.
1042
+ description: The RDS instance description.
1043
+ Returns:
1044
+ dict[str, Any]: The response.
1045
+ """
1046
+ try :
1047
+ client = get_rds_client (region_id )
1048
+ request = rds_20140815_models .ModifyDBInstanceDescriptionRequest (
1049
+ dbinstance_id = db_instance_id ,
1050
+ dbinstance_description = description
1051
+ )
1052
+ response = await client .modify_dbinstance_description_async (request )
1053
+ return response .body .to_map ()
1054
+ except Exception as e :
1055
+ raise e
1056
+
1057
+
1058
+ @mcp .tool ()
1059
+ async def allocate_instance_public_connection (
1060
+ region_id : str ,
1061
+ db_instance_id : str ,
1062
+ connection_string_prefix : str = None ,
1063
+ port : str = '3306'
1064
+ ):
1065
+ """
1066
+ allocate db instance public connection.
1067
+ Args:
1068
+ region_id: The region ID of the RDS instance.
1069
+ db_instance_id: The ID of the RDS instance.
1070
+ connection_string_prefix: The prefix of connection string.
1071
+ Returns:
1072
+ dict[str, Any]: The response.
1073
+ """
1074
+ try :
1075
+ if connection_string_prefix is None :
1076
+ connection_string_prefix = db_instance_id + "-public"
1077
+ client = get_rds_client (region_id )
1078
+ request = rds_20140815_models .AllocateInstancePublicConnectionRequest (
1079
+ dbinstance_id = db_instance_id ,
1080
+ connection_string_prefix = connection_string_prefix ,
1081
+ port = port
1082
+ )
1083
+ response = await client .allocate_instance_public_connection_async (request )
1084
+ return response .body .to_map ()
1085
+ except Exception as e :
1086
+ raise e
1087
+
1088
+
1089
+ @mcp .tool ()
1090
+ async def describe_all_whitelist_template (
1091
+ region_id : str ,
1092
+ template_name : str = None
1093
+ ) -> List [Dict [str , Any ]]:
1094
+ """
1095
+ describe all whitelist template.
1096
+ Args:
1097
+ region_id: The region ID of the RDS instance.
1098
+ template_name: The ID of the RDS instance.
1099
+ Returns:
1100
+ List[Dict[str, Any]]: The response contains all whitelist template information.
1101
+ """
1102
+ try :
1103
+ client = get_rds_client (region_id )
1104
+ next_pages = True
1105
+ all_whitelists = []
1106
+ while next_pages :
1107
+ request = rds_20140815_models .DescribeAllWhitelistTemplateRequest (
1108
+ template_name = template_name ,
1109
+ fuzzy_search = True ,
1110
+ max_records_per_page = 100
1111
+ )
1112
+ response = await client .describe_all_whitelist_template_async (request )
1113
+ next_pages = response .body .data .has_next
1114
+ all_whitelists .extend (response .body .data .templates )
1115
+ return [item .to_map () for item in all_whitelists ]
1116
+ except Exception as e :
1117
+ raise e
1118
+
1119
+
1120
+ @mcp .tool ()
1121
+ async def describe_instance_linked_whitelist_template (
1122
+ region_id : str ,
1123
+ db_instance_id : str
1124
+ ):
1125
+ """
1126
+ describe instance linked whitelist template.
1127
+ Args:
1128
+ region_id: The region ID of the RDS instance.
1129
+ db_instance_id: The ID of the RDS instance.
1130
+ Returns:
1131
+ dict[str, Any]: The response.
1132
+ """
1133
+ try :
1134
+ client = get_rds_client (region_id )
1135
+ request = rds_20140815_models .DescribeInstanceLinkedWhitelistTemplateRequest (
1136
+ ins_name = db_instance_id
1137
+ )
1138
+ response = await client .describe_instance_linked_whitelist_template_async (request )
1139
+ return response .body .to_map ()
1140
+ except Exception as e :
1141
+ raise e
1142
+
1143
+
1144
+ @mcp .tool ()
1145
+ async def attach_whitelist_template_to_instance (
1146
+ region_id : str ,
1147
+ db_instance_id : str ,
1148
+ template_id : int
1149
+ ):
1150
+ """
1151
+ allocate db instance public connection.
1152
+ Args:
1153
+ region_id: The region ID of the RDS instance.
1154
+ db_instance_id: The ID of the RDS instance.
1155
+ template_id: Whitelist Template ID. Can be obtained via DescribeAllWhitelistTemplate.
1156
+ Returns:
1157
+ dict[str, Any]: The response.
1158
+ """
1159
+ try :
1160
+ client = get_rds_client (region_id )
1161
+ request = rds_20140815_models .AttachWhitelistTemplateToInstanceRequest (
1162
+ ins_name = db_instance_id ,
1163
+ template_id = template_id
1164
+ )
1165
+ response = await client .attach_whitelist_template_to_instance_async (request )
1166
+ return response .body .to_map ()
1167
+ except Exception as e :
1168
+ raise e
1169
+
1170
+
1171
+ @mcp .tool ()
1172
+ async def add_tags_to_db_instance (
1173
+ region_id : str ,
1174
+ db_instance_id : str ,
1175
+ tags : Dict [str , str ]
1176
+ ):
1177
+ """
1178
+ add tags to db instance.
1179
+ Args:
1180
+ region_id: The region ID of the RDS instance.
1181
+ db_instance_id: The ID of the RDS instance.
1182
+ tags: The tags to be added to the RDS instance.
1183
+ Returns:
1184
+ dict[str, Any]: The response.
1185
+ """
1186
+ try :
1187
+ client = get_rds_client (region_id )
1188
+ request = rds_20140815_models .AddTagsToResourceRequest (
1189
+ region_id = region_id ,
1190
+ dbinstance_id = db_instance_id ,
1191
+ tags = json .dumps (tags )
1192
+ )
1193
+ response = await client .add_tags_to_resource_async (request )
1194
+ return response .body .to_map ()
1195
+ except Exception as e :
1196
+ raise e
1197
+
1198
+
992
1199
@mcp .tool ()
993
1200
async def get_current_time () -> Dict [str , Any ]:
994
1201
"""Get the current time.
@@ -1013,7 +1220,7 @@ async def get_current_time() -> Dict[str, Any]:
1013
1220
1014
1221
1015
1222
def main ():
1016
- mcp .run (transport = os .getenv ('SERVER_TRANSPORT' , 'stdio ' ))
1223
+ mcp .run (transport = os .getenv ('SERVER_TRANSPORT' , 'sse ' ))
1017
1224
1018
1225
1019
1226
if __name__ == '__main__' :
0 commit comments