Skip to content

Commit 2b6bba6

Browse files
committed
fix
1 parent fdfafdc commit 2b6bba6

File tree

2 files changed

+202
-155
lines changed

2 files changed

+202
-155
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
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)

src/alibabacloud_rds_openapi_mcp_server/toolsets/rds_mssql_custom.py renamed to src/alibabacloud_rds_openapi_mcp_server/toolsets/rds_custom_mssql.py

Lines changed: 7 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Provides SQL Server-specific MCP tools for the "rds_custom" product.
4+
5+
This toolset requires the base `rds_custom` toolset to be loaded
6+
simultaneously. See the base module's docstring for detailed usage.
7+
"""
28
import logging
39
from typing import Dict, Any, Optional, List
410
from .tool_registry import tool
@@ -7,78 +13,9 @@
713

814
logger = logging.getLogger(__name__)
915

10-
RDS_CUSTOM_GROUP_NAME = 'rds_mssql_custom'
11-
12-
@tool(group=RDS_CUSTOM_GROUP_NAME)
13-
async def describe_rc_instances(region_id: str, db_instance_id: str|None) -> Dict[str, Any]:
14-
"""
15-
describe rds custom instances.
16-
17-
Args:
18-
region_id: The region ID of the RDS Custom instances.
19-
db_instance_id: The ID of a specific instance. If omitted, all instances in the region are returned.
20-
21-
Returns:
22-
dict[str, Any]: The response containing instance metadata.
23-
"""
24-
request = RdsApiModels.DescribeRCInstancesRequest(
25-
region_id=region_id,
26-
instance_id=db_instance_id
27-
)
28-
rds_client = AliyunServiceGateway(region_id).rds()
29-
return rds_client.describe_rcinstances_with_options(request)
30-
31-
@tool(group=RDS_CUSTOM_GROUP_NAME)
32-
def describe_rc_instance_attribute(region_id: str,instance_id: str) -> Dict[str, Any]:
33-
"""
34-
describe a single rds custom instance's details.
35-
36-
Args:
37-
region_id: The region ID of the RDS Custom instance.
38-
instance_id: The ID of the RDS Custom instance.
39-
40-
Returns:
41-
dict[str, Any]: The response containing the instance details.
42-
"""
43-
request = RdsApiModels.DescribeRCInstanceAttributeRequest(
44-
region_id=region_id,
45-
instance_id=instance_id
46-
)
47-
return AliyunServiceGateway(region_id).rds().describe_rcinstance_attribute_with_options(request)
48-
49-
@tool(group=RDS_CUSTOM_GROUP_NAME)
50-
def resize_rc_instance_disk(
51-
region_id: str,
52-
instance_id: str,
53-
new_size: int,
54-
disk_id: str,
55-
auto_pay: bool = False,
56-
dry_run: bool = False,
57-
) -> Dict[str, Any]:
58-
"""
59-
resize a specific rds custom instance's disk.
6016

61-
Args:
62-
region_id: The region ID of the RDS Custom instance.
63-
instance_id: The ID of the RDS Custom instance.
64-
new_size: The target size of the disk in GiB.
65-
disk_id: The ID of the cloud disk.
66-
auto_pay: Specifies whether to enable automatic payment. Default is false.
67-
dry_run: Specifies whether to perform a dry run. Default is false.
17+
RDS_CUSTOM_GROUP_NAME = 'rds_custom_mssql'
6818

