Skip to content

Commit 9f04663

Browse files
author
wenfeng.wf
committed
Add tools.
1 parent 405ba35 commit 9f04663

File tree

3 files changed

+249
-29
lines changed

3 files changed

+249
-29
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,32 @@ Add the following configuration to the MCP client configuration file:
8080

8181
## Components
8282
### Tools
83+
* `add_tags_to_db_instance`: Add tags to an RDS instance.
84+
* `allocate_instance_public_connection`: Allocate a public connection for an RDS instance.
85+
* `attach_whitelist_template_to_instance`: Attach a whitelist template to an RDS instance.
8386
* `create_db_instance`: Create an RDS instance.
84-
* `describe_db_instances`: Queries instances.
85-
* `describe_db_instance_attribute`: Queries the details of an instance.
86-
* `describe_db_instance_performance`: Queries the performance data of an instance.
87-
* `describe_error_logs`: Queries the error log of an instance.
88-
* `describe_db_instance_net_info`: Batch retrieves network configuration details for multiple RDS instances.
89-
* `describe_db_instance_ip_allowlist`: Batch retrieves IP allowlist configurations for multiple RDS instances.
90-
* `describe_db_instance_databases`: Batch retrieves database information for multiple RDS instances.
91-
* `describe_db_instance_accounts`: Batch retrieves account information for multiple RDS instances.
87+
* `create_db_instance_account`: Create an account for RDS instance.
88+
* `describe_all_whitelist_template`: Query the whitelist template list.
9289
* `describe_available_classes`: Query available instance classes and storage ranges.
9390
* `describe_available_zones`: Query available zones for RDS instances.
9491
* `describe_bills`: Query the consumption summary of all product instances or billing items for a user within a specific billing period.
92+
* `describe_db_instance_accounts`: Batch retrieves account information for multiple RDS instances.
93+
* `describe_db_instance_attribute`: Queries the details of an instance.
94+
* `describe_db_instance_databases`: Batch retrieves database information for multiple RDS instances.
95+
* `describe_db_instance_ip_allowlist`: Batch retrieves IP allowlist configurations for multiple RDS instances.
96+
* `describe_db_instance_net_info`: Batch retrieves network configuration details for multiple RDS instances.
97+
* `describe_db_instance_parameters`: Batch retrieves parameter information for multiple RDS instances.
98+
* `describe_db_instance_performance`: Queries the performance data of an instance.
99+
* `describe_db_instances`: Queries instances.
100+
* `describe_error_logs`: Queries the error log of an instance.
101+
* `describe_instance_linked_whitelist_template`: Query the whitelist template list.
102+
* `describe_slow_log_records`: Query slow log records for an RDS instance.
95103
* `describe_vpcs`: Query VPC list.
96104
* `describe_vswitches`: Query VSwitch list.
97-
* `describe_slow_log_records`: Query slow log records for an RDS instance.
98-
* `describe_db_instance_parameters`: Batch retrieves parameter information for multiple RDS instances.
99-
* `modify_parameter`: Modify RDS instance parameters.
100-
* `modify_db_instance_spec`: Modify RDS instance specifications.
101105
* `get_current_time`: Get the current time.
106+
* `modify_db_instance_description`: Modify RDS instance descriptions.
107+
* `modify_db_instance_spec`: Modify RDS instance specifications.
108+
* `modify_parameter`: Modify RDS instance parameters.
102109

103110
### Resources
104111
None at this time

README_CN.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,32 @@ git clone https://github.com/aliyun/alibabacloud-rds-openapi-mcp-server.git
7777

