Skip to content

Commit 2cb0814

Browse files
authored
Merge pull request #3 from wangype/main
feat(rds): enhance error logs query functionality
2 parents 6a13ed2 + 97df4f6 commit 2cb0814

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/rds_openapi_mcp_server/server.py

+71
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,77 @@ async def describe_slow_log_records(
807807
raise OpenAPIError(f"Failed to query slow log records: {str(e)}")
808808

809809

810+
@mcp.tool()
811+
async def describe_error_logs(
812+
region_id: str,
813+
db_instance_id: str,
814+
start_time: str,
815+
end_time: str,
816+
page_size: int = 30,
817+
page_number: int = 1
818+
) -> Dict[str, Any]:
819+
"""
820+
Query error logs of an RDS instance.
821+
822+
Args:
823+
region_id (str): The region ID of the RDS instance.
824+
db_instance_id (str): The ID of the RDS instance.
825+
start_time (str): The start time of the query. Format: yyyy-MM-ddTHH:mmZ (UTC time).
826+
end_time (str): The end time of the query. Format: yyyy-MM-ddTHH:mmZ (UTC time).
827+
page_size (int): The number of records per page. Range: 30~100. Default: 30.
828+
page_number (int): The page number. Default: 1.
829+
830+
Returns:
831+
Dict[str, Any]: A dictionary containing error log information with the following structure:
832+
{
833+
"Items": {
834+
"ErrorLog": [
835+
{
836+
"CreateTime": "2011-05-30T12:11:04Z",
837+
"ErrorInfo": "Error log content"
838+
}
839+
]
840+
},
841+
"PageNumber": 1,
842+
"PageRecordCount": 30,
843+
"TotalRecordCount": 100,
844+
"RequestId": "98504E07-BB0E-40FC-B152-E4882615812C"
845+
}
846+
847+
Raises:
848+
OpenAPIError: If the API call fails or returns an error.
849+
"""
850+
try:
851+
start_time = transform_to_datetime(start_time)
852+
end_time = transform_to_datetime(end_time)
853+
client = get_rds_client(region_id)
854+
request = rds_20140815_models.DescribeErrorLogsRequest(
855+
dbinstance_id=db_instance_id,
856+
start_time=start_time,
857+
end_time=end_time,
858+
page_size=page_size,
859+
page_number=page_number
860+
)
861+
response = await client.describe_error_logs_async(request)
862+
return {
863+
"Items": {
864+
"ErrorLog": [
865+
{
866+
"CreateTime": log.create_time,
867+
"ErrorInfo": log.error_info
868+
}
869+
for log in response.body.items.error_log
870+
]
871+
},
872+
"PageNumber": response.body.page_number,
873+
"PageRecordCount": response.body.page_record_count,
874+
"TotalRecordCount": response.body.total_record_count,
875+
"RequestId": response.body.request_id
876+
}
877+
except Exception as e:
878+
logger.error(f"Failed to describe error logs: {str(e)}")
879+
raise OpenAPIError(f"Failed to describe error logs: {str(e)}")
880+
810881
@mcp.tool()
811882
async def get_current_time() -> Dict[str, Any]:
812883
"""Get the current time.

0 commit comments

Comments
 (0)