69-
Returns:
70-
dict[str, Any]: The response containing the result of the operation.
71-
"""
72-
request = RdsApiModels.ResizeRCInstanceDiskRequest(
73-
region_id=region_id,
74-
instance_id=instance_id,
75-
new_size=new_size,
76-
disk_id=disk_id,
77-
auto_pay=auto_pay,
78-
dry_run=dry_run,
79-
type='online'
80-
)
81-
return AliyunServiceGateway(region_id).rds().resize_rcinstance_disk_with_options(request)
8219

8320
@tool(group=RDS_CUSTOM_GROUP_NAME)
8421
def describe_rc_instance_ip_address(
@@ -124,42 +61,6 @@ def describe_rc_instance_ip_address(
12461
)
12562
return AliyunServiceGateway(region_id).rds().describe_rcinstance_ip_address_with_options(request)
12663

127-
@tool(group=RDS_CUSTOM_GROUP_NAME)
128-
def modify_rc_instance_attribute(
129-
region_id: str,
130-
instance_id: str,
131-
password: Optional[str] = None,
132-
reboot: Optional[bool] = None,
133-
host_name: Optional[str] = None,
134-
security_group_id: Optional[str] = None,
135-
deletion_protection: Optional[bool] = None
136-
) -> Dict[str, Any]:
137-
"""
138-
modify attributes of a specific rds custom instance.
139-
140-
Args:
141-
region_id: The region ID of the RDS Custom instance.
142-
instance_id: The ID of the RDS Custom instance to modify.
143-
password: The new password for the instance.
144-
reboot: Specifies whether to restart the instance after modification.
145-
host_name: The new hostname for the instance.
146-
security_group_id: The ID of the new security group for the instance.
147-
deletion_protection: Specifies whether to enable the deletion protection feature.
148-
149-
Returns:
150-
dict[str, Any]: The response containing the result of the operation.
151-
"""
152-
request = RdsApiModels.ModifyRCInstanceAttributeRequest(
153-
region_id=region_id,
154-
instance_id=instance_id,
155-
password=password,
156-
reboot=reboot,
157-
host_name=host_name,
158-
security_group_id=security_group_id,
159-
deletion_protection=deletion_protection
160-
)
161-
return AliyunServiceGateway(region_id).rds().modify_rcinstance_attribute_with_options(request)
162-
16364
@tool(group=RDS_CUSTOM_GROUP_NAME)
16465
def stop_rc_instances(
16566
region_id: str,
@@ -238,55 +139,6 @@ def reboot_rc_instance(
238139
)
239140
return AliyunServiceGateway(region_id).rds().reboot_rcinstance_with_options(request)
240141

241-
@tool(group=RDS_CUSTOM_GROUP_NAME)
242-
def describe_rc_instance_vnc_url(
243-
region_id: str,
244-
instance_id: str,
245-
db_type: str
246-
) -> Dict[str, Any]:
247-
"""
248-
describe the vnc login url for a specific rds custom instance.
249-
250-
Args:
251-
region_id: The region ID of the RDS Custom instance.
252-
instance_id: The ID of the instance.
253-
db_type: The database type, e.g., 'mysql' or 'mssql'.
254-
255-
Returns:
256-
dict[str, Any]: The response containing the VNC login URL.
257-
"""
258-
request = RdsApiModels.DescribeRCInstanceVncUrlRequest(
259-
region_id=region_id,
260-
instance_id=instance_id,
261-
db_type=db_type
262-
)
263-
return AliyunServiceGateway(region_id).rds().describe_rcinstance_vnc_url_with_options(request)
264-
265-
@tool(group=RDS_CUSTOM_GROUP_NAME)
266-
def modify_rc_instance_description(
267-
region_id: str,
268-
instance_id: str,
269-
instance_description: str
270-
) -> Dict[str, Any]:
271-
"""
272-
modify the description of a specific rds custom instance.
273-
274-
Args:
275-
region_id: The region ID of the RDS Custom instance.
276-
instance_id: The ID of the instance to modify.
277-
instance_description: The new description for the instance.
278-
279-
Returns:
280-
dict[str, Any]: The response containing the result of the operation.
281-
"""
282-
283-
request = RdsApiModels.ModifyRCInstanceDescriptionRequest(
284-
region_id=region_id,
285-
instance_id=instance_id,
286-
instance_description=instance_description
287-
)
288-
return AliyunServiceGateway(region_id).rds().modify_rcinstance_description_with_options(request)
289-
290142
@tool(group=RDS_CUSTOM_GROUP_NAME)
291143
def describe_rc_image_list(
292144
region_id: str,

0 commit comments

Comments
 (0)