Skip to content

add restart instance tool #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ Add the following configuration to the MCP client configuration file:
* `describe_slow_log_records`: Query slow log records for an RDS instance.
* `describe_vpcs`: Query VPC list.
* `describe_vswitches`: Query VSwitch list.
* `modify_security_ips`: Modify security ips
* `modify_security_ips`: Modify RDS instance security IP whitelist.
* `get_current_time`: Get the current time.
* `modify_db_instance_description`: Modify RDS instance descriptions.
* `modify_db_instance_spec`: Modify RDS instance specifications.
* `modify_parameter`: Modify RDS instance parameters.
* `restart_db_instance`: Restart an RDS instance.

### Resources
None at this time
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ git clone https://github.com/aliyun/alibabacloud-rds-openapi-mcp-server.git
* `modify_db_instance_description`: 修改RDS实例描述
* `modify_db_instance_spec`: 修改RDS实例规格
* `modify_parameter`: 修改RDS实例参数
* `restart_db_instance`: 重启RDS实例

### 资源
当前暂无资源
Expand Down
51 changes: 51 additions & 0 deletions src/alibabacloud_rds_openapi_mcp_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,57 @@ async def modify_security_ips(
raise OpenAPIError(f"modify rds instance security ips failed: {str(e)}")


@mcp.tool()
async def restart_db_instance(
region_id: str,
dbinstance_id: str,
effective_time: str = "Immediate",
switch_time: str = None,
client_token: str = None
) -> Dict[str, Any]:
"""Restart an RDS instance.

Args:
region_id (str): The region ID of the RDS instance.
dbinstance_id (str): The ID of the RDS instance.
effective_time (str, optional): When to restart the instance. Options:
- Immediate: Restart immediately
- MaintainTime: Restart during maintenance window
- ScheduleTime: Restart at specified time
Default: Immediate
switch_time (str, optional): The scheduled restart time in format: yyyy-MM-ddTHH:mm:ssZ (UTC time).
Required when effective_time is ScheduleTime.
client_token (str, optional): Idempotency token, max 64 ASCII characters.

Returns:
Dict[str, Any]: Response containing the request ID.
"""
try:
# Initialize client
client = get_rds_client(region_id)

# Create request
request = rds_20140815_models.RestartDBInstanceRequest(
dbinstance_id=dbinstance_id
)

# Add optional parameters
if effective_time:
request.effective_time = effective_time
if switch_time:
request.switch_time = switch_time
if client_token:
request.client_token = client_token

# Make the API request
response = client.restart_dbinstance(request)
return response.body.to_map()

except Exception as e:
logger.error(f"Error occurred while restarting instance: {str(e)}")
raise OpenAPIError(f"Failed to restart RDS instance: {str(e)}")


def main():
mcp.run(transport=os.getenv('SERVER_TRANSPORT', 'stdio'))

Expand Down