7878
## 功能组件
7979
### 工具集
80+
* `add_tags_to_db_instance`: 添加标签到RDS实例
81+
* `allocate_instance_public_connection`: 为RDS实例分配公网连接
82+
* `attach_whitelist_template_to_instance`: 将白名单模板绑定到RDS实例
8083
* `create_db_instance`: 创建RDS实例
81-
* `describe_db_instances`: 查询实例列表
82-
* `describe_db_instance_attribute`: 查询实例详情
83-
* `describe_db_instance_metrics`: 查询实例性能数据、错误日志和SQL报告
84+
* `create_db_instance_account`: 创建RDS实例账号
85+
* `describe_all_whitelist_template`: 查询白名单模板列表
86+
* `describe_available_classes`: 查询可用实例规格和存储范围
87+
* `describe_available_zones`: 查询RDS实例可用区域
88+
* `describe_bills`: 查询用户在特定计费周期内所有产品实例或计费项的消费汇总
89+
* `describe_db_instance_accounts`: 批量查询多个RDS实例的账户信息
90+
* `describe_db_instance_attribute`: 查询实例详细信息
91+
* `describe_db_instance_databases`: 批量查询多个RDS实例的数据库信息
92+
* `describe_db_instance_ip_allowlist`: 批量查询多个RDS实例的IP白名单配置
93+
* `describe_db_instance_net_info`: 批量查询多个RDS实例的网络配置详情
94+
* `describe_db_instance_parameters`: 批量查询多个RDS实例的参数信息
8495
* `describe_db_instance_performance`: 查询实例性能数据
96+
* `describe_db_instances`: 查询实例
8597
* `describe_error_logs`: 查询实例错误日志
86-
* `describe_db_instance_net_info`: 批量查询实例网络信息
87-
* `describe_db_instance_ip_allowlist`: 批量查询实例IP白名单配置
88-
* `describe_db_instance_databases`: 批量查询实例的DB信息
89-
* `describe_db_instance_accounts`: 批量查询实例的账号信息
90-
* `describe_available_classes`: 查询可用实例规格和存储范围
91-
* `describe_available_zones`: 查询RDS可用区
92-
* `describe_bills`: 批量查询实例账单信息.
98+
* `describe_instance_linked_whitelist_template`: 查询绑定到实例的白名单模板列表
99+
* `describe_slow_log_records`: 查询RDS实例的慢日志记录
93100
* `describe_vpcs`: 查询VPC列表
94-
* `describe_vswitches`: 查询虚拟交换机列表
95-
* `describe_slow_log_records`: 查询RDS慢日志记录
96-
* `describe_db_instance_parameters`: 批量查询实例参数信息.
97-
* `modify_parameter`: 修改RDS实例参数
98-
* `modify_db_instance_spec`: 调整RDS实例规格
101+
* `describe_vswitches`: 查询VSwitch列表
99102
* `get_current_time`: 获取当前时间
103+
* `modify_db_instance_description`: 修改RDS实例描述
104+
* `modify_db_instance_spec`: 修改RDS实例规格
105+
* `modify_parameter`: 修改RDS实例参数
100106

101107
### 资源
102108
当前暂无资源

src/alibabacloud_rds_openapi_mcp_server/server.py

Lines changed: 209 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ async def describe_db_instance_performance(region_id: str,
8686
start_time: start time(e.g. 2023-01-01 00:00)
8787
end_time: end time(e.g. 2023-01-01 00:00)
8888
"""
89+
8990
def _compress_performance(performance_value, max_items=10):
9091
if len(performance_value) > max_items:
9192
result = []
9293
offset = len(performance_value) / 10
9394
for i in range(0, len(performance_value), int(offset)):
9495
_item = None
9596
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('&')]):
9799
_item = performance_value[j]
98100
else:
99101
result.append(_item)
@@ -879,6 +881,43 @@ async def describe_db_instance_accounts(
879881
except Exception as e:
880882
raise e
881883

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+
882921
@mcp.tool()
883922
async def describe_db_instance_parameters(
884923
region_id: str,
@@ -989,6 +1028,174 @@ async def describe_bills(
9891028
raise e
9901029

9911030

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+
9921199
@mcp.tool()
9931200
async def get_current_time() -> Dict[str, Any]:
9941201
"""Get the current time.
@@ -1013,7 +1220,7 @@ async def get_current_time() -> Dict[str, Any]:
10131220

10141221

10151222
def main():
1016-
mcp.run(transport=os.getenv('SERVER_TRANSPORT', 'stdio'))
1223+
mcp.run(transport=os.getenv('SERVER_TRANSPORT', 'sse'))
10171224

10181225

10191226
if __name__ == '__main__':

0 commit comments

Comments
 (